team-ljyzipelo

공개

설치 정리와 소스별 빌드 회귀 검증을 보완함

작성자
호시노 히나타
작성 시각
커밋
bcf9e37bc4f672d0fbe153f882ed52b2c2f67338
부모
3baafa0
이 시점의 파일 보기

변경된 파일 4개

+139-7
수정packaging/windows/rust/README.md+1-1
@@ -13,7 +13,7 @@ python3 packaging/windows/rust/build.py \
1313
1414Cargo 1.99.1, Windows GNU Rust target, MinGW-w64와 makensis가 필요합니다.
1515도구는 자동 설치하지 않습니다. 기본 profile은 release이고 개발 검증에는 --profile dev를 사용할 수 있습니다.
16삭제: 출력 폴더는 새 경로여야 하며 기존 파일을 덮어쓰지 않습니다. 입력 저장소는 커밋된 상태여야 합니다.
16추가: 출력 폴더는 새 경로여야 하며 기존 파일을 덮어쓰지 않습니다. 입력 저장소는 커밋된 상태여야 합니다. 캐시는 실행 파일과 소스 커밋별로 분리하며 빌드 중 소스 변경을 거부합니다.
1717앱과 작업자 PR이 병합되기 전에는 각 PR의 별도 소스 경로를 인자로 지정합니다.
1818빌드 정보에는 소스 커밋, 실행 파일 SHA-256, target, profile, 기능 목록을 기록합니다.
1919
수정packaging/windows/rust/build.py+18-4
@@ -27,6 +27,16 @@ def pe_machine(path):
2727
2828def build_binary(manifest, binary, target_dir, profile, features=()):
2929 manifest = Path(manifest).resolve(strict=True)
30추가: commit = subprocess.check_output(
31추가: ["git", "-C", str(manifest.parent), "rev-parse", "HEAD"], text=True
32추가: ).strip()
33추가: dirty = subprocess.check_output(
34추가: ["git", "-C", str(manifest.parent), "status", "--porcelain"], text=True
35추가: )
36추가: if dirty.strip():
37추가: raise ValueError("소스에 커밋하지 않은 변경이 있음")
38추가: # 작업 복사본 간 mtime 기반 캐시 혼합을 방지함.
39추가: target_dir = target_dir / binary / commit
3040 command = ["cargo", "+1.99.1", "build", "--locked", "--manifest-path", str(manifest),
3141 "--target", TARGET, "--target-dir", str(target_dir), "--profile", profile,
3242 "--bin", binary]
@@ -42,10 +52,14 @@ def build_binary(manifest, binary, target_dir, profile, features=()):
4252 output = target_dir / TARGET / ("debug" if profile == "dev" else profile) / (binary + ".exe")
4353 if pe_machine(output) != 0x8664:
4454 raise ValueError("x64 Windows 실행 파일이 아님")
45삭제: commit = subprocess.check_output(["git", "-C", str(manifest.parent), "rev-parse", "HEAD"], text=True).strip()
46삭제: dirty = subprocess.check_output(["git", "-C", str(manifest.parent), "status", "--porcelain"], text=True)
47삭제: if dirty.strip():
48삭제: raise ValueError("소스에 커밋하지 않은 변경이 있음")
55추가: current_commit = subprocess.check_output(
56추가: ["git", "-C", str(manifest.parent), "rev-parse", "HEAD"], text=True
57추가: ).strip()
58추가: dirty = subprocess.check_output(
59추가: ["git", "-C", str(manifest.parent), "status", "--porcelain"], text=True
60추가: )
61추가: if current_commit != commit or dirty.strip():
62추가: raise ValueError("빌드 중 소스가 바뀜")
4963 return output, {"commit": commit, "sha256": hashlib.sha256(output.read_bytes()).hexdigest(),
5064 "binary": binary, "features": list(features)}
5165
수정packaging/windows/rust/installer.nsi+59-2
@@ -13,6 +13,7 @@ SetOverwrite off
1313AllowSkipFiles off
1414ShowInstDetails show
1515!define MUI_ABORTWARNING
16추가: !define MUI_CUSTOMFUNCTION_ABORT Rollback
1617!insertmacro MUI_PAGE_WELCOME
1718!insertmacro MUI_PAGE_INSTFILES
1819Page custom FinishCreate
@@ -22,6 +23,10 @@ Page custom FinishCreate
2223Var Dialog
2324Var ApplyButton
2425Var Mutex
26추가: Var RootOwned
27추가: Var ShortcutOwned
28추가: Var UninstallOwned
29추가: Var InstallComplete
2530!define APPKEY "Software\Zipelo-Dev"
2631!define PROGKEY "Software\Classes\ZipeloDev.Archive"
2732!define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Zipelo-Dev"
@@ -33,6 +38,7 @@ Function .onInit
3338 ${EndIf}
3439 SetShellVarContext current
3540 SetRegView 64
41추가: System::Call 'kernel32::SetLastError(i 0)'
3642 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e'
3743 Pop $1
3844 StrCpy $Mutex $0
@@ -67,12 +73,24 @@ Section "Zipelo"
6773 ${ElseIf} $0 != 2
6874 Goto failed
6975 ${EndIf}
76추가: ; 공유 등록 값이 이미 있으면 형식과 관계없이 보존함.
77추가: System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "Software\RegisteredApplications", i 0, i 0x20119, *p.r1) i.r0'
78추가: ${If} $0 == 0
79추가: System::Call 'advapi32::RegQueryValueExW(p r1, w "Zipelo 개발판", p 0, p 0, p 0, p 0) i.r2'
80추가: System::Call 'advapi32::RegCloseKey(p r1)'
81추가: ${If} $2 != 2
82추가: Goto failed
83추가: ${EndIf}
84추가: ${ElseIf} $0 != 2
85추가: Goto failed
86추가: ${EndIf}
7087 IfFileExists "$SMPROGRAMS\Zipelo 개발판.lnk" failed
7188 ClearErrors
7289 CreateDirectory "$LOCALAPPDATA\Programs"
7390 IfErrors failed
7491 System::Call 'kernel32::CreateDirectoryW(w "$INSTDIR", p 0) i.r0'
7592 IntCmp $0 0 failed
93추가: StrCpy $RootOwned 1
7694 SetOutPath "$INSTDIR"
7795 ClearErrors
7896 File "payload\Zipelo.exe"
@@ -84,20 +102,54 @@ Section "Zipelo"
84102 IfErrors failed
85103 WriteINIStr "$INSTDIR\install.ini" "Zipelo" "Location" "$INSTDIR"
86104 IfErrors failed
105추가: StrCpy $ShortcutOwned 1
87106 CreateShortcut "$SMPROGRAMS\Zipelo 개발판.lnk" "$INSTDIR\Zipelo.exe"
88107 IfErrors failed
108추가: StrCpy $UninstallOwned 1
89109 WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo 개발판"
90110 WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0-dev"
91111 WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"'
92112 IfErrors failed
113추가: StrCpy $InstallComplete 1
93114 Goto done
94115failed:
116추가: Call Rollback
95117 SetErrorLevel 1
96삭제: MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 새로 복사한 파일이 남았다면 해당 폴더의 제거 프로그램을 사용하세요."
118추가: MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 이번 설치 항목을 정리했으며, 사용 중이라 지우지 못한 항목은 상세 보기에서 확인하세요."
97119 Abort
98120 done:
99121SectionEnd
100122
123추가: Function Rollback
124추가: ${If} $InstallComplete == 1
125추가: ${OrIf} $RootOwned != 1
126추가: Return
127추가: ${EndIf}
128추가: SetOutPath "$TEMP"
129추가: ${If} $ShortcutOwned == 1
130추가: Delete "$SMPROGRAMS\Zipelo 개발판.lnk"
131추가: ${EndIf}
132추가: ${If} $UninstallOwned == 1
133추가: DeleteRegValue HKCU "${UNKEY}" "DisplayName"
134추가: DeleteRegValue HKCU "${UNKEY}" "DisplayVersion"
135추가: DeleteRegValue HKCU "${UNKEY}" "UninstallString"
136추가: DeleteRegKey /ifempty HKCU "${UNKEY}"
137추가: ${EndIf}
138추가: Delete "$INSTDIR\Zipelo.exe"
139추가: Delete "$INSTDIR\zipelo-archive-worker.exe"
140추가: Delete "$INSTDIR\LICENSE"
141추가: Delete "$INSTDIR\BUILD-INFO.json"
142추가: Delete "$INSTDIR\install.ini"
143추가: Delete "$INSTDIR\Uninstall.exe"
144추가: RMDir "$INSTDIR"
145추가: StrCpy $RootOwned 0
146추가: FunctionEnd
147추가:
148추가: Function .onInstFailed
149추가: Call Rollback
150추가: SetErrorLevel 1
151추가: FunctionEnd
152추가:
101153Function FinishCreate
102154 GetDlgItem $0 $HWNDPARENT 1
103155 SendMessage $0 ${WM_SETTEXT} 0 "STR:마침"
@@ -145,6 +197,7 @@ FunctionEnd
145197Function un.onInit
146198 SetShellVarContext current
147199 SetRegView 64
200추가: System::Call 'kernel32::SetLastError(i 0)'
148201 System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e'
149202 Pop $1
150203 StrCpy $Mutex $0
@@ -170,8 +223,12 @@ Section "Uninstall"
170223 Delete "$INSTDIR\LICENSE"
171224 Delete "$INSTDIR\BUILD-INFO.json"
172225 Delete "$SMPROGRAMS\Zipelo 개발판.lnk"
226추가: IfErrors uninstall_failed
173227 ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함.
174삭제: DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo 개발판"
228추가: ReadRegStr $0 HKCU "Software\RegisteredApplications" "Zipelo 개발판"
229추가: ${If} $0 == "${APPKEY}\Capabilities"
230추가: DeleteRegValue HKCU "Software\RegisteredApplications" "Zipelo 개발판"
231추가: ${EndIf}
175232 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip"
176233 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar"
177234 DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz"
수정tests/ci/test_windows_installer.py+61-0
@@ -2,7 +2,11 @@ import argparse
22import importlib.util
33from pathlib import Path
44import struct
5추가: import shutil
6추가: import subprocess
57import tempfile
8추가: import sys
9추가: from unittest.mock import patch
610import unittest
711
812ROOT = Path(__file__).resolve().parents[2]
@@ -47,3 +51,60 @@ class InstallerInputTests(unittest.TestCase):
4751 self.assertEqual(sentinel.read_bytes(), b"preserve")
4852 self.assertEqual(list(output.iterdir()), [sentinel])
4953 self.assertFalse(args.target_dir.exists())
54추가:
55추가: @unittest.skipUnless(shutil.which("makensis"), "NSIS가 설치되지 않음")
56추가: def test_nsis_compiles_payloads_and_finish_callbacks(self):
57추가: payload = self.root / "payload"
58추가: payload.mkdir()
59추가: for name in ("Zipelo.exe", "zipelo-archive-worker.exe", "LICENSE", "BUILD-INFO.json"):
60추가: (payload / name).write_bytes(b"compile-only test fixture")
61추가: shutil.copyfile(ROOT / "packaging/windows/rust/installer.nsi", self.root / "installer.nsi")
62추가: completed = subprocess.run(["makensis", "-WX", "installer.nsi"], cwd=self.root,
63추가: stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
64추가: self.assertEqual(completed.returncode, 0, completed.stdout)
65추가: installer = self.root / "Zipelo-0.1.0-dev-windows-x64-setup.exe"
66추가: self.assertIn(MODULE.pe_machine(installer), (0x14C, 0x8664))
67추가: self.assertGreater(installer.stat().st_size, 100000)
68추가:
69추가: def test_source_commit_change_cannot_reuse_an_old_binary(self):
70추가: repo = self.root / "source"
71추가: repo.mkdir()
72추가: manifest = repo / "Cargo.toml"
73추가: manifest.write_text("fixture")
74추가: real_run = subprocess.run
75추가: environment = dict(MODULE.os.environ, GIT_AUTHOR_NAME="Zipelo test",
76추가: GIT_AUTHOR_EMAIL="[email protected]", GIT_COMMITTER_NAME="Zipelo test",
77추가: GIT_COMMITTER_EMAIL="[email protected]")
78추가:
79추가: def git(*args):
80추가: real_run(["git", *args], cwd=repo, env=environment, check=True,
81추가: stdout=subprocess.PIPE, stderr=subprocess.PIPE)
82추가:
83추가: git("init", "-b", "features/installer-fixture")
84추가: git("add", ".")
85추가: git("commit", "-m", "첫 시험 소스를 기록함")
86추가:
87추가: def cached_compiler(command, **options):
88추가: if command[0] != "cargo":
89추가: return real_run(command, **options)
90추가: target = Path(command[command.index("--target-dir") + 1])
91추가: output = target / MODULE.TARGET / "debug/fixture.exe"
92추가: output.parent.mkdir(parents=True, exist_ok=True)
93추가: if not output.exists():
94추가: header = b"MZ" + bytes(58) + struct.pack("<I", 128) + bytes(64)
95추가: output.write_bytes(header + b"PE\0\0" + struct.pack("<H", 0x8664)
96추가: + manifest.read_bytes())
97추가: return subprocess.CompletedProcess(command, 0)
98추가:
99추가: with patch.dict(MODULE.os.environ, {"CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER": sys.executable}):
100추가: with patch.object(MODULE.subprocess, "run", side_effect=cached_compiler):
101추가: first, first_record = MODULE.build_binary(manifest, "fixture", self.root / "target", "dev")
102추가: manifest.write_text("changed fixture")
103추가: git("add", ".")
104추가: git("commit", "-m", "변경된 시험 소스를 기록함")
105추가: with patch.object(MODULE.subprocess, "run", side_effect=cached_compiler):
106추가: second, second_record = MODULE.build_binary(manifest, "fixture", self.root / "target", "dev")
107추가: self.assertNotEqual(first_record["commit"], second_record["commit"])
108추가: self.assertNotEqual(first_record["sha256"], second_record["sha256"])
109추가: self.assertTrue(second.read_bytes().endswith(b"changed fixture"))
110추가: self.assertTrue(first.read_bytes().endswith(b"fixture"))