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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
ci/release/archive.py
CHANGED
|
@@ -8,6 +8,7 @@ from collections import deque
|
|
| 8 |
import os
|
| 9 |
from pathlib import Path
|
| 10 |
import re
|
|
|
|
| 11 |
import sys
|
| 12 |
import tarfile
|
| 13 |
import zipfile
|
|
@@ -39,7 +40,7 @@ def archive_members(archive):
|
|
| 39 |
raise ValueError(f"Unsupported release archive: {archive.name}")
|
| 40 |
|
| 41 |
|
| 42 |
-
def validate_archive_root(archive, expected_root):
|
| 43 |
members = archive_members(archive)
|
| 44 |
if not members:
|
| 45 |
raise ValueError(f"Release archive is empty: {archive.name}")
|
|
@@ -47,6 +48,7 @@ def validate_archive_root(archive, expected_root):
|
|
| 47 |
has_payload = False
|
| 48 |
paths = set()
|
| 49 |
symlinks = {}
|
|
|
|
| 50 |
for member in members:
|
| 51 |
name = member.name if isinstance(member, tarfile.TarInfo) else member.filename
|
| 52 |
normalized = name.rstrip("/")
|
|
@@ -68,12 +70,14 @@ def validate_archive_root(archive, expected_root):
|
|
| 68 |
raise ValueError(f"Unsupported archive member in {archive.name}: {name}")
|
| 69 |
if member_type == 0o120000:
|
| 70 |
symlinks[normalized] = member
|
| 71 |
-
is_regular_file = not member.is_dir() and member_type != 0o120000
|
| 72 |
if parts[0] != expected_root:
|
| 73 |
raise ValueError(
|
| 74 |
f"Expected root directory {expected_root} in {archive.name}, found: {name}"
|
| 75 |
)
|
| 76 |
has_payload |= len(parts) > 1 and is_regular_file
|
|
|
|
|
|
|
| 77 |
|
| 78 |
if symlinks:
|
| 79 |
with zipfile.ZipFile(archive) as package:
|
|
@@ -130,6 +134,30 @@ def validate_archive_root(archive, expected_root):
|
|
| 130 |
|
| 131 |
if not has_payload:
|
| 132 |
raise ValueError(f"Release archive has no files below {expected_root}: {archive.name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
def main():
|
|
@@ -143,13 +171,19 @@ def main():
|
|
| 143 |
validate_parser = subparsers.add_parser("validate")
|
| 144 |
validate_parser.add_argument("archive", type=Path)
|
| 145 |
validate_parser.add_argument("expected_root")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
args = parser.parse_args()
|
| 148 |
try:
|
| 149 |
if args.command == "root-name":
|
| 150 |
print(archive_root_name(args.tag, args.sha))
|
|
|
|
|
|
|
| 151 |
else:
|
| 152 |
-
validate_archive_root(args.archive, args.expected_root)
|
| 153 |
except (OSError, ValueError, tarfile.TarError, zipfile.BadZipFile) as error:
|
| 154 |
print(error, file=sys.stderr)
|
| 155 |
return 1
|
|
|
|
| 8 |
import os
|
| 9 |
from pathlib import Path
|
| 10 |
import re
|
| 11 |
+
import shutil
|
| 12 |
import sys
|
| 13 |
import tarfile
|
| 14 |
import zipfile
|
|
|
|
| 40 |
raise ValueError(f"Unsupported release archive: {archive.name}")
|
| 41 |
|
| 42 |
|
| 43 |
+
def validate_archive_root(archive, expected_root, copying=None):
|
| 44 |
members = archive_members(archive)
|
| 45 |
if not members:
|
| 46 |
raise ValueError(f"Release archive is empty: {archive.name}")
|
|
|
|
| 48 |
has_payload = False
|
| 49 |
paths = set()
|
| 50 |
symlinks = {}
|
| 51 |
+
license_member = None
|
| 52 |
for member in members:
|
| 53 |
name = member.name if isinstance(member, tarfile.TarInfo) else member.filename
|
| 54 |
normalized = name.rstrip("/")
|
|
|
|
| 70 |
raise ValueError(f"Unsupported archive member in {archive.name}: {name}")
|
| 71 |
if member_type == 0o120000:
|
| 72 |
symlinks[normalized] = member
|
| 73 |
+
is_regular_file = not member.is_dir() and member_type in {0, 0o100000}
|
| 74 |
if parts[0] != expected_root:
|
| 75 |
raise ValueError(
|
| 76 |
f"Expected root directory {expected_root} in {archive.name}, found: {name}"
|
| 77 |
)
|
| 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
|
| 81 |
|
| 82 |
if symlinks:
|
| 83 |
with zipfile.ZipFile(archive) as package:
|
|
|
|
| 134 |
|
| 135 |
if not has_payload:
|
| 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)
|
| 161 |
|
| 162 |
|
| 163 |
def main():
|
|
|
|
| 171 |
validate_parser = subparsers.add_parser("validate")
|
| 172 |
validate_parser.add_argument("archive", type=Path)
|
| 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)
|
| 178 |
|
| 179 |
args = parser.parse_args()
|
| 180 |
try:
|
| 181 |
if args.command == "root-name":
|
| 182 |
print(archive_root_name(args.tag, args.sha))
|
| 183 |
+
elif args.command == "stage-copying":
|
| 184 |
+
stage_copying(args.directory)
|
| 185 |
else:
|
| 186 |
+
validate_archive_root(args.archive, args.expected_root, args.copying)
|
| 187 |
except (OSError, ValueError, tarfile.TarError, zipfile.BadZipFile) as error:
|
| 188 |
print(error, file=sys.stderr)
|
| 189 |
return 1
|