team-ljyzipelo

공개
78줄3.3 KB
1"""Rust 앱과 작업자를 Ubuntu amd64 패키지로 생성함."""
2
3import argparse
4import hashlib
5import importlib.util
6import json
7from pathlib import Path
8import shutil
9import subprocess
10
11ROOT = Path(__file__).resolve().parents[3]
12SPEC = importlib.util.spec_from_file_location("windows_build", ROOT / "packaging/windows/rust/build.py")
13WINDOWS = importlib.util.module_from_spec(SPEC)
14SPEC.loader.exec_module(WINDOWS)
15TARGET = "x86_64-unknown-linux-gnu"
16
17
18def build(args):
19 output = Path(args.output).resolve()
20 output.mkdir(parents=True, exist_ok=False)
21 stage = output / "stage"
22 lib = stage / "usr/lib/zipelo"
23 lib.mkdir(parents=True)
24 records = {}
25 docs = stage / "usr/share/doc/zipelo"
26 docs.mkdir(parents=True)
27 WINDOWS.LICENSES.generate(
28 [ROOT / "experiments/rust-ui-memory-app/Cargo.toml", ROOT / "experiments/rust-archive-worker/Cargo.toml"],
29 docs / "THIRD-PARTY-LICENSES.txt",
30 )
31 for name, manifest, binary, features in (
32 ("Zipelo", ROOT / "experiments/rust-ui-memory-app/Cargo.toml", "zipelo-ui-memory-app", ("ui",)),
33 ("zipelo-archive-worker", ROOT / "experiments/rust-archive-worker/Cargo.toml", "zipelo-archive-worker", ()),
34 ):
35 source, records[name] = WINDOWS.build_binary(manifest, binary, Path(args.target_dir).resolve(), args.profile, features, TARGET)
36 shutil.copy2(source, lib / name)
37 if (lib / name).read_bytes()[:4] != b"\x7fELF":
38 raise ValueError("Linux 실행 파일이 아님")
39 (lib / "BUILD-INFO.json").write_text(json.dumps({"target": TARGET, "profile": args.profile, "files": records}, indent=4) + "\n")
40 bindir = stage / "usr/bin"
41 bindir.mkdir()
42 (bindir / "zipelo").symlink_to("../lib/zipelo/Zipelo")
43 desktop = stage / "usr/share/applications"
44 desktop.mkdir(parents=True)
45 shutil.copyfile(Path(__file__).with_name("zipelo.desktop"), desktop / "zipelo.desktop")
46 subprocess.run(["desktop-file-validate", str(desktop / "zipelo.desktop")], check=True)
47 shutil.copyfile(ROOT / "LICENSE", docs / "copyright")
48 control = stage / "DEBIAN"
49 control.mkdir()
50 (control / "control").write_text("""Package: zipelo
51Version: 0.1.0~dev1
52Architecture: amd64
53Maintainer: Zipelo contributors <[email protected]>
54Section: utils
55Priority: optional
56Depends: libc6 (>= 2.39), libgcc-s1, libx11-6, libxkbcommon0, libwayland-client0, libegl1, libgl1, libfontconfig1, fonts-noto-cjk, xdg-utils, desktop-file-utils
57Description: Lightweight Rust archive application
58 ZIP, 7z, TAR, GZ and TAR.GZ archive application with a separate worker.
59""")
60 for script in ("postinst", "postrm"):
61 shutil.copyfile(Path(__file__).with_name(script), control / script)
62 (control / script).chmod(0o755)
63 package = output / "zipelo_0.1.0~dev1_amd64.deb"
64 subprocess.run(["dpkg-deb", "--root-owner-group", "--build", str(stage), str(package)], check=True)
65 print(package)
66 print("SHA-256 " + hashlib.sha256(package.read_bytes()).hexdigest())
67
68
69def main():
70 parser = argparse.ArgumentParser(description=__doc__)
71 parser.add_argument("--output", required=True)
72 parser.add_argument("--target-dir", required=True)
73 parser.add_argument("--profile", choices=("dev", "release"), default="release")
74 build(parser.parse_args())
75
76
77if __name__ == "__main__":
78 main()