team-ljyzipelo

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