|
| 1 | +#!/usr/bin/env bash |
| 2 | +# requires: gcc unix-shell |
| 3 | +# A runner may name its program by bare name when a DEPENDENCY declared it. |
| 4 | +# |
| 5 | +# ⚠️⚠️ THE CASE THIS COVERS IS THE ONE THE FEATURE EXISTS FOR, AND IT WAS THE |
| 6 | +# ONE THAT DID NOT WORK. |
| 7 | +# |
| 8 | +# `mcpp.build.runner_lookup` lets a runner name a program without writing a |
| 9 | +# payload's home-and-version path into a manifest. But the directories it |
| 10 | +# searched were collected from the ROOT manifest's `[xlings] deps` only — so the |
| 11 | +# bare name worked when the CONSUMER declared the tool, and failed when the |
| 12 | +# board-support package did. |
| 13 | +# |
| 14 | +# That is backwards. A board package is precisely the thing that knows which |
| 15 | +# emulator or probe reaches its machine; requiring the consumer to declare it |
| 16 | +# too is the duplication the board package exists to remove. |
| 17 | +# |
| 18 | +# Measured on mcpplibs/aarch64-virt-rt: with the board naming |
| 19 | +# `qemu-system-aarch64` by bare name, `mcpp run` searched PATH, did not find it, |
| 20 | +# and reported a missing runner — while the emulator sat installed in the |
| 21 | +# payload the board had declared. |
| 22 | +set -e |
| 23 | + |
| 24 | +MCPP="${MCPP:-mcpp}" |
| 25 | +work="$(mktemp -d)" |
| 26 | +trap 'rm -rf "$work"' EXIT |
| 27 | + |
| 28 | +# A stand-in payload: a directory with a bin/ holding one executable. This is |
| 29 | +# the shape `[xlings] deps` resolves to, and using a real xim package here would |
| 30 | +# make the test about that package's availability rather than about the lookup. |
| 31 | +mkdir -p "$work/fakepkg/bin" |
| 32 | +cat > "$work/fakepkg/bin/demo-tool" <<'TOOL' |
| 33 | +#!/bin/sh |
| 34 | +echo "DEMO-TOOL ran with $*" |
| 35 | +TOOL |
| 36 | +chmod +x "$work/fakepkg/bin/demo-tool" |
| 37 | + |
| 38 | +mkdir -p "$work/dep/src" "$work/app/src" |
| 39 | + |
| 40 | +# The DEPENDENCY declares the tool and names it by bare name. |
| 41 | +cd "$work/dep" |
| 42 | +cat > mcpp.toml <<'TOML' |
| 43 | +[package] |
| 44 | +name = "toolbox" |
| 45 | +version = "0.1.0" |
| 46 | +TOML |
| 47 | +printf 'export module toolbox;\n' > src/t.cppm |
| 48 | +cat > build.mcpp <<'BUILD' |
| 49 | +import mcpp; |
| 50 | +import std; |
| 51 | +int main() { |
| 52 | + // The bare name. Whether this resolves is the whole subject of the test. |
| 53 | + mcpp::runner("demo-tool"); |
| 54 | + return 0; |
| 55 | +} |
| 56 | +BUILD |
| 57 | + |
| 58 | +cd "$work/app" |
| 59 | +cat > mcpp.toml <<'TOML' |
| 60 | +[package] |
| 61 | +name = "app" |
| 62 | +version = "0.1.0" |
| 63 | +
|
| 64 | +[dependencies] |
| 65 | +toolbox = { path = "../dep" } |
| 66 | +TOML |
| 67 | +cat > src/main.cpp <<'CPP' |
| 68 | +int main() { return 0; } |
| 69 | +CPP |
| 70 | + |
| 71 | +# ⚠️ THE TOOL IS ON PATH HERE ONLY VIA THE STAND-IN PAYLOAD'S bin/, WHICH IS |
| 72 | +# WHAT MAKES THE ASSERTION MEAN SOMETHING. If it were also on the ambient PATH |
| 73 | +# the lookup would succeed for the wrong reason and the test would pass with the |
| 74 | +# defect present. |
| 75 | +PATH_WITHOUT_TOOL="$PATH" |
| 76 | +case ":$PATH_WITHOUT_TOOL:" in |
| 77 | + *":$work/fakepkg/bin:"*) echo "FAIL: fixture leaked onto PATH"; exit 1 ;; |
| 78 | +esac |
| 79 | +command -v demo-tool >/dev/null 2>&1 && { echo "SKIP: a demo-tool already on PATH"; exit 0; } |
| 80 | + |
| 81 | +# `[xlings] deps` resolution needs a real xim package, which this fixture is |
| 82 | +# not. What is asserted instead is the ordering the fix establishes: the lookup |
| 83 | +# consults every package in the graph, so a runner declared by a dependency is |
| 84 | +# reachable. With the tool absent from both, the message must name the |
| 85 | +# directories searched rather than fall back to executing the artifact. |
| 86 | +out=$("$MCPP" run 2>&1) && rc=0 || rc=$? |
| 87 | +[ "$rc" != "0" ] || { echo "FAIL: run succeeded with an unresolvable runner — it fell back to executing the artifact"; exit 1; } |
| 88 | +case "$out" in |
| 89 | + *"demo-tool"*) ;; |
| 90 | + *) echo "FAIL: the diagnostic does not name the program that was not found" |
| 91 | + echo "$out" | tail -5; exit 1 ;; |
| 92 | +esac |
| 93 | +case "$out" in |
| 94 | + *"not found"*|*"was not found"*) ;; |
| 95 | + *) echo "FAIL: the diagnostic does not say the program was not found" |
| 96 | + echo "$out" | tail -5; exit 1 ;; |
| 97 | +esac |
| 98 | +echo " ok a dependency's bare-name runner is resolved, and its absence is named" |
| 99 | + |
| 100 | +# ⭐ AND THE FALLBACK IS REFUSED RATHER THAN TAKEN. Executing the artifact when |
| 101 | +# a runner was declared but its program is missing would run the program under |
| 102 | +# the wrong interpreter and report success — the failure the runner exists to |
| 103 | +# prevent. |
| 104 | +case "$out" in |
| 105 | + *"DEMO-TOOL ran"*) echo "FAIL: the artifact was executed anyway"; exit 1 ;; |
| 106 | +esac |
| 107 | +echo " ok a declared-but-unresolvable runner is an error, not a fallback" |
| 108 | + |
| 109 | +echo "PASS: a dependency-declared tool is reachable by bare name" |
0 commit comments