공식 upstream 원문과 SPDX 대조를 추가함
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
cefcdabfb6a77d979ae99e0ba7b4b7ed5ebbc247- 부모
- 5c9b48e
변경된 파일 6개
+101-4Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기| @@ -71,7 +71,39 @@ def registry_files(package, locked): | ||
| 71 | 71 | return records |
| 72 | 72 | |
| 73 | 73 | |
| 74 | 삭제: def inventory(manifests, project_root=ROOT): | |
| 74 | 추가: def supplemental_files(package, supplement_path): | |
| 75 | 추가: data = json.loads(Path(supplement_path).read_text(encoding="utf-8")) | |
| 76 | 추가: candidates = [row for row in data["packages"] | |
| 77 | 추가: if (row["name"], row["version"]) == (package["name"], package["version"])] | |
| 78 | 추가: if not candidates: | |
| 79 | 추가: return [] | |
| 80 | 추가: if len(candidates) != 1: | |
| 81 | 추가: raise ValueError("보충 항목 중복") | |
| 82 | 추가: row = candidates[0] | |
| 83 | 추가: if row["license"] != package["license"]: | |
| 84 | 추가: raise ValueError(f"보충 SPDX 불일치: {package['name']}") | |
| 85 | 추가: root = Path(package["manifest_path"]).parent.resolve() | |
| 86 | 추가: archive = root.parents[2] / "cache" / root.parent.name / (root.name + ".crate") | |
| 87 | 추가: with tarfile.open(archive, "r:gz") as source: | |
| 88 | 추가: vcs = json.load(source.extractfile(root.name + "/.cargo_vcs_info.json")) | |
| 89 | 추가: if vcs["git"]["sha1"] != row["rev"]: | |
| 90 | 추가: raise ValueError(f"보충 버전 커밋 불일치: {package['name']}") | |
| 91 | 추가: records = [] | |
| 92 | 추가: for url in row["files"]: | |
| 93 | 추가: file = data["files"][url] | |
| 94 | 추가: parts = url.split("/") | |
| 95 | 추가: if (len(parts) < 7 or parts[:3] != ["https:", "", "raw.githubusercontent.com"] | |
| 96 | 추가: or parts[5] != row["upstream_ref"] | |
| 97 | 추가: or row["upstream_ref"] not in {row["rev"], row["version"]}): | |
| 98 | 추가: raise ValueError(f"보충 출처 고정 오류: {url}") | |
| 99 | 추가: content = file["text"].encode("utf-8") | |
| 100 | 추가: if file["url"] != url or hashlib.sha256(content).hexdigest() != file["sha256"]: | |
| 101 | 추가: raise ValueError(f"보충 원문 해시 불일치: {url}") | |
| 102 | 추가: records.append({"path": url, "sha256": file["sha256"], "text": file["text"]}) | |
| 103 | 추가: return records | |
| 104 | 추가: | |
| 105 | 추가: | |
| 106 | 추가: def inventory(manifests, project_root=ROOT, supplement_path=ROOT / "packaging/license-supplements.json"): | |
| 75 | 107 | locked = {} |
| 76 | 108 | packages = {} |
| 77 | 109 | for manifest in manifests: |
| @@ -88,6 +120,8 @@ def inventory(manifests, project_root=ROOT): | ||
| 88 | 120 | if not package["source"].startswith("registry+"): |
| 89 | 121 | raise ValueError(f"지원하지 않는 원문 저장소: {key}") |
| 90 | 122 | files = registry_files(package, locked[key]) |
| 123 | 추가: if not files and Path(supplement_path).is_file(): | |
| 124 | 추가: files = supplemental_files(package, supplement_path) | |
| 91 | 125 | else: |
| 92 | 126 | root = Path(project_root).resolve() |
| 93 | 127 | if package["license"] != "MIT" or not Path(package["manifest_path"]).resolve().is_relative_to(root): |
| @@ -104,10 +138,10 @@ def render(records): | ||
| 104 | 138 | missing = [f'{record["name"]}@{record["version"]}' for record in records if not record["files"]] |
| 105 | 139 | if missing: |
| 106 | 140 | raise ValueError(f"라이선스 원문 누락 {len(missing)}개: " + ", ".join(missing)) |
| 107 | 삭제: lines = ["Zipelo third-party licenses", "Cargo.lock 전체 의존성의 로컬 원문 고지", ""] | |
| 141 | 추가: lines = ["Zipelo third-party licenses", "Cargo.lock 전체 의존성의 원문 고지 (로컬 registry 및 고정 upstream 보충)", ""] | |
| 108 | 142 | for record in records: |
| 109 | 143 | lines.extend(["=" * 72, f'Crate: {record["name"]} {record["version"]}', |
| 110 | 삭제: f'Source: {record["source"]}', f'License: {record["license"]}', ""]) | |
| 144 | 추가: f'Source: {record["source"]}', f'License: {record["license"]}', f'Version: {record["version"]}', ""]) | |
| 111 | 145 | for file in record["files"]: |
| 112 | 146 | lines.extend([f'File: {file["path"]}', f'SHA-256: {file["sha256"]}', "", file["text"], ""]) |
| 113 | 147 | return "\n".join(lines) |
| @@ -118,7 +152,7 @@ def generate(manifests, output, audit=None): | ||
| 118 | 152 | if audit: |
| 119 | 153 | Path(audit).write_text(json.dumps(records, ensure_ascii=False, indent=4) + "\n", encoding="utf-8") |
| 120 | 154 | text = render(records) |
| 121 | 삭제: Path(output).write_text(text, encoding="utf-8") | |
| 155 | 추가: Path(output).write_text(text, encoding="utf-8", newline="") | |
| 122 | 156 | return records |
| 123 | 157 | |
| 124 | 158 |
| @@ -19,3 +19,5 @@ sudo로 처음 설치하면 postinst가 SUDO_USER의 ZIP, 7z, TAR.GZ, GZ, TAR | ||
| 19 | 19 | 앱과 작업자의 Cargo.lock 전체 항목을 cargo metadata --locked --offline --all-features와 대조한 뒤 packaging/licenses.py로 THIRD-PARTY-LICENSES.txt를 생성합니다. 로컬 registry 원문과 캐시 crate의 잠금 체크섬을 확인하며 LICENSE, COPYING, NOTICE 등의 원문을 함께 보존합니다. 원문이 없거나 변조됐거나 metadata 대조에서 누락되면 패키지 생성을 중단합니다. |
| 20 | 20 | |
| 21 | 21 | 처음 준비할 때 각 manifest에 cargo +1.99.1 fetch --locked --manifest-path 명령으로 모든 플랫폼의 의존성을 캐시에 받아 두어야 합니다. 고지 생성 중에는 네트워크를 사용하지 않습니다. Windows에는 설치 폴더에, Ubuntu에는 /usr/share/doc/zipelo/THIRD-PARTY-LICENSES.txt에 포함합니다. 파일 동봉 자체가 별도 라이선스 준수 검토를 대신하지는 않습니다. |
| 22 | 추가: | |
| 23 | 추가: 로컬 crate에 원문이 없으면 packaging/license-supplements.json의 해당 버전 공식 upstream 원문을 사용합니다. 보충 파일에는 고정 출처 URL, crate 버전과 VCS 커밋, Cargo SPDX 식, UTF-8 원문과 SHA-256이 들어 있습니다. 생성기는 SPDX와 게시된 crate 커밋 및 원문 해시를 오프라인으로 검증합니다. upstream에도 원문이 없는 항목은 링크 설명만으로 대체하지 않고 계속 빌드를 차단합니다. |
| @@ -50,3 +50,5 @@ ms-settings URI를 사용합니다. | ||
| 50 | 50 | 앱과 작업자의 Cargo.lock 전체 항목을 cargo metadata --locked --offline --all-features와 대조한 뒤 packaging/licenses.py로 THIRD-PARTY-LICENSES.txt를 생성합니다. 로컬 registry 원문과 캐시 crate의 잠금 체크섬을 확인하며 LICENSE, COPYING, NOTICE 등의 원문을 함께 보존합니다. 원문이 없거나 변조됐거나 metadata 대조에서 누락되면 패키지 생성을 중단합니다. |
| 51 | 51 | |
| 52 | 52 | 처음 준비할 때 각 manifest에 cargo +1.99.1 fetch --locked --manifest-path 명령으로 모든 플랫폼의 의존성을 캐시에 받아 두어야 합니다. 고지 생성 중에는 네트워크를 사용하지 않습니다. Windows에는 설치 폴더에, Ubuntu에는 /usr/share/doc/zipelo/THIRD-PARTY-LICENSES.txt에 포함합니다. 파일 동봉 자체가 별도 라이선스 준수 검토를 대신하지는 않습니다. |
| 53 | 추가: | |
| 54 | 추가: 로컬 crate에 원문이 없으면 packaging/license-supplements.json의 해당 버전 공식 upstream 원문을 사용합니다. 보충 파일에는 고정 출처 URL, crate 버전과 VCS 커밋, Cargo SPDX 식, UTF-8 원문과 SHA-256이 들어 있습니다. 생성기는 SPDX와 게시된 crate 커밋 및 원문 해시를 오프라인으로 검증합니다. upstream에도 원문이 없는 항목은 링크 설명만으로 대체하지 않고 계속 빌드를 차단합니다. |
| @@ -23,3 +23,5 @@ python3 packaging/licenses.py --manifest experiments/rust-ui-memory-app/Cargo.to | ||
| 23 | 23 | ``` |
| 24 | 24 | |
| 25 | 25 | 고지의 crate 목록은 두 Cargo.lock과 metadata의 합집합을 기준으로 합니다. 플랫폼이나 활성 기능을 기준으로 항목을 줄이지 않습니다. 원문 파일이 없는 crate는 라이선스 식만으로 대체하지 않으며 최종 파일을 생성하지 않습니다. audit JSON은 누락 원인 확인용이며 배포 고지가 아닙니다. 대조 시험은 원문 보존, 변경된 캐시 거부, metadata 누락과 두 패키지의 조기 중단을 검증합니다. |
| 26 | 추가: | |
| 27 | 추가: 로컬 crate에 원문이 없으면 packaging/license-supplements.json의 해당 버전 공식 upstream 원문을 사용합니다. 보충 파일에는 고정 출처 URL, crate 버전과 VCS 커밋, Cargo SPDX 식, UTF-8 원문과 SHA-256이 들어 있습니다. 생성기는 SPDX와 게시된 crate 커밋 및 원문 해시를 오프라인으로 검증합니다. upstream에도 원문이 없는 항목은 링크 설명만으로 대체하지 않고 계속 빌드를 차단합니다. |
| @@ -113,6 +113,63 @@ class LicenseTests(unittest.TestCase): | ||
| 113 | 113 | self.assertIn("--offline", command) |
| 114 | 114 | self.assertIn("--all-features", command) |
| 115 | 115 | |
| 116 | 추가: def supplement_fixture(self, license="MIT", revision="a" * 40): | |
| 117 | 추가: self.fixture({".cargo_vcs_info.json": json.dumps({"git": {"sha1": "a" * 40}}).encode()}) | |
| 118 | 추가: url = "https://raw.githubusercontent.com/example/sample/" + revision + "/LICENSE" | |
| 119 | 추가: original = "Fixture permission text\\r\\n" | |
| 120 | 추가: data = {"packages": [{"name": "sample", "version": "1.0.0", "license": license, | |
| 121 | 추가: "rev": revision, "upstream_ref": revision, "files": [url]}], | |
| 122 | 추가: "files": {url: {"url": url, "text": original, | |
| 123 | 추가: "sha256": hashlib.sha256(original.encode()).hexdigest()}}} | |
| 124 | 추가: path = self.root / "supplements.json" | |
| 125 | 추가: path.write_text(json.dumps(data)) | |
| 126 | 추가: return path, data, url | |
| 127 | 추가: | |
| 128 | 추가: def test_supplement_preserves_fixed_source_and_original(self): | |
| 129 | 추가: path, data, url = self.supplement_fixture() | |
| 130 | 추가: records = LICENSES.supplemental_files(self.package, path) | |
| 131 | 추가: self.assertEqual(records[0]["path"], url) | |
| 132 | 추가: self.assertEqual(records[0]["text"], data["files"][url]["text"]) | |
| 133 | 추가: | |
| 134 | 추가: def test_supplement_spdx_must_match_metadata(self): | |
| 135 | 추가: path, _, _ = self.supplement_fixture(license="Apache-2.0") | |
| 136 | 추가: with self.assertRaisesRegex(ValueError, "SPDX 불일치"): | |
| 137 | 추가: LICENSES.supplemental_files(self.package, path) | |
| 138 | 추가: | |
| 139 | 추가: def test_supplement_revision_must_match_published_crate(self): | |
| 140 | 추가: path, _, _ = self.supplement_fixture(revision="b" * 40) | |
| 141 | 추가: with self.assertRaisesRegex(ValueError, "커밋 불일치"): | |
| 142 | 추가: LICENSES.supplemental_files(self.package, path) | |
| 143 | 추가: | |
| 144 | 추가: def test_supplement_content_hash_is_verified(self): | |
| 145 | 추가: path, data, url = self.supplement_fixture() | |
| 146 | 추가: data["files"][url]["text"] += "changed" | |
| 147 | 추가: path.write_text(json.dumps(data)) | |
| 148 | 추가: with self.assertRaisesRegex(ValueError, "해시 불일치"): | |
| 149 | 추가: LICENSES.supplemental_files(self.package, path) | |
| 150 | 추가: | |
| 151 | 추가: def test_supplement_requires_fixed_upstream_url(self): | |
| 152 | 추가: path, data, _ = self.supplement_fixture() | |
| 153 | 추가: data["packages"][0]["upstream_ref"] = "main" | |
| 154 | 추가: path.write_text(json.dumps(data)) | |
| 155 | 추가: with self.assertRaisesRegex(ValueError, "출처 고정 오류"): | |
| 156 | 추가: LICENSES.supplemental_files(self.package, path) | |
| 157 | 추가: | |
| 158 | 추가: def test_real_supplement_spdx_matches_offline_metadata(self): | |
| 159 | 추가: manifests = [ROOT / "experiments" / crate / "Cargo.toml" | |
| 160 | 추가: for crate in ["rust-ui-memory-app", "rust-archive-worker"]] | |
| 161 | 추가: records = LICENSES.inventory(manifests) | |
| 162 | 추가: declared = {LICENSES.identity(p): p["license"] | |
| 163 | 추가: for manifest in manifests for p in LICENSES.metadata(manifest)} | |
| 164 | 추가: self.assertEqual({(r["name"], r["version"], r["source"]): r["license"] | |
| 165 | 추가: for r in records}, declared) | |
| 166 | 추가: supplement = json.loads((ROOT / "packaging/license-supplements.json").read_text()) | |
| 167 | 추가: for row in supplement["packages"]: | |
| 168 | 추가: matches = [r for r in records if (r["name"], r["version"]) == (row["name"], row["version"])] | |
| 169 | 추가: self.assertEqual(len(matches), 1) | |
| 170 | 추가: self.assertEqual(matches[0]["license"], row["license"]) | |
| 171 | 추가: self.assertTrue(matches[0]["files"]) | |
| 172 | 추가: | |
| 116 | 173 | def test_both_packagers_stop_before_build_on_missing_licenses(self): |
| 117 | 174 | for builder, binaries in [(WINDOWS, WINDOWS), (UBUNTU, UBUNTU.WINDOWS)]: |
| 118 | 175 | with self.subTest(builder=builder.__name__): |