leejunyoung5819wayland-android-remote

공개

Ubuntu(Wayland/X11)에서 Android 기기 화면 미러링 및 원격 제어 (Rust)

121줄4.4 KB
1#!/usr/bin/env python3
2"""실행 파일에 들어가는 Rust 크레이트의 라이선스 원문을 한 파일로 모은다.
3
4MIT·BSD 등은 바이너리를 배포할 때 저작권 고지와 라이선스 원문을 함께 줘야 한다.
5`cargo metadata`로 빌드(비개발) 의존성만 골라, 각 크레이트 폴더의 LICENSE*/COPYING*/NOTICE*
6파일을 이어 붙인다. 원문 파일이 없는 크레이트는 SPDX 식별자만 적는다.
7
8 scripts/third-party-licenses.py [출력 경로] (기본 target/third-party-licenses.txt)
9"""
10
11import json
12import os
13import subprocess
14import sys
15
16PREFIXES = ("license", "licence", "copying", "notice", "unlicense", "copyright")
17
18WTFPL = """ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
19 Version 2, December 2004
20
21 Copyright (C) 2004 Sam Hocevar <[email protected]>
22
23 Everyone is permitted to copy and distribute verbatim or modified
24 copies of this license document, and changing it is allowed as long
25 as the name is changed.
26
27 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
28 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
29
30 0. You just DO WHAT THE FUCK YOU WANT TO.
31"""
32
33
34def fallback(pkg):
35 """원문 파일이 없는 크레이트: 고를 수 있는 라이선스 가운데 원문을 붙일 수 있는 것을 고른다."""
36 lic = pkg.get("license") or ""
37 if "Apache-2.0" in lic:
38 return "Apache-2.0", "(crate ships no license file; used under Apache-2.0, full text at the end of this file)\n"
39 if "WTFPL" in lic:
40 return "WTFPL", WTFPL
41 return None, "(no license file shipped in the crate; SPDX identifier above applies)\n"
42
43
44def build_deps(meta):
45 nodes = {n["id"]: n for n in meta["resolve"]["nodes"]}
46 root = meta["resolve"]["root"]
47 seen, stack = set(), [root]
48 while stack:
49 i = stack.pop()
50 if i in seen:
51 continue
52 seen.add(i)
53 for d in nodes[i]["deps"]:
54 if any(k["kind"] in (None, "build") for k in d["dep_kinds"]):
55 stack.append(d["pkg"])
56 seen.discard(root)
57 return seen
58
59
60def license_files(pkg):
61 root = os.path.dirname(pkg["manifest_path"])
62 files = []
63 if pkg.get("license_file"):
64 files.append(os.path.join(root, pkg["license_file"]))
65 for name in sorted(os.listdir(root)):
66 path = os.path.join(root, name)
67 if os.path.isfile(path) and name.lower().startswith(PREFIXES) and path not in files:
68 files.append(path)
69 return files
70
71
72def main():
73 out_path = sys.argv[1] if len(sys.argv) > 1 else "target/third-party-licenses.txt"
74 meta = json.loads(
75 subprocess.check_output(
76 ["cargo", "metadata", "--format-version", "1", "--locked",
77 "--filter-platform", "x86_64-unknown-linux-gnu"],
78 )
79 )
80 pkgs = {p["id"]: p for p in meta["packages"]}
81 deps = sorted((pkgs[i] for i in build_deps(meta)), key=lambda p: (p["name"], p["version"]))
82
83 parts = [
84 "Android Remote - third-party licenses\n",
85 "The android-remote binary includes the following Rust crates.\n",
86 "FFmpeg and other system libraries are linked dynamically from the distribution.\n\n",
87 ]
88 missing = 0
89 need_apache = False
90 for p in deps:
91 parts.append("=" * 78 + "\n")
92 parts.append(f"{p['name']} {p['version']}\n")
93 parts.append(f"License: {p.get('license') or 'see files below'}\n")
94 if p.get("repository"):
95 parts.append(f"Source: {p['repository']}\n")
96 files = license_files(p)
97 if not files:
98 missing += 1
99 chosen, text = fallback(p)
100 if chosen == "Apache-2.0":
101 need_apache = True
102 parts.append(text)
103 for f in files:
104 parts.append("-" * 78 + f"\n{os.path.basename(f)}:\n\n")
105 with open(f, encoding="utf-8", errors="replace") as fh:
106 parts.append(fh.read().rstrip() + "\n")
107 parts.append("\n")
108
109 if need_apache:
110 parts.append("=" * 78 + "\nApache License 2.0 (full text)\n\n")
111 with open("/usr/share/common-licenses/Apache-2.0", encoding="utf-8") as fh:
112 parts.append(fh.read())
113
114 os.makedirs(os.path.dirname(out_path) or ".", exist_ok=True)
115 with open(out_path, "w", encoding="utf-8") as fh:
116 fh.writelines(parts)
117 print(f"{out_path}: 크레이트 {len(deps)}개, 원문 없는 크레이트 {missing}개")
118
119
120if __name__ == "__main__":
121 main()