별도 체크아웃별 라이선스 검증을 수정함
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
78ffdc279d58568e4334eacbc1e36d53e16c7e58- 부모
- cc455f9
변경된 파일 3개
+103-26| @@ -142,35 +142,51 @@ def supplemental_files(package, supplement_path): | ||
| 142 | 142 | return records |
| 143 | 143 | |
| 144 | 144 | |
| 145 | 삭제: def inventory(manifests, project_root=ROOT, supplement_path=ROOT / "packaging/license-supplements.json"): | |
| 146 | 삭제: locked = {} | |
| 147 | 삭제: packages = {} | |
| 145 | 추가: def repository_root(manifest): | |
| 146 | 추가: result = subprocess.run( | |
| 147 | 추가: ["git", "-C", str(manifest.parent), "rev-parse", "--show-toplevel"], | |
| 148 | 추가: check=True, capture_output=True, text=True, | |
| 149 | 추가: ) | |
| 150 | 추가: return Path(result.stdout.strip()).resolve(strict=True) | |
| 151 | 추가: | |
| 152 | 추가: | |
| 153 | 추가: def inventory(manifests, project_root=None, supplement_path=ROOT / "packaging/license-supplements.json"): | |
| 154 | 추가: records = {} | |
| 148 | 155 | for manifest in manifests: |
| 149 | 156 | manifest = Path(manifest).resolve(strict=True) |
| 150 | 157 | lock = tomllib.loads(manifest.with_name("Cargo.lock").read_text()) |
| 151 | 삭제: locked.update({identity(package): package for package in lock["package"]}) | |
| 152 | 삭제: packages.update({identity(package): package for package in metadata(manifest)}) | |
| 153 | 삭제: if set(locked) != set(packages): | |
| 154 | 삭제: raise ValueError(f"Cargo.lock/metadata 불일치: 누락 {sorted(set(locked) - set(packages))}, " | |
| 155 | 삭제: f"추가 {sorted(set(packages) - set(locked))}") | |
| 156 | 삭제: records = [] | |
| 157 | 삭제: for key, package in sorted(packages.items()): | |
| 158 | 삭제: if package.get("source"): | |
| 159 | 삭제: if not package["source"].startswith("registry+"): | |
| 160 | 삭제: raise ValueError(f"지원하지 않는 원문 저장소: {key}") | |
| 161 | 삭제: files = registry_files(package, locked[key]) | |
| 162 | 삭제: if not files and Path(supplement_path).is_file(): | |
| 163 | 삭제: files = supplemental_files(package, supplement_path) | |
| 164 | 삭제: else: | |
| 165 | 삭제: root = Path(project_root).resolve() | |
| 166 | 삭제: if package["license"] != "MIT" or not Path(package["manifest_path"]).resolve().is_relative_to(root): | |
| 167 | 삭제: raise ValueError(f"프로젝트 라이선스 범위 확인 필요: {key}") | |
| 168 | 삭제: content = (root / "LICENSE").read_bytes() | |
| 169 | 삭제: files = [{"path": "project/LICENSE", "sha256": hashlib.sha256(content).hexdigest(), | |
| 170 | 삭제: "text": content.decode("utf-8")}] | |
| 171 | 삭제: records.append({"name": key[0], "version": key[1], "source": key[2], | |
| 172 | 삭제: "license": package["license"], "files": files}) | |
| 173 | 삭제: return records | |
| 158 | 추가: locked = {identity(package): package for package in lock["package"]} | |
| 159 | 추가: packages = {identity(package): package for package in metadata(manifest)} | |
| 160 | 추가: if set(locked) != set(packages): | |
| 161 | 추가: raise ValueError(f"Cargo.lock/metadata 불일치: 누락 {sorted(set(locked) - set(packages))}, " | |
| 162 | 추가: f"추가 {sorted(set(packages) - set(locked))}") | |
| 163 | 추가: root = None | |
| 164 | 추가: for key, package in sorted(packages.items()): | |
| 165 | 추가: if package.get("source"): | |
| 166 | 추가: if not package["source"].startswith("registry+"): | |
| 167 | 추가: raise ValueError(f"지원하지 않는 원문 저장소: {key}") | |
| 168 | 추가: files = registry_files(package, locked[key]) | |
| 169 | 추가: if not files and Path(supplement_path).is_file(): | |
| 170 | 추가: files = supplemental_files(package, supplement_path) | |
| 171 | 추가: else: | |
| 172 | 추가: if root is None: | |
| 173 | 추가: root = Path(project_root).resolve() if project_root else repository_root(manifest) | |
| 174 | 추가: if (package["license"] != "MIT" | |
| 175 | 추가: or not Path(package["manifest_path"]).resolve().is_relative_to(root)): | |
| 176 | 추가: raise ValueError(f"프로젝트 라이선스 범위 확인 필요: {key}") | |
| 177 | 추가: content = (root / "LICENSE").read_bytes() | |
| 178 | 추가: files = [{"path": "project/LICENSE", "sha256": hashlib.sha256(content).hexdigest(), | |
| 179 | 추가: "text": content.decode("utf-8")}] | |
| 180 | 추가: if key in records: | |
| 181 | 추가: if records[key]["license"] != package["license"]: | |
| 182 | 추가: raise ValueError(f"입력 저장소 간 SPDX 불일치: {key}") | |
| 183 | 추가: for file in files: | |
| 184 | 추가: if file not in records[key]["files"]: | |
| 185 | 추가: records[key]["files"].append(file) | |
| 186 | 추가: else: | |
| 187 | 추가: records[key] = {"name": key[0], "version": key[1], "source": key[2], | |
| 188 | 추가: "license": package["license"], "files": files} | |
| 189 | 추가: return [records[key] for key in sorted(records)] | |
| 174 | 190 | |
| 175 | 191 | |
| 176 | 192 | def render(records): |
| @@ -49,6 +49,8 @@ ms-settings URI를 사용합니다. | ||
| 49 | 49 | |
| 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 | 추가: 별도 체크아웃을 입력하면 각 manifest가 속한 Git 저장소의 LICENSE와 로컬 패키지의 MIT 선언 및 경로 범위를 따로 검증합니다. 두 입력의 Cargo.lock과 metadata도 각각 대조한 뒤 고지를 합치며, 같은 이름과 버전의 패키지라도 서로 다른 저작권 고지는 모두 보존합니다. | |
| 53 | 추가: | |
| 52 | 54 | 처음 준비할 때 각 manifest에 cargo +1.99.1 fetch --locked --manifest-path 명령으로 모든 플랫폼의 의존성을 캐시에 받아 두어야 합니다. 고지 생성 중에는 네트워크를 사용하지 않습니다. Windows에는 설치 폴더에, Ubuntu에는 /usr/share/doc/zipelo/THIRD-PARTY-LICENSES.txt에 포함합니다. 파일 동봉 자체가 별도 라이선스 준수 검토를 대신하지는 않습니다. |
| 53 | 55 | |
| 54 | 56 | 로컬 crate에 원문이 없으면 packaging/license-supplements.json의 해당 버전 공식 upstream 원문을 사용합니다. 보충 파일에는 고정 출처 URL, crate 버전과 VCS 커밋, Cargo SPDX 식, UTF-8 원문과 SHA-256이 들어 있습니다. 생성기는 SPDX와 게시된 crate 커밋 및 원문 해시를 오프라인으로 검증합니다. 승인된 표준 보충도 없는 항목은 링크 설명만으로 대체하지 않고 계속 빌드를 차단합니다. |
| @@ -88,6 +88,65 @@ class LicenseTests(unittest.TestCase): | ||
| 88 | 88 | with self.assertRaisesRegex(ValueError, "Cargo.lock/metadata 불일치"): |
| 89 | 89 | LICENSES.inventory([self.manifest], self.root) |
| 90 | 90 | |
| 91 | 추가: def checkout_fixture(self, name, license_text): | |
| 92 | 추가: checkout = self.root / name | |
| 93 | 추가: crate = checkout / "experiments" / "shared" | |
| 94 | 추가: crate.mkdir(parents=True) | |
| 95 | 추가: subprocess.run(["git", "init", "-q", str(checkout)], check=True) | |
| 96 | 추가: (checkout / "LICENSE").write_text(license_text) | |
| 97 | 추가: (crate / "Cargo.toml").write_text( | |
| 98 | 추가: '[workspace]\n[package]\nname = "shared"\nversion = "1.0.0"\nlicense = "MIT"\n' | |
| 99 | 추가: ) | |
| 100 | 추가: (crate / "src").mkdir() | |
| 101 | 추가: (crate / "src/lib.rs").write_text("") | |
| 102 | 추가: (crate / "Cargo.lock").write_text( | |
| 103 | 추가: 'version = 4\n[[package]]\nname = "shared"\nversion = "1.0.0"\n' | |
| 104 | 추가: ) | |
| 105 | 추가: return crate / "Cargo.toml" | |
| 106 | 추가: | |
| 107 | 추가: def test_separate_checkouts_preserve_each_repository_license(self): | |
| 108 | 추가: app = self.checkout_fixture("app-checkout", "App copyright\n") | |
| 109 | 추가: worker = self.checkout_fixture("worker-checkout", "Worker copyright\n") | |
| 110 | 추가: records = LICENSES.inventory([app, worker]) | |
| 111 | 추가: self.assertEqual(len(records), 1) | |
| 112 | 추가: self.assertEqual( | |
| 113 | 추가: {file["text"] for file in records[0]["files"]}, | |
| 114 | 추가: {"App copyright\n", "Worker copyright\n"}, | |
| 115 | 추가: ) | |
| 116 | 추가: args = SimpleNamespace(output=self.root / "windows", target_dir=self.root / "target", | |
| 117 | 추가: profile="release", app_manifest=app, worker_manifest=worker) | |
| 118 | 추가: with patch.object(WINDOWS, "build_binary", side_effect=RuntimeError("compile reached")) as build: | |
| 119 | 추가: with self.assertRaisesRegex(RuntimeError, "compile reached"): | |
| 120 | 추가: WINDOWS.build(args) | |
| 121 | 추가: self.assertEqual(build.call_args.args[0], app) | |
| 122 | 추가: notice = (args.output / "payload/THIRD-PARTY-LICENSES.txt").read_text() | |
| 123 | 추가: self.assertIn("App copyright", notice) | |
| 124 | 추가: self.assertIn("Worker copyright", notice) | |
| 125 | 추가: | |
| 126 | 추가: def test_second_checkout_license_is_validated_before_deduplication(self): | |
| 127 | 추가: app = self.checkout_fixture("app-checkout", "App copyright\n") | |
| 128 | 추가: worker = self.checkout_fixture("worker-checkout", "Worker copyright\n") | |
| 129 | 추가: worker.write_text(worker.read_text().replace('license = "MIT"', 'license = "Apache-2.0"')) | |
| 130 | 추가: with self.assertRaisesRegex(ValueError, "프로젝트 라이선스 범위"): | |
| 131 | 추가: LICENSES.inventory([app, worker]) | |
| 132 | 추가: | |
| 133 | 추가: def test_external_path_dependency_is_not_covered_by_input_license(self): | |
| 134 | 추가: app = self.checkout_fixture("app-checkout", "App copyright\n") | |
| 135 | 추가: foreign = self.checkout_fixture("foreign-checkout", "Foreign copyright\n") | |
| 136 | 추가: package = LICENSES.metadata(app)[0] | |
| 137 | 추가: package["manifest_path"] = str(foreign) | |
| 138 | 추가: with patch.object(LICENSES, "metadata", return_value=[package]): | |
| 139 | 추가: with self.assertRaisesRegex(ValueError, "프로젝트 라이선스 범위"): | |
| 140 | 추가: LICENSES.inventory([app]) | |
| 141 | 추가: | |
| 142 | 추가: def test_each_input_lock_is_checked_before_merging(self): | |
| 143 | 추가: app = self.checkout_fixture("app-checkout", "App copyright\n") | |
| 144 | 추가: worker = self.checkout_fixture("worker-checkout", "Worker copyright\n") | |
| 145 | 추가: package = LICENSES.metadata(app)[0] | |
| 146 | 추가: with patch.object(LICENSES, "metadata", side_effect=[[package], []]): | |
| 147 | 추가: with self.assertRaisesRegex(ValueError, "Cargo.lock/metadata 불일치"): | |
| 148 | 추가: LICENSES.inventory([app, worker]) | |
| 149 | 추가: | |
| 91 | 150 | def test_modified_registry_license_is_rejected(self): |
| 92 | 151 | locked = self.fixture({"LICENSE": b"Fixture license"}) |
| 93 | 152 | (self.registry / "LICENSE").write_bytes(b"Modified license") |