설치 정리와 소스별 빌드 회귀 검증을 보완함
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
bcf9e37bc4f672d0fbe153f882ed52b2c2f67338- 부모
- 3baafa0
변경된 파일 4개
+139-7| @@ -13,7 +13,7 @@ python3 packaging/windows/rust/build.py \ | ||
| 13 | 13 | |
| 14 | 14 | Cargo 1.99.1, Windows GNU Rust target, MinGW-w64와 makensis가 필요합니다. |
| 15 | 15 | 도구는 자동 설치하지 않습니다. 기본 profile은 release이고 개발 검증에는 --profile dev를 사용할 수 있습니다. |
| 16 | 삭제: 출력 폴더는 새 경로여야 하며 기존 파일을 덮어쓰지 않습니다. 입력 저장소는 커밋된 상태여야 합니다. | |
| 16 | 추가: 출력 폴더는 새 경로여야 하며 기존 파일을 덮어쓰지 않습니다. 입력 저장소는 커밋된 상태여야 합니다. 캐시는 실행 파일과 소스 커밋별로 분리하며 빌드 중 소스 변경을 거부합니다. | |
| 17 | 17 | 앱과 작업자 PR이 병합되기 전에는 각 PR의 별도 소스 경로를 인자로 지정합니다. |
| 18 | 18 | 빌드 정보에는 소스 커밋, 실행 파일 SHA-256, target, profile, 기능 목록을 기록합니다. |
| 19 | 19 |
| @@ -27,6 +27,16 @@ def pe_machine(path): | ||
| 27 | 27 | |
| 28 | 28 | def build_binary(manifest, binary, target_dir, profile, features=()): |
| 29 | 29 | 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 | |
| 30 | 40 | command = ["cargo", "+1.99.1", "build", "--locked", "--manifest-path", str(manifest), |
| 31 | 41 | "--target", TARGET, "--target-dir", str(target_dir), "--profile", profile, |
| 32 | 42 | "--bin", binary] |
| @@ -42,10 +52,14 @@ def build_binary(manifest, binary, target_dir, profile, features=()): | ||
| 42 | 52 | output = target_dir / TARGET / ("debug" if profile == "dev" else profile) / (binary + ".exe") |
| 43 | 53 | if pe_machine(output) != 0x8664: |
| 44 | 54 | 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("빌드 중 소스가 바뀜") | |
| 49 | 63 | return output, {"commit": commit, "sha256": hashlib.sha256(output.read_bytes()).hexdigest(), |
| 50 | 64 | "binary": binary, "features": list(features)} |
| 51 | 65 |
| @@ -13,6 +13,7 @@ SetOverwrite off | ||
| 13 | 13 | AllowSkipFiles off |
| 14 | 14 | ShowInstDetails show |
| 15 | 15 | !define MUI_ABORTWARNING |
| 16 | 추가: !define MUI_CUSTOMFUNCTION_ABORT Rollback | |
| 16 | 17 | !insertmacro MUI_PAGE_WELCOME |
| 17 | 18 | !insertmacro MUI_PAGE_INSTFILES |
| 18 | 19 | Page custom FinishCreate |
| @@ -22,6 +23,10 @@ Page custom FinishCreate | ||
| 22 | 23 | Var Dialog |
| 23 | 24 | Var ApplyButton |
| 24 | 25 | Var Mutex |
| 26 | 추가: Var RootOwned | |
| 27 | 추가: Var ShortcutOwned | |
| 28 | 추가: Var UninstallOwned | |
| 29 | 추가: Var InstallComplete | |
| 25 | 30 | !define APPKEY "Software\Zipelo-Dev" |
| 26 | 31 | !define PROGKEY "Software\Classes\ZipeloDev.Archive" |
| 27 | 32 | !define UNKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Zipelo-Dev" |
| @@ -33,6 +38,7 @@ Function .onInit | ||
| 33 | 38 | ${EndIf} |
| 34 | 39 | SetShellVarContext current |
| 35 | 40 | SetRegView 64 |
| 41 | 추가: System::Call 'kernel32::SetLastError(i 0)' | |
| 36 | 42 | System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e' |
| 37 | 43 | Pop $1 |
| 38 | 44 | StrCpy $Mutex $0 |
| @@ -67,12 +73,24 @@ Section "Zipelo" | ||
| 67 | 73 | ${ElseIf} $0 != 2 |
| 68 | 74 | Goto failed |
| 69 | 75 | ${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} | |
| 70 | 87 | IfFileExists "$SMPROGRAMS\Zipelo 개발판.lnk" failed |
| 71 | 88 | ClearErrors |
| 72 | 89 | CreateDirectory "$LOCALAPPDATA\Programs" |
| 73 | 90 | IfErrors failed |
| 74 | 91 | System::Call 'kernel32::CreateDirectoryW(w "$INSTDIR", p 0) i.r0' |
| 75 | 92 | IntCmp $0 0 failed |
| 93 | 추가: StrCpy $RootOwned 1 | |
| 76 | 94 | SetOutPath "$INSTDIR" |
| 77 | 95 | ClearErrors |
| 78 | 96 | File "payload\Zipelo.exe" |
| @@ -84,20 +102,54 @@ Section "Zipelo" | ||
| 84 | 102 | IfErrors failed |
| 85 | 103 | WriteINIStr "$INSTDIR\install.ini" "Zipelo" "Location" "$INSTDIR" |
| 86 | 104 | IfErrors failed |
| 105 | 추가: StrCpy $ShortcutOwned 1 | |
| 87 | 106 | CreateShortcut "$SMPROGRAMS\Zipelo 개발판.lnk" "$INSTDIR\Zipelo.exe" |
| 88 | 107 | IfErrors failed |
| 108 | 추가: StrCpy $UninstallOwned 1 | |
| 89 | 109 | WriteRegStr HKCU "${UNKEY}" "DisplayName" "Zipelo 개발판" |
| 90 | 110 | WriteRegStr HKCU "${UNKEY}" "DisplayVersion" "0.1.0-dev" |
| 91 | 111 | WriteRegStr HKCU "${UNKEY}" "UninstallString" '$\"$INSTDIR\Uninstall.exe$\"' |
| 92 | 112 | IfErrors failed |
| 113 | 추가: StrCpy $InstallComplete 1 | |
| 93 | 114 | Goto done |
| 94 | 115 | failed: |
| 116 | 추가: Call Rollback | |
| 95 | 117 | SetErrorLevel 1 |
| 96 | 삭제: MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 새로 복사한 파일이 남았다면 해당 폴더의 제거 프로그램을 사용하세요." | |
| 118 | 추가: MessageBox MB_OK|MB_ICONSTOP "설치를 완료하지 못했습니다. 기존 Zipelo 개발판이 있으면 먼저 제거하고, 여유 공간과 쓰기 권한을 확인하세요. 이번 설치 항목을 정리했으며, 사용 중이라 지우지 못한 항목은 상세 보기에서 확인하세요." | |
| 97 | 119 | Abort |
| 98 | 120 | done: |
| 99 | 121 | SectionEnd |
| 100 | 122 | |
| 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 | 추가: | |
| 101 | 153 | Function FinishCreate |
| 102 | 154 | GetDlgItem $0 $HWNDPARENT 1 |
| 103 | 155 | SendMessage $0 ${WM_SETTEXT} 0 "STR:마침" |
| @@ -145,6 +197,7 @@ FunctionEnd | ||
| 145 | 197 | Function un.onInit |
| 146 | 198 | SetShellVarContext current |
| 147 | 199 | SetRegView 64 |
| 200 | 추가: System::Call 'kernel32::SetLastError(i 0)' | |
| 148 | 201 | System::Call 'kernel32::CreateMutexW(p 0, i 0, w "Local\ZipeloDevSetup") p.r0 ?e' |
| 149 | 202 | Pop $1 |
| 150 | 203 | StrCpy $Mutex $0 |
| @@ -170,8 +223,12 @@ Section "Uninstall" | ||
| 170 | 223 | Delete "$INSTDIR\LICENSE" |
| 171 | 224 | Delete "$INSTDIR\BUILD-INFO.json" |
| 172 | 225 | Delete "$SMPROGRAMS\Zipelo 개발판.lnk" |
| 226 | 추가: IfErrors uninstall_failed | |
| 173 | 227 | ; 자신이 등록한 값만 제거하고 다른 파일과 키를 보존함. |
| 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} | |
| 175 | 232 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".zip" |
| 176 | 233 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".tar" |
| 177 | 234 | DeleteRegValue HKCU "${APPKEY}\Capabilities\FileAssociations" ".gz" |
| @@ -2,7 +2,11 @@ import argparse | ||
| 2 | 2 | import importlib.util |
| 3 | 3 | from pathlib import Path |
| 4 | 4 | import struct |
| 5 | 추가: import shutil | |
| 6 | 추가: import subprocess | |
| 5 | 7 | import tempfile |
| 8 | 추가: import sys | |
| 9 | 추가: from unittest.mock import patch | |
| 6 | 10 | import unittest |
| 7 | 11 | |
| 8 | 12 | ROOT = Path(__file__).resolve().parents[2] |
| @@ -47,3 +51,60 @@ class InstallerInputTests(unittest.TestCase): | ||
| 47 | 51 | self.assertEqual(sentinel.read_bytes(), b"preserve") |
| 48 | 52 | self.assertEqual(list(output.iterdir()), [sentinel]) |
| 49 | 53 | 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")) |