team-ljyzipelo

공개
83줄3.6 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 shutil.copyfile(Path(__file__).with_name("default-apps"), lib / "default-apps")
25 (lib / "default-apps").chmod(0o755)
26 records = {}
27 docs = stage / "usr/share/doc/zipelo"
28 docs.mkdir(parents=True)
29 WINDOWS.LICENSES.generate(
30 [ROOT / "experiments/rust-ui-memory-app/Cargo.toml", ROOT / "experiments/rust-archive-worker/Cargo.toml"],
31 docs / "THIRD-PARTY-LICENSES.txt",
32 )
33 for name, manifest, binary, features in (
34 ("Zipelo", ROOT / "experiments/rust-ui-memory-app/Cargo.toml", "zipelo-ui-memory-app", ("ui",)),
35 ("zipelo-archive-worker", ROOT / "experiments/rust-archive-worker/Cargo.toml", "zipelo-archive-worker", ()),
36 ):
37 source, records[name] = WINDOWS.build_binary(manifest, binary, Path(args.target_dir).resolve(), args.profile, features, TARGET)
38 shutil.copy2(source, lib / name)
39 if (lib / name).read_bytes()[:4] != b"\x7fELF":
40 raise ValueError("Linux 실행 파일이 아님")
41 (lib / "BUILD-INFO.json").write_text(json.dumps({"target": TARGET, "profile": args.profile, "files": records}, indent=4) + "\n")
42 bindir = stage / "usr/bin"
43 bindir.mkdir()
44 (bindir / "zipelo").symlink_to("../lib/zipelo/Zipelo")
45 desktop = stage / "usr/share/applications"
46 desktop.mkdir(parents=True)
47 shutil.copyfile(Path(__file__).with_name("zipelo.desktop"), desktop / "zipelo.desktop")
48 icons = stage / "usr/share/icons/hicolor/256x256/apps"
49 icons.mkdir(parents=True)
50 shutil.copyfile(ROOT / "experiments/rust-ui-memory-app/src/assets/icons/zipelo-256.png", icons / "zipelo.png")
51 subprocess.run(["desktop-file-validate", str(desktop / "zipelo.desktop")], check=True)
52 shutil.copyfile(ROOT / "LICENSE", docs / "copyright")
53 control = stage / "DEBIAN"
54 control.mkdir()
55 (control / "control").write_text("""Package: zipelo
56Version: 0.2.2
57Architecture: amd64
58Maintainer: Zipelo contributors <[email protected]>
59Section: utils
60Priority: optional
61Depends: libc6 (>= 2.39), libgcc-s1, libx11-6, libxkbcommon0, libxkbcommon-x11-0, libwayland-client0, libegl1, libgl1, libfontconfig1, fonts-noto-cjk, xdg-utils, desktop-file-utils
62Description: Lightweight Rust archive application
63 ZIP, 7z, TAR, GZ and TAR.GZ archive application with a separate worker.
64""")
65 for script in ("postinst", "prerm", "postrm"):
66 shutil.copyfile(Path(__file__).with_name(script), control / script)
67 (control / script).chmod(0o755)
68 package = output / "zipelo_0.2.2_amd64.deb"
69 subprocess.run(["dpkg-deb", "--root-owner-group", "--build", str(stage), str(package)], check=True)
70 print(package)
71 print("SHA-256 " + hashlib.sha256(package.read_bytes()).hexdigest())
72
73
74def main():
75 parser = argparse.ArgumentParser(description=__doc__)
76 parser.add_argument("--output", required=True)
77 parser.add_argument("--target-dir", required=True)
78 parser.add_argument("--profile", choices=("dev", "release"), default="release")
79 build(parser.parse_args())
80
81
82if __name__ == "__main__":
83 main()