mirror of
https://github.com/github/codeql.git
synced 2026-02-12 05:01:06 +01:00
Merge pull request #21287 from github/redsun82/fix-rust-deps-patching
Bazel: fix Rust deps patching for semver build metadata
This commit is contained in:
20
misc/bazel/3rdparty/patch_defs.py
vendored
20
misc/bazel/3rdparty/patch_defs.py
vendored
@@ -2,7 +2,23 @@ import sys
|
||||
import re
|
||||
import pathlib
|
||||
|
||||
label_re = re.compile(r'"@(vendor.*)//:(.+)-([\d.]+)"')
|
||||
# Problem number 1:
|
||||
# https://github.com/bazelbuild/rules_rust/issues/3255
|
||||
# `crates_vendor` generates broken labels in `defs.bzl`: instead of
|
||||
# "anyhow": Label("@vendor__anyhow-1.0.44//:anyhow")
|
||||
# it produces
|
||||
# "anyhow": Label("@vendor//:anyhow-1.0.44")
|
||||
# which results in: ERROR: no such package '@@[unknown repo 'vendor' requested from @@]//'
|
||||
#
|
||||
# Problem number 2:
|
||||
# Semver versions can contain `+` for build metadata (e.g., `0.9.11+spec-1.1.0`).
|
||||
# Bazel repo names use `-` instead of `+`, so `vendor_ts__toml-0.9.11+spec-1.1.0`
|
||||
# becomes `vendor_ts__toml-0.9.11-spec-1.1.0`. The generated labels reference the
|
||||
# `+` version which doesn't exist, causing:
|
||||
# ERROR: no such package '@@[unknown repo 'vendor_ts__toml-0.9.11+spec-1.1.0'
|
||||
# requested from @@ (did you mean 'vendor_ts__toml-0.9.11-spec-1.1.0'?)]//
|
||||
|
||||
label_re = re.compile(r'"@(vendor.*)//:([^+]+)-([\d.]+(?:\+.*)?)"')
|
||||
|
||||
file = pathlib.Path(sys.argv[1])
|
||||
temp = file.with_suffix(f'{file.suffix}.tmp')
|
||||
@@ -10,7 +26,7 @@ temp = file.with_suffix(f'{file.suffix}.tmp')
|
||||
|
||||
with open(file) as input, open(temp, "w") as output:
|
||||
for line in input:
|
||||
line = label_re.sub(lambda m: f'"@{m[1]}__{m[2]}-{m[3]}//:{m[2].replace("-", "_")}"', line)
|
||||
line = label_re.sub(lambda m: f'"@{m[1]}__{m[2]}-{m[3].replace("+", "-")}//:{m[2].replace("-", "_")}"', line)
|
||||
output.write(line)
|
||||
|
||||
temp.rename(file)
|
||||
|
||||
Reference in New Issue
Block a user