|
| 1 | +#!/usr/bin/env bash |
| 2 | +# requires: gcc fresh-sandbox |
| 3 | +# 990 -- a lock entry's key and hash do not depend on which members a command |
| 4 | +# plans (#868). |
| 5 | +# |
| 6 | +# Two members take one workspace dependency under two spellings: `a` writes |
| 7 | +# `widget2.workspace = true`, `c` writes `[dependencies.mcpplibs] |
| 8 | +# widget2.workspace = true`. The key was the spelling of a selected member, so |
| 9 | +# `-p a` wrote `[package."widget2"]` and `-p c` `[package."mcpplibs.widget2"]`, |
| 10 | +# each with its own hash (the hash is taken over the key), and the lock changed |
| 11 | +# between commands with no change to a manifest. |
| 12 | +# |
| 13 | +# Criteria: `--workspace`, `-p a` and `-p c` write the same key and hash; it is |
| 14 | +# the workspace's own spelling (`[workspace.dependencies] widget2`), which |
| 15 | +# precedes every member's. |
| 16 | +set -e |
| 17 | + |
| 18 | +TMP=$(mktemp -d) |
| 19 | +trap "rm -rf $TMP" EXIT |
| 20 | + |
| 21 | +export MCPP_HOME="$TMP/mcpp-home" |
| 22 | +source "$(dirname "$0")/_inherit_toolchain.sh" |
| 23 | + |
| 24 | +mkdir -p "$TMP/ws" |
| 25 | +cd "$TMP/ws" |
| 26 | + |
| 27 | +# A package of the default namespace, from a project-local index, with its |
| 28 | +# payload already in place: nothing is fetched. |
| 29 | +mkdir -p local-index/pkgs/w .mcpp/.xlings/data/xpkgs/mcpplibs.widget2/1.0.0/src |
| 30 | +cat > local-index/pkgs/w/widget2.lua <<'EOF' |
| 31 | +package = { |
| 32 | + spec = "1", |
| 33 | + namespace = "mcpplibs", |
| 34 | + name = "widget2", |
| 35 | + description = "a package of the default namespace from a local index", |
| 36 | + licenses = {"MIT"}, |
| 37 | + type = "package", |
| 38 | + xpm = { |
| 39 | + linux = { ["1.0.0"] = { url = "https://example.invalid/w.tar.gz" } }, |
| 40 | + macosx = { ["1.0.0"] = { url = "https://example.invalid/w.tar.gz" } }, |
| 41 | + windows = { ["1.0.0"] = { url = "https://example.invalid/w.zip" } }, |
| 42 | + }, |
| 43 | + mcpp = { |
| 44 | + language = "c++23", |
| 45 | + import_std = false, |
| 46 | + sources = { "src/widget2.cppm" }, |
| 47 | + targets = { ["widget2"] = { kind = "lib" } }, |
| 48 | + deps = {}, |
| 49 | + }, |
| 50 | +} |
| 51 | +EOF |
| 52 | +printf 'export module widget2;\nexport int widget2_value() { return 35; }\n' \ |
| 53 | + > .mcpp/.xlings/data/xpkgs/mcpplibs.widget2/1.0.0/src/widget2.cppm |
| 54 | + |
| 55 | +cat > mcpp.toml <<'EOF' |
| 56 | +[workspace] |
| 57 | +members = ["a", "c"] |
| 58 | +
|
| 59 | +[workspace.indices] |
| 60 | +mcpplibs = { path = "local-index" } |
| 61 | +
|
| 62 | +[workspace.dependencies] |
| 63 | +widget2 = "1.0.0" |
| 64 | +EOF |
| 65 | + |
| 66 | +mkdir -p a/src c/src |
| 67 | +cat > a/mcpp.toml <<'EOF' |
| 68 | +[package] |
| 69 | +name = "a" |
| 70 | +version = "0.1.0" |
| 71 | +
|
| 72 | +[dependencies] |
| 73 | +widget2.workspace = true |
| 74 | +
|
| 75 | +[targets.a] |
| 76 | +kind = "lib" |
| 77 | +EOF |
| 78 | +printf 'export module a;\nimport widget2;\nexport int a_value() { return widget2_value() + 7; }\n' > a/src/a.cppm |
| 79 | + |
| 80 | +cat > c/mcpp.toml <<'EOF' |
| 81 | +[package] |
| 82 | +name = "c" |
| 83 | +version = "0.1.0" |
| 84 | +
|
| 85 | +[dependencies.mcpplibs] |
| 86 | +widget2.workspace = true |
| 87 | +
|
| 88 | +[targets.c] |
| 89 | +kind = "bin" |
| 90 | +main = "src/main.cpp" |
| 91 | +EOF |
| 92 | +printf 'import widget2;\nint main() { return widget2_value() == 35 ? 0 : 1; }\n' > c/src/main.cpp |
| 93 | + |
| 94 | +entry() { # the lock's widget2 entry: its header and its hash |
| 95 | + grep -E '^\[package\..*widget2"\]' mcpp.lock |
| 96 | + awk '/widget2"\]/{f=1} f && /^hash/{print; exit}' mcpp.lock |
| 97 | +} |
| 98 | + |
| 99 | +declare -A seen |
| 100 | +for sel in "--workspace" "-p a" "-p c"; do |
| 101 | + rm -f mcpp.lock |
| 102 | + # shellcheck disable=SC2086 |
| 103 | + "$MCPP" build $sel --configure-only > "build.log" 2>&1 || { |
| 104 | + cat build.log |
| 105 | + echo "FAIL: mcpp build $sel --configure-only" |
| 106 | + exit 1 |
| 107 | + } |
| 108 | + seen[$sel]="$(entry)" |
| 109 | +done |
| 110 | + |
| 111 | +for sel in "--workspace" "-p a" "-p c"; do |
| 112 | + [[ "${seen[$sel]}" == "${seen[--workspace]}" ]] || { |
| 113 | + for s in "--workspace" "-p a" "-p c"; do echo "$s: ${seen[$s]}"; done |
| 114 | + echo "FAIL: the lock entry of widget2 depends on the members a command plans" |
| 115 | + exit 1 |
| 116 | + } |
| 117 | +done |
| 118 | +grep -q '^\[package\."widget2"\]' <<<"${seen[--workspace]}" || { |
| 119 | + echo "${seen[--workspace]}" |
| 120 | + echo "FAIL: the key is not the workspace's own spelling (widget2)" |
| 121 | + exit 1 |
| 122 | +} |
| 123 | + |
| 124 | +echo "OK" |
0 commit comments