|
| 1 | +#!/usr/bin/env bash |
| 2 | +# requires: gcc fresh-sandbox |
| 3 | +# 192_install_path_namespace.sh — a package must never be satisfied from |
| 4 | +# ANOTHER namespace's install directory. |
| 5 | +# |
| 6 | +# `Fetcher::install_path(ns, shortName, version)` answers "where is THIS |
| 7 | +# package installed". Its last-resort legacy scan matched any directory ending |
| 8 | +# in `-x-<shortName>`, whatever namespace that directory belonged to, so a |
| 9 | +# lookup for `acme:widget@1.5.0` returned `compat-x-widget/1.5.0`. The caller |
| 10 | +# then skips the install ("already present") and reads the other package's |
| 11 | +# tree. |
| 12 | +# |
| 13 | +# WHY IT WAS UNREACHABLE UNTIL NOW |
| 14 | +# |
| 15 | +# install_path also matches on version, so two packages sharing a short name |
| 16 | +# collided only if they also shared a version — and the ecosystem's module |
| 17 | +# layers carried packaging counters (`imgui@0.0.6`) while the compat packages |
| 18 | +# carried upstream versions (`compat.imgui@1.92.8`). Aligning the module layers |
| 19 | +# to upstream (mcpp-index#163) makes them coincide, which is how this surfaced. |
| 20 | +# |
| 21 | +# WHY THE SILENT SHAPE IS THE ONE THAT MATTERS |
| 22 | +# |
| 23 | +# Discovered against a Form B neighbour, so the wrong verdir had no mcpp.toml |
| 24 | +# and the build stopped — with a diagnostic naming the wrong cause. Between two |
| 25 | +# packages whose sources live in the verdir, there is no error at all: the |
| 26 | +# build compiles the wrong package's source. That is what this test pins. |
| 27 | +set -e |
| 28 | + |
| 29 | +TMP=$(mktemp -d) |
| 30 | +trap "rm -rf $TMP" EXIT |
| 31 | + |
| 32 | +export MCPP_HOME="$TMP/mcpp-home" |
| 33 | +source "$(dirname "$0")/_inherit_toolchain.sh" |
| 34 | + |
| 35 | +mkdir -p "$TMP/proj" |
| 36 | +cd "$TMP/proj" |
| 37 | + |
| 38 | +# ── Two packages, same short name, same version, different namespaces ───── |
| 39 | +mkdir -p local-index/pkgs/a |
| 40 | +cat > local-index/pkgs/a/acme.widget.lua <<'EOF' |
| 41 | +package = { |
| 42 | + spec = "1", |
| 43 | + namespace = "acme", |
| 44 | + name = "widget", |
| 45 | + description = "acme's widget", |
| 46 | + licenses = {"MIT"}, |
| 47 | + type = "package", |
| 48 | + xpm = { |
| 49 | + linux = { ["1.5.0"] = { url = "https://example.invalid/w.tar.gz", sha256 = "0000000000000000000000000000000000000000000000000000000000000000" } }, |
| 50 | + macosx = { ["1.5.0"] = { url = "https://example.invalid/w.tar.gz", sha256 = "0000000000000000000000000000000000000000000000000000000000000000" } }, |
| 51 | + windows = { ["1.5.0"] = { url = "https://example.invalid/w.zip", sha256 = "0000000000000000000000000000000000000000000000000000000000000000" } }, |
| 52 | + }, |
| 53 | + mcpp = { |
| 54 | + language = "c++23", |
| 55 | + import_std = false, |
| 56 | + sources = { "src/widget.cppm" }, |
| 57 | + targets = { ["widget"] = { kind = "lib" } }, |
| 58 | + deps = {}, |
| 59 | + }, |
| 60 | +} |
| 61 | +EOF |
| 62 | + |
| 63 | +# ── Only the FOREIGN namespace's payload is on disk ─────────────────────── |
| 64 | +# `compat:widget@1.5.0` is installed; `acme:widget@1.5.0` is not. Nothing may |
| 65 | +# hand acme's lookup this directory. |
| 66 | +# |
| 67 | +# It goes in the GLOBAL store ($MCPP_HOME/registry/data/xpkgs), which is what |
| 68 | +# `Fetcher::install_path` scans — the project's own .mcpp/.xlings tree is a |
| 69 | +# different root reached by `install_path_from_project_data`. Seeding the wrong |
| 70 | +# one makes this test pass on a broken binary, which is exactly what the first |
| 71 | +# draft did. |
| 72 | +mkdir -p "$MCPP_HOME/registry/data/xpkgs/compat-x-widget/1.5.0/src" |
| 73 | +cat > "$MCPP_HOME/registry/data/xpkgs/compat-x-widget/1.5.0/src/widget.cppm" <<'EOF' |
| 74 | +export module widget; |
| 75 | +// If this ever reaches a build that asked for acme:widget, the wrong package |
| 76 | +// was compiled. The value is the tell. |
| 77 | +export int widget_value() { return 1; } |
| 78 | +EOF |
| 79 | + |
| 80 | +mkdir -p src |
| 81 | +cat > src/main.cpp <<'EOF' |
| 82 | +import widget; |
| 83 | +int main() { return widget_value() == 2 ? 0 : 1; } |
| 84 | +EOF |
| 85 | + |
| 86 | +cat > mcpp.toml <<'EOF' |
| 87 | +[package] |
| 88 | +name = "consumer" |
| 89 | +version = "0.1.0" |
| 90 | +
|
| 91 | +[dependencies.acme] |
| 92 | +widget = "1.5.0" |
| 93 | +
|
| 94 | +[indices] |
| 95 | +acme = { path = "local-index" } |
| 96 | +EOF |
| 97 | + |
| 98 | +# The build must NOT succeed: acme:widget is not installed and its url is |
| 99 | +# unreachable by design. What it must never do is satisfy the dependency from |
| 100 | +# compat's directory. |
| 101 | +if "$MCPP" build > b.log 2>&1; then |
| 102 | + echo "--- build log ---"; cat b.log |
| 103 | + echo "FAIL: build succeeded, so acme:widget was satisfied from somewhere —" |
| 104 | + echo " the only widget payload on disk belongs to compat." |
| 105 | + exit 1 |
| 106 | +fi |
| 107 | + |
| 108 | +# Distinguish "correctly refused" from "compiled the wrong package and then |
| 109 | +# failed for an unrelated reason": compat's source must never be compiled. |
| 110 | +if grep -qE "compat-x-widget/1\.5\.0/src/widget\.cppm" b.log; then |
| 111 | + grep -nE "compat-x-widget" b.log | head -5 |
| 112 | + echo "FAIL: the build reached compat's source while resolving acme:widget" |
| 113 | + exit 1 |
| 114 | +fi |
| 115 | +echo " ok: acme:widget was not satisfied from compat-x-widget" |
| 116 | + |
| 117 | +# And the diagnostic has to name the directory it looked in — `<verdir>` as a |
| 118 | +# literal placeholder cannot distinguish a missing mcpp field from a wrong |
| 119 | +# verdir, which is what made this take a while to find. |
| 120 | +if grep -q "<verdir>" b.log; then |
| 121 | + echo "FAIL: diagnostic still prints the literal placeholder '<verdir>'" |
| 122 | + exit 1 |
| 123 | +fi |
| 124 | +echo " ok: diagnostics name a real path" |
| 125 | + |
| 126 | +echo "OK" |
0 commit comments