diff --git a/scripts/check-buildinfo b/scripts/check-buildinfo index d98bab0..7711840 100755 --- a/scripts/check-buildinfo +++ b/scripts/check-buildinfo @@ -6,6 +6,7 @@ Example: ./check-buildinfo package.deb package.buildinfo """ + import argparse import hashlib import subprocess @@ -21,11 +22,15 @@ def lookup_buildinfos(buildinfos: Path) -> dict: data = {} for path in buildinfos.glob("**/*.buildinfo"): info = BuildInfo(path.read_text()) - for details in info['Checksums-Sha256']: - if details['name'].endswith('.deb'): - if details['name'] in data: + for details in info["Checksums-Sha256"]: + if details["name"].endswith(".deb") or details["name"].endswith(".ddeb"): + # If the package is debug symbols, coerce Ubuntu-style ".ddeb" + # to Debian-style ".deb". + if "dbgsym" in details["name"]: + details["name"] = details["name"].replace(".ddeb", ".deb") + if details["name"] in data: raise ValueError(f"ERROR: duplicate checksum for {details['name']}") - data[details['name']] = details['sha256'] + data[details["name"]] = details["sha256"] return data @@ -45,39 +50,45 @@ def check_package(package: Path, buildinfos: dict) -> bool: return False -def added_files(against="origin/main") -> List[Path]: +def added_files(against: str) -> List[Path]: """Get list of added files compared to main""" added = [] - output = subprocess.check_output([ - "git", "log", - # Only list added files - "--diff-filter=A", - # Set our terminal width to be huge so it doesn't truncate - "--stat=999999", - # Output nothing else - "--pretty=", - f"{against}..HEAD" - ], text=True) + output = subprocess.check_output( + [ + "git", + "log", + # Only list added files + "--diff-filter=A", + # Set our terminal width to be huge so it doesn't truncate + "--stat=999999", + # Output nothing else + "--pretty=", + f"{against}..HEAD", + ], + text=True, + ) for line in output.splitlines(): if "|" not in line: continue path = Path(line.split("|", 1)[0].strip()) - if path.name.endswith('.deb') and path.exists(): - # Wasn't deleted in an intermediate commit - added.append(path) + if path.name.endswith(".deb") or path.name.endswith(".ddeb"): + if path.exists(): + # Wasn't deleted in an intermediate commit + added.append(path) added.sort(key=lambda x: x.name) return added def main(): - parser = argparse.ArgumentParser( - description="Check packages against their buildinfo files" - ) + parser = argparse.ArgumentParser(description="Check packages against their buildinfo files") parser.add_argument("buildinfos", type=Path, help="Folder with buildinfo files") + parser.add_argument( + "--against", default="origin/main", type=str, help="Git ref from which to detect changes" + ) args = parser.parse_args() buildinfos = lookup_buildinfos(args.buildinfos) status = 0 - added = added_files() + added = added_files(args.against) if not added: print("No new packages detected.") sys.exit(0) @@ -87,5 +98,5 @@ def main(): sys.exit(status) -if __name__ == '__main__': +if __name__ == "__main__": main()