| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 5 | common_dir="$(git -C "$repo_root" rev-parse --path-format=absolute --git-common-dir)" |
| 6 | project_root="$(dirname "$common_dir")" |
| 7 | job="${ZIPELO_CI_JOB:-rust-local}" |
| 8 | if [[ ! "$job" =~ ^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$ ]]; then |
| 9 | echo "유효하지 않은 작업명: $job" >&2 |
| 10 | exit 2 |
| 11 | fi |
| 12 | ci_tools="${ZIPELO_CI_TOOLS:-$project_root/tests/work/$job/tools}" |
| 13 | validate_write_tree() { |
| 14 | python3 - "$project_root" "$job" "$ci_tools" <<'PYTHON' |
| 15 | import os |
| 16 | from pathlib import Path |
| 17 | import sys |
| 18 | |
| 19 | project = Path(sys.argv[1]).resolve() |
| 20 | allowed = project / "tests/work" / sys.argv[2] |
| 21 | tools = Path(os.path.abspath(sys.argv[3])) |
| 22 | |
| 23 | |
| 24 | def reject(path): |
| 25 | raise SystemExit(f"작업 폴더 밖의 경로는 허용하지 않음: {path}") |
| 26 | |
| 27 | |
| 28 | for path in (project / "tests", project / "tests/work", allowed): |
| 29 | if path.resolve() != path: |
| 30 | reject(path) |
| 31 | if not tools.is_relative_to(allowed) or tools.resolve() != tools: |
| 32 | reject(tools) |
| 33 | |
| 34 | seen = set() |
| 35 | |
| 36 | |
| 37 | def check(path): |
| 38 | try: |
| 39 | resolved = path.resolve() |
| 40 | except (OSError, RuntimeError): |
| 41 | reject(path) |
| 42 | if not resolved.is_relative_to(allowed): |
| 43 | reject(path) |
| 44 | if path.is_dir(): |
| 45 | identity = (path.stat().st_dev, path.stat().st_ino) |
| 46 | if identity in seen: |
| 47 | return |
| 48 | seen.add(identity) |
| 49 | for child in path.iterdir(): |
| 50 | check(child) |
| 51 | |
| 52 | |
| 53 | if tools.is_dir(): |
| 54 | check(tools) |
| 55 | print(tools) |
| 56 | PYTHON |
| 57 | } |
| 58 | ci_tools="$(validate_write_tree)" |
| 59 | mkdir -p "$ci_tools/downloads" "$ci_tools/mingw" "$ci_tools/cargo" \ |
| 60 | "$ci_tools/rustup" "$ci_tools/tmp" |
| 61 | export CARGO_HOME="$ci_tools/cargo" |
| 62 | export RUSTUP_HOME="$ci_tools/rustup" |
| 63 | export TMPDIR="$ci_tools/tmp" |
| 64 | |
| 65 | # 도구를 프로젝트 안에 풀며 시스템 패키지는 설치하지 않음. |
| 66 | ( |
| 67 | cd "$ci_tools/downloads" |
| 68 | apt-get download \ |
| 69 | gcc-mingw-w64-x86-64-posix \ |
| 70 | g++-mingw-w64-x86-64-posix \ |
| 71 | gcc-mingw-w64-x86-64-posix-runtime \ |
| 72 | gcc-mingw-w64-base \ |
| 73 | binutils-mingw-w64-x86-64 \ |
| 74 | binutils-mingw-w64-base \ |
| 75 | mingw-w64-x86-64-dev \ |
| 76 | mingw-w64-common |
| 77 | for package in ./*.deb; do |
| 78 | validate_write_tree >/dev/null |
| 79 | dpkg-deb -x "$package" "$ci_tools/mingw" |
| 80 | done |
| 81 | ) |
| 82 | validate_write_tree >/dev/null |
| 83 | rustup toolchain install 1.99.1 \ |
| 84 | --profile minimal --no-self-update --target x86_64-pc-windows-gnu |