Skip to content
Bitcoin Roots

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

ci/release/archive.py

Before: ci/release/archive.py · After: ci/release/archive.py

File metadata
index 26227cc03a77c0acda9a4226d83858298a7ba819..ff09feeedc61f7b5ddaf789e744778604511d8c9 100755

Download original patch · Release notes

Diff rows 1–87 of 87. 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/archive.py CHANGED
@@ -8,6 +8,7 @@ from collections import deque
8
8
  import os
9
9
  from pathlib import Path
10
10
  import re
11
+ import shutil
11
12
  import sys
12
13
  import tarfile
13
14
  import zipfile
@@ -39,7 +40,7 @@ def archive_members(archive):
39
40
  raise ValueError(f"Unsupported release archive: {archive.name}")
40
41
 
41
42
 
42
- def validate_archive_root(archive, expected_root):
43
+ def validate_archive_root(archive, expected_root, copying=None):
43
44
  members = archive_members(archive)
44
45
  if not members:
45
46
  raise ValueError(f"Release archive is empty: {archive.name}")
@@ -47,6 +48,7 @@ def validate_archive_root(archive, expected_root):
47
48
  has_payload = False
48
49
  paths = set()
49
50
  symlinks = {}
51
+ license_member = None
50
52
  for member in members:
51
53
  name = member.name if isinstance(member, tarfile.TarInfo) else member.filename
52
54
  normalized = name.rstrip("/")
@@ -68,12 +70,14 @@ def validate_archive_root(archive, expected_root):
68
70
  raise ValueError(f"Unsupported archive member in {archive.name}: {name}")
69
71
  if member_type == 0o120000:
70
72
  symlinks[normalized] = member
71
- is_regular_file = not member.is_dir() and member_type != 0o120000
73
+ is_regular_file = not member.is_dir() and member_type in {0, 0o100000}
72
74
  if parts[0] != expected_root:
73
75
  raise ValueError(
74
76
  f"Expected root directory {expected_root} in {archive.name}, found: {name}"
75
77
  )
76
78
  has_payload |= len(parts) > 1 and is_regular_file
79
+ if normalized == f"{expected_root}/COPYING" and is_regular_file:
80
+ license_member = member
77
81
 
78
82
  if symlinks:
79
83
  with zipfile.ZipFile(archive) as package:
@@ -130,6 +134,30 @@ def validate_archive_root(archive, expected_root):
130
134
 
131
135
  if not has_payload:
132
136
  raise ValueError(f"Release archive has no files below {expected_root}: {archive.name}")
137
+ if copying is not None:
138
+ if license_member is None:
139
+ raise ValueError(f"Release archive is missing regular COPYING: {archive.name}")
140
+ expected_notice = copying.read_bytes()
141
+ notice_size = license_member.size if isinstance(license_member, tarfile.TarInfo) else license_member.file_size
142
+ if notice_size != len(expected_notice):
143
+ raise ValueError(f"Release archive COPYING differs from canonical notice: {archive.name}")
144
+ if isinstance(license_member, tarfile.TarInfo):
145
+ with tarfile.open(archive, mode="r:gz") as package:
146
+ notice = package.extractfile(license_member).read()
147
+ else:
148
+ with zipfile.ZipFile(archive) as package:
149
+ notice = package.read(license_member)
150
+ if notice != expected_notice:
151
+ raise ValueError(f"Release archive COPYING differs from canonical notice: {archive.name}")
152
+
153
+
154
+ def stage_copying(directory):
155
+ if not directory.is_dir():
156
+ raise ValueError(f"License staging directory does not exist: {directory}")
157
+ destination = directory / "COPYING"
158
+ if destination.is_symlink():
159
+ raise ValueError(f"License staging refuses a COPYING symlink: {directory}")
160
+ shutil.copyfile(Path(__file__).resolve().parents[2] / "COPYING", destination)
133
161
 
134
162
 
135
163
  def main():
@@ -143,13 +171,19 @@ def main():
143
171
  validate_parser = subparsers.add_parser("validate")
144
172
  validate_parser.add_argument("archive", type=Path)
145
173
  validate_parser.add_argument("expected_root")
174
+ validate_parser.add_argument("--copying", type=Path)
175
+
176
+ copying_parser = subparsers.add_parser("stage-copying")
177
+ copying_parser.add_argument("directory", type=Path)
146
178
 
147
179
  args = parser.parse_args()
148
180
  try:
149
181
  if args.command == "root-name":
150
182
  print(archive_root_name(args.tag, args.sha))
183
+ elif args.command == "stage-copying":
184
+ stage_copying(args.directory)
151
185
  else:
152
- validate_archive_root(args.archive, args.expected_root)
186
+ validate_archive_root(args.archive, args.expected_root, args.copying)
153
187
  except (OSError, ValueError, tarfile.TarError, zipfile.BadZipFile) as error:
154
188
  print(error, file=sys.stderr)
155
189
  return 1