Skip to content

Commit 1e1e174

Browse files
paldepindCopilot
andauthored
Rust: Refactor RUST_ANALYZER_SRC_TAG and INTEGRITY updates
Refactor regex replacements for RUST_ANALYZER_SRC_TAG and RUST_ANALYZER_SRC_INTEGRITY to ensure exactly one assignment is made for each. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 9f9bc5e commit 1e1e174

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎rust/scripts/update_rust_analyzer.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,20 @@ def update_rust_analyzer_sources(rust_analyzer_version: str) -> None:
8989
integrity = "sha256-" + base64.b64encode(hashlib.sha256(archive).digest()).decode()
9090

9191
module = MODULE_BAZEL.read_text()
92-
module = re.sub(
92+
module, tag_replacements = re.subn(
9393
r'RUST_ANALYZER_SRC_TAG = "[^"]+"',
9494
f'RUST_ANALYZER_SRC_TAG = "{release_date}"',
9595
module,
96-
count=1,
9796
)
98-
module = re.sub(
97+
if tag_replacements != 1:
98+
raise RuntimeError("expected exactly one RUST_ANALYZER_SRC_TAG assignment")
99+
module, integrity_replacements = re.subn(
99100
r'RUST_ANALYZER_SRC_INTEGRITY = "[^"]+"',
100101
f'RUST_ANALYZER_SRC_INTEGRITY = "{integrity}"',
101102
module,
102-
count=1,
103103
)
104+
if integrity_replacements != 1:
105+
raise RuntimeError("expected exactly one RUST_ANALYZER_SRC_INTEGRITY assignment")
104106
MODULE_BAZEL.write_text(module)
105107

106108

0 commit comments

Comments
 (0)