team-ljyzipelo

공개
67줄3.1 KB
1"""현재 화면과 로컬 Git 기준 화면의 촬영 실행 파일을 준비함."""
2
3import argparse
4import os
5from pathlib import Path
6import subprocess
7import tarfile
8
9ROOT = Path(__file__).resolve().parents[2]
10MANIFEST = Path("experiments/rust-ui-memory-app/Cargo.toml")
11HELPER = Path("tests/rust-app-ui/capture.rs")
12BIN = '\n[[bin]]\nname = "zipelo-ui-capture"\npath = "../../tests/rust-app-ui/capture.rs"\nrequired-features = ["ui-fixture"]\n'
13
14
15def main():
16 parser = argparse.ArgumentParser(description=__doc__)
17 parser.add_argument("--before-ref", default="b10c7eedddd202f83766aa8f001142cdfdb4097c")
18 parser.add_argument("--output", type=Path, default=ROOT / "tests/ui-redesign/runs")
19 parser.add_argument("--target-dir", type=Path, required=True)
20 args = parser.parse_args()
21 output = args.output.resolve()
22 if not output.is_relative_to(ROOT / "tests"):
23 raise ValueError("기준 소스와 실행 파일은 tests/ 안에만 저장함")
24 before = output / "before-src"
25 if before.exists():
26 raise ValueError("기존 기준 소스는 보존함. 새 --output 폴더를 지정하세요")
27 before.mkdir(parents=True)
28 revision = subprocess.check_output(
29 ["git", "rev-parse", "--verify", "--end-of-options", args.before_ref + "^{commit}"],
30 cwd=ROOT, text=True,
31 ).strip()
32 with subprocess.Popen(["git", "archive", revision], cwd=ROOT, stdout=subprocess.PIPE) as archive:
33 with tarfile.open(fileobj=archive.stdout, mode="r|") as source:
34 source.extractall(before, filter="data")
35 if archive.wait() != 0:
36 raise RuntimeError("로컬 기준 소스를 읽지 못함")
37 helper = (ROOT / HELPER).read_text()
38 helper = helper.replace(
39 "self.app.begin_extract();",
40 "self.app.model.begin(start, &mut self.factory);",
41 )
42 helper = helper.replace(
43 'app.add_sources(vec![base.join("읽어주세요.txt"), base.join("사진")]);',
44 "let _ = &mut app;",
45 )
46 helper = helper.replace('self.app.browse_folder("Install");', "")
47 helper = helper.replace('self.app.show_create(false);', "")
48 (before / HELPER).write_text(helper)
49 original = before / MANIFEST
50 original.write_text(original.read_text() + BIN)
51 environment = dict(os.environ, CARGO_TARGET_DIR=str(args.target_dir.resolve()))
52 for variant, root in [("before", before), ("after", ROOT)]:
53 with (output / f"{variant}-build.log").open("w") as log:
54 subprocess.run(
55 ["cargo", "+1.99.1", "build", "--locked", "--offline", "--manifest-path",
56 str(root / MANIFEST), "--features", "ui-fixture", "--bin", "zipelo-ui-capture"],
57 cwd=ROOT, env=environment, stdout=log, stderr=log, check=True,
58 )
59 executable = args.target_dir.resolve() / "debug/zipelo-ui-capture"
60 destination = output / f"{variant}-capture"
61 destination.write_bytes(executable.read_bytes())
62 destination.chmod(executable.stat().st_mode)
63 print(f"기준 커밋 {revision}, 촬영 실행 파일 {output}")
64
65
66if __name__ == "__main__":
67 main()