Debian Codegraph @

debian/blank-vendor-checksums.py

raw
1 #!/usr/bin/env python3
2 """Blank the file lists in a vendor directory's .cargo-checksum.json files.
3
4 Cargo refuses to use a vendored crate whose files do not match the checksums
5 recorded there, which breaks two things at once: the quilt patches applied to
6 debian/rust-vendor, and any crate shipping a file dpkg-source strips from the
7 .debian.tar (.gitmodules, .gitignore, ...). An empty "files" map turns the
8 check off; "package" is kept because cargo still reads it.
9 """
10
11 import json
12 import pathlib
13 import sys
14
15 vendor = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else "debian/rust-vendor")
16
17 for path in sorted(vendor.glob("*/.cargo-checksum.json")):
18 data = json.loads(path.read_text())
19 if data.get("files") == {}:
20 continue
21 blanked = {"files": {}}
22 if "package" in data:
23 blanked["package"] = data["package"]
24 path.write_text(json.dumps(blanked, separators=(",", ":")))