Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 61: [PATCH 61/68] fix(release): assemble platform-specific license notices

ci/release/notices.py

Before: /dev/null · After: ci/release/notices.py

File metadata
new file mode 100644
index 0000000000000000000000000000000000000000..dc42aa295bff345c8c5d748489413054b083e582

Download original patch · Release notes

Diff rows 1–209 of 209. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

ci/release/notices.py ADDED
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) 2026-present The Bitcoin Roots developers
3
+ # Distributed under the MIT software license, see the accompanying
4
+ # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
+
6
+ import argparse
7
+ import hashlib
8
+ import json
9
+ from pathlib import Path, PurePosixPath
10
+ import re
11
+ import sys
12
+ import tarfile
13
+ import zipfile
14
+
15
+ ROOT = Path(__file__).resolve().parents[2]
16
+ TRACKED_NOTICES = {
17
+ "secp256k1": "src/secp256k1/COPYING",
18
+ "minisketch": "src/minisketch/LICENSE",
19
+ "leveldb": "src/leveldb/LICENSE",
20
+ "crc32c": "src/crc32c/LICENSE",
21
+ "ctaes": "src/crypto/ctaes/COPYING",
22
+ "libmultiprocess": "src/ipc/libmultiprocess/COPYING",
23
+ "RobotoMono-Apache2": "contrib/roots/notices/RobotoMono-APACHE-2.0.txt",
24
+ "RobotoMono-attribution": "contrib/roots/notices/RobotoMono-NOTICE.txt",
25
+ }
26
+ COMMON_EXTERNAL = {"qt", "boost", "libevent", "zeromq", "qrencode", "sqlite", "miniupnpc"}
27
+ MACOS_EXTERNAL = {"pcre2", "libsodium", "brotli", "graphite2", "md4c", "glib", "libpng", "openssl", "freetype", "harfbuzz", "icu", "gettext", "dbus", "zstd", "libb2", "double-conversion"}
28
+ WINDOWS_EXTERNAL = {"zlib", "libpng", "pcre2", "bzip2", "brotli", "freetype", "double-conversion", "libiconv"}
29
+ PLATFORMS = {"linux-x86_64", "linux-aarch64", "darwin-x86_64", "darwin-arm64", "windows-x86_64"}
30
+
31
+
32
+ def digest(data):
33
+ return hashlib.sha256(data).hexdigest()
34
+
35
+
36
+ def required_components(platform):
37
+ if platform not in PLATFORMS:
38
+ raise ValueError(f"Unknown notice platform: {platform}")
39
+ return COMMON_EXTERNAL | (MACOS_EXTERNAL if platform.startswith("darwin") else {"capnp"} if platform.startswith("linux") else WINDOWS_EXTERNAL)
40
+
41
+
42
+ def safe_path(path):
43
+ if not isinstance(path, str) or not path or "\x00" in path or PurePosixPath(path).is_absolute() or "\\" in path or any(x in {"", ".", ".."} for x in path.split("/")):
44
+ raise ValueError(f"Unsafe notice path: {path}")
45
+ return path
46
+
47
+
48
+ def validate_index(index, read, expected_platform):
49
+ if index.get("format") != 1:
50
+ raise ValueError("Unsupported notice index format")
51
+ required = required_components(expected_platform)
52
+ if index.get("platform") != expected_platform:
53
+ raise ValueError(f"Notice platform mismatch: expected {expected_platform}, found {index.get('platform')}")
54
+ components = index.get("components", {})
55
+ if not required <= components.keys():
56
+ raise ValueError(f"Missing dependency notice inputs: {sorted(required - components.keys())}")
57
+ for component, metadata in components.items():
58
+ if not metadata.get("version") or not metadata.get("source") or not re.fullmatch(r"[0-9a-f]{64}", metadata.get("source_sha256", "")):
59
+ raise ValueError(f"Missing exact notice provenance: {component}")
60
+ if not metadata.get("files") and not (component == "sqlite" and index["platform"].startswith("darwin") and metadata.get("role") == "system-library"):
61
+ raise ValueError(f"Missing notice text: {component}")
62
+ provenance_type = metadata.get("provenance_type")
63
+ if provenance_type not in {"build-receipt", "pinned-source-archive", "versioned-primary-notice", "source-version-stability"}:
64
+ raise ValueError(f"Unsupported notice provenance: {component}")
65
+ evidence = metadata.get("evidence")
66
+ if evidence not in index.get("files", {}):
67
+ raise ValueError(f"Missing retained notice provenance: {component}")
68
+ if metadata["version"] == "unknown" and (provenance_type != "source-version-stability" or len(metadata.get("notice_stable_versions", [])) < 2):
69
+ raise ValueError(f"Unknown version requires explicit notice stability evidence: {component}")
70
+ for path in metadata.get("files", []):
71
+ if path not in index.get("files", {}):
72
+ raise ValueError(f"Missing indexed notice: {path}")
73
+ for path, sha256 in index.get("files", {}).items():
74
+ safe_path(path)
75
+ data = read(path)
76
+ if not data or digest(data) != sha256:
77
+ raise ValueError(f"Notice bytes differ from index: {path}")
78
+ for component, source in TRACKED_NOTICES.items():
79
+ path = f"tracked/{component}.txt"
80
+ if path not in index.get("files", {}) or read(path) != (ROOT / source).read_bytes():
81
+ raise ValueError(f"Missing or altered tracked notice: {component}")
82
+
83
+
84
+ def stage(directory, inputs, expected_platform):
85
+ index = json.loads(inputs.read_text())
86
+ source_directory = inputs.parent
87
+ def read(path):
88
+ safe_path(path)
89
+ source = source_directory / path
90
+ if source.is_symlink() or not source.is_file() or not source.resolve().is_relative_to(source_directory.resolve()):
91
+ raise ValueError(f"Notice input is not a regular file: {path}")
92
+ return source.read_bytes()
93
+ validate_index(index, read, expected_platform)
94
+ destination = directory / "notices"
95
+ if not directory.is_dir() or destination.exists() or destination.is_symlink():
96
+ raise ValueError("Notice staging requires an existing root without notices")
97
+ destination.mkdir()
98
+ for path in sorted(index["files"]):
99
+ target = destination / path
100
+ target.parent.mkdir(parents=True, exist_ok=True)
101
+ target.write_bytes(read(path))
102
+ (destination / "index.json").write_text(json.dumps(index, indent=2, sort_keys=True) + "\n")
103
+
104
+
105
+ def collect(platform, descriptor, destination):
106
+ """Copy reviewed notices and their retained primary-source evidence.
107
+
108
+ Dependency versions and linkage evidence belong to the build inventory,
109
+ never to a guess based on a dylib's ABI number. Evidence can be an original
110
+ receipt or independently verified source selection with log/binary evidence.
111
+ Unknown patch versions remain unknown when notice bytes are proven stable.
112
+ """
113
+ dependencies = json.loads(descriptor.read_text())
114
+ index = {"format": 1, "platform": platform, "components": {}, "files": {}}
115
+ payload = {}
116
+ for component, source in TRACKED_NOTICES.items():
117
+ path = f"tracked/{component}.txt"
118
+ payload[path] = (ROOT / source).read_bytes()
119
+ for component, metadata in dependencies.items():
120
+ safe_path(component)
121
+ source = Path(metadata.get("evidence", metadata.get("receipt", "")))
122
+ if not source.is_absolute():
123
+ source = descriptor.parent / source
124
+ if source.is_symlink() or not source.is_file():
125
+ raise ValueError(f"Missing retained primary-source evidence: {component}")
126
+ entry = {"version": metadata["version"], "source": metadata["source"],
127
+ "source_sha256": metadata.get("source_sha256", digest(source.read_bytes())),
128
+ "provenance_type": metadata.get("provenance_type", "build-receipt"),
129
+ "role": metadata.get("role", "build-dependency"), "files": []}
130
+ if "notice_stable_versions" in metadata:
131
+ entry["notice_stable_versions"] = metadata["notice_stable_versions"]
132
+ evidence = f"provenance/{component}/{source.name}"
133
+ safe_path(evidence)
134
+ payload[evidence] = source.read_bytes()
135
+ entry["evidence"] = evidence
136
+ for number, filename in enumerate(metadata["files"]):
137
+ notice = Path(filename)
138
+ if not notice.is_absolute():
139
+ notice = descriptor.parent / notice
140
+ if notice.is_symlink() or not notice.is_file():
141
+ raise ValueError(f"Missing exact dependency notice: {component}: {filename}")
142
+ path = f"external/{component}/{number}-{notice.name}"
143
+ safe_path(path)
144
+ payload[path] = notice.read_bytes()
145
+ entry["files"].append(path)
146
+ index["components"][component] = entry
147
+ index["files"] = {path: digest(data) for path, data in payload.items()}
148
+ validate_index(index, payload.__getitem__, platform)
149
+ if destination.exists():
150
+ raise ValueError("Notice collection destination already exists")
151
+ destination.mkdir(parents=True)
152
+ for path, data in payload.items():
153
+ target = destination / path
154
+ target.parent.mkdir(parents=True, exist_ok=True)
155
+ target.write_bytes(data)
156
+ (destination / "index.json").write_text(json.dumps(index, indent=2, sort_keys=True) + "\n")
157
+
158
+
159
+ def validate_archive(archive, expected_root, expected_platform):
160
+ prefix = f"{expected_root}/notices/"
161
+ if archive.suffix == ".zip":
162
+ with zipfile.ZipFile(archive) as package:
163
+ def read(path):
164
+ member = package.getinfo(prefix + safe_path(path))
165
+ if member.is_dir() or (member.external_attr >> 16) & 0o170000 not in {0, 0o100000}:
166
+ raise ValueError(f"Notice is not a regular member: {path}")
167
+ return package.read(member)
168
+ validate_index(json.loads(read("index.json")), read, expected_platform)
169
+ else:
170
+ with tarfile.open(archive) as package:
171
+ def read(path):
172
+ member = package.getmember(prefix + safe_path(path))
173
+ if not member.isfile():
174
+ raise ValueError(f"Notice is not a regular member: {path}")
175
+ return package.extractfile(member).read()
176
+ validate_index(json.loads(read("index.json")), read, expected_platform)
177
+
178
+
179
+ def main():
180
+ parser = argparse.ArgumentParser()
181
+ commands = parser.add_subparsers(dest="command", required=True)
182
+ staging = commands.add_parser("stage")
183
+ staging.add_argument("directory", type=Path)
184
+ staging.add_argument("inputs", type=Path)
185
+ staging.add_argument("platform", choices=sorted(PLATFORMS))
186
+ validation = commands.add_parser("validate")
187
+ validation.add_argument("archive", type=Path)
188
+ validation.add_argument("expected_root")
189
+ validation.add_argument("platform", choices=sorted(PLATFORMS))
190
+ collection = commands.add_parser("collect")
191
+ collection.add_argument("platform", choices=sorted(PLATFORMS))
192
+ collection.add_argument("descriptor", type=Path)
193
+ collection.add_argument("destination", type=Path)
194
+ args = parser.parse_args()
195
+ try:
196
+ if args.command == "stage":
197
+ stage(args.directory, args.inputs, args.platform)
198
+ elif args.command == "validate":
199
+ validate_archive(args.archive, args.expected_root, args.platform)
200
+ else:
201
+ collect(args.platform, args.descriptor, args.destination)
202
+ except (OSError, ValueError, KeyError, tarfile.TarError, zipfile.BadZipFile) as error:
203
+ print(error, file=sys.stderr)
204
+ return 1
205
+ return 0
206
+
207
+
208
+ if __name__ == "__main__":
209
+ sys.exit(main())