Skip to content

Commit 3eb2707

Browse files
committed
Sanitize vendored crate checksums for PPA builds
1 parent 5efbcc6 commit 3eb2707

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/launchpad_ppa.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ jobs:
137137
rm -rf vendor .cargo
138138
mkdir -p .cargo
139139
cargo vendor --locked vendor > .cargo/config.toml
140+
python3 debian/sanitize-vendor.py
140141
grep -q 'replace-with = "vendored-sources"' .cargo/config.toml
141142
grep -q '\[source.vendored-sources\]' .cargo/config.toml
142143
grep -q '^directory = "vendor"$' .cargo/config.toml
143144
test -d vendor
145+
! find vendor -name '*.orig' -print | grep -q .
144146
145147
- name: Prepare package version
146148
if: steps.check_distro.outputs.should_run == 'true'

debian/sanitize-vendor.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
from pathlib import Path
5+
6+
7+
def main() -> int:
8+
vendor_root = Path("vendor")
9+
if not vendor_root.is_dir():
10+
raise SystemExit("vendor directory not found")
11+
12+
checksum_files = list(vendor_root.rglob(".cargo-checksum.json"))
13+
for checksum_file in checksum_files:
14+
crate_dir = checksum_file.parent
15+
data = json.loads(checksum_file.read_text())
16+
files = data.get("files", {})
17+
18+
removed = []
19+
for rel_path in list(files.keys()):
20+
if rel_path.endswith(".orig"):
21+
removed.append(rel_path)
22+
files.pop(rel_path, None)
23+
target = crate_dir / rel_path
24+
if target.exists():
25+
target.unlink()
26+
27+
if removed:
28+
checksum_file.write_text(
29+
json.dumps(data, separators=(",", ":"), sort_keys=True) + "\n"
30+
)
31+
print(f"sanitized {checksum_file} ({len(removed)} .orig entries)")
32+
33+
return 0
34+
35+
36+
if __name__ == "__main__":
37+
raise SystemExit(main())

0 commit comments

Comments
 (0)