team-ljyzipelo

공개
81줄3.5 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 icons = stage / "usr/share/icons/hicolor/256x256/apps"
47 icons.mkdir(parents=True)
48 shutil.copyfile(ROOT / "experiments/rust-ui-memory-app/src/assets/icons/zipelo-256.png", icons / "zipelo.png")
49 subprocess.run(["desktop-file-validate", str(desktop / "zipelo.desktop")], check=True)
50 shutil.copyfile(ROOT / "LICENSE", docs / "copyright")
51 control = stage / "DEBIAN"
52 control.mkdir()
53 (control / "control").write_text("""Package: zipelo
54Version: 0.1.0
55Architecture: amd64
56Maintainer: Zipelo contributors <[email protected]>
57Section: utils
58Priority: optional
59Depends: libc6 (>= 2.39), libgcc-s1, libx11-6, libxkbcommon0, libwayland-client0, libegl1, libgl1, libfontconfig1, fonts-noto-cjk, xdg-utils, desktop-file-utils
60Description: Lightweight Rust archive application
61 ZIP, 7z, TAR, GZ and TAR.GZ archive application with a separate worker.
62""")
63 for script in ("postinst", "postrm"):
64 shutil.copyfile(Path(__file__).with_name(script), control / script)
65 (control / script).chmod(0o755)
66 package = output / "zipelo_0.1.0_amd64.deb"
67 subprocess.run(["dpkg-deb", "--root-owner-group", "--build", str(stage), str(package)], check=True)
68 print(package)
69 print("SHA-256 " + hashlib.sha256(package.read_bytes()).hexdigest())
70
71
72def main():
73 parser = argparse.ArgumentParser(description=__doc__)
74 parser.add_argument("--output", required=True)
75 parser.add_argument("--target-dir", required=True)
76 parser.add_argument("--profile", choices=("dev", "release"), default="release")
77 build(parser.parse_args())
78
79
80if __name__ == "__main__":
81 main()