|
| 1 | +#!/usr/bin/env bash |
| 2 | +# requires: elf llvm |
| 3 | +source "$(dirname "${BASH_SOURCE[0]}")/_toolchain_env.sh" |
| 4 | +# 1048 -- a git reference with no tag, rev or branch follows the remote's default branch; a |
| 5 | +# reference on the command line takes the same forms (SPEC-001 §5; SPEC-016 §8). |
| 6 | +# |
| 7 | +# The default branch is the one the remote announces (`git ls-remote --symref`), here `trunk`; the |
| 8 | +# lock records it and its commit, and an offline build reads them. A dependency that names two of |
| 9 | +# rev / tag / branch is refused. `--platform git+<url>#tag=<t>` selects a platform from a |
| 10 | +# repository as a manifest's `{ git = ..., tag = ... }` does. |
| 11 | +# |
| 12 | +# Criteria: the build reports the default branch and runs; mcpp.lock names `#branch=trunk@<sha>`; |
| 13 | +# an offline rebuild succeeds; two refs are refused; the platform from git builds its row. |
| 14 | +set -e |
| 15 | +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT |
| 16 | +fail() { echo "FAIL: $1"; [ -n "${2:-}" ] && printf '%s\n' "$2" | tail -20; exit 1; } |
| 17 | +g() { git -c user.name=e2e -c user.email=e2e@example.invalid -c init.defaultBranch=trunk "$@"; } |
| 18 | +mkdir -p "$t/lib/src" "$t/app/src" "$t/toy-platform" "$t/bare/src" |
| 19 | +cat > "$t/lib/mcpp.toml" <<'EOF' |
| 20 | +[package] |
| 21 | +name = "gitlib" |
| 22 | +version = "0.1.0" |
| 23 | +
|
| 24 | +[targets.gitlib] |
| 25 | +kind = "lib" |
| 26 | +EOF |
| 27 | +echo 'int gitlib_value() { return 9; }' > "$t/lib/src/lib.cpp" |
| 28 | +(cd "$t/lib" && g init -q . && g add -A && g commit -qm init) |
| 29 | +cat > "$t/app/mcpp.toml" <<EOF |
| 30 | +[package] |
| 31 | +name = "app" |
| 32 | +version = "0.1.0" |
| 33 | +
|
| 34 | +[dependencies] |
| 35 | +gitlib = { git = "$t/lib" } |
| 36 | +EOF |
| 37 | +echo 'int gitlib_value(); int main() { return gitlib_value(); }' > "$t/app/src/main.cpp" |
| 38 | +cd "$t/app" |
| 39 | + |
| 40 | +out=$("$MCPP" build 2>&1) || fail "the build failed" "$out" |
| 41 | +grep -q "the default branch of .* is trunk" <<<"$out" || fail "the default branch is not reported" "$out" |
| 42 | +set +e; "$(find target -path '*/bin/app' -type f | head -1)"; rc=$?; set -e |
| 43 | +[ "$rc" = 9 ] || fail "the program returned $rc, not 9" |
| 44 | +grep -Eq 'source = "git\+.*#branch=trunk@[0-9a-f]{40}"' mcpp.lock || fail "the lock does not record the branch and its commit" "$(cat mcpp.lock)" |
| 45 | +rm -rf target |
| 46 | +out=$("$MCPP" build --offline 2>&1) || fail "the offline build did not read the lock" "$out" |
| 47 | +echo " ok the default branch is followed, locked, and read offline" |
| 48 | + |
| 49 | +sed -i "s|gitlib = { git = \"$t/lib\" }|gitlib = { git = \"$t/lib\", tag = \"v1\", branch = \"trunk\" }|" mcpp.toml |
| 50 | +out=$("$MCPP" build 2>&1 || true) |
| 51 | +grep -q "names 2 of rev / tag / branch; a git dependency names at most one" <<<"$out" || fail "two refs were not refused" "$out" |
| 52 | +echo " ok a dependency that names two refs is refused" |
| 53 | + |
| 54 | +cat > "$t/toy-platform/mcpp.toml" <<EOF |
| 55 | +[package] |
| 56 | +name = "toy-platform" |
| 57 | +version = "0.1.0" |
| 58 | +
|
| 59 | +[platform] |
| 60 | +toolchain = "llvm@${LLVM_VERSION}" |
| 61 | +
|
| 62 | +[[platform.define]] |
| 63 | +triple = "x86_64-toyos" |
| 64 | +clang-triple = "x86_64-unknown-linux-gnu" |
| 65 | +object-format = "elf" |
| 66 | +execution = "linux" |
| 67 | +
|
| 68 | +[[platform.provider]] |
| 69 | +serves = ["x86_64-toyos"] |
| 70 | +
|
| 71 | +[platform.build] |
| 72 | +cflags = ["-ffreestanding", "-fno-stack-protector", "-fno-pic"] |
| 73 | +
|
| 74 | +[platform.link] |
| 75 | +driver = "compiler" |
| 76 | +
|
| 77 | +[platform.layers] |
| 78 | +"c-abi" = false |
| 79 | +"c++-abi" = false |
| 80 | +"compiler-runtime" = false |
| 81 | +"kernel-abi" = false |
| 82 | +EOF |
| 83 | +(cd "$t/toy-platform" && g init -q . && g add -A && g commit -qm toy && g tag v1) |
| 84 | +cat > "$t/bare/mcpp.toml" <<'EOF' |
| 85 | +[package] |
| 86 | +name = "bare" |
| 87 | +version = "0.1.0" |
| 88 | +
|
| 89 | +[build] |
| 90 | +sources = ["src/*.c"] |
| 91 | +ldflags = ["-nostdlib", "-static", "-no-pie"] |
| 92 | +
|
| 93 | +[targets.bare] |
| 94 | +kind = "bin" |
| 95 | +main = "src/main.c" |
| 96 | +EOF |
| 97 | +printf 'void _start(void) { __asm__ volatile("mov $60, %%eax\\n mov $7, %%edi\\n syscall"); }\n' > "$t/bare/src/main.c" |
| 98 | +cd "$t/bare" |
| 99 | +out=$("$MCPP" build --target x86_64-toyos --platform "git+$t/toy-platform#tag=v1" 2>&1) || fail "the platform from git did not build its row" "$out" |
| 100 | +grep -q "Platform toy-platform 0.1.0" <<<"$out" || fail "the platform is not reported" "$out" |
| 101 | +echo " ok --platform git+<url>#tag=<t> selects the platform from its repository" |
| 102 | +echo "PASS: 1048 a git reference follows the default branch" |
0 commit comments