|
| 1 | +#!/usr/bin/env bash |
| 2 | +# The criteria for `deps-vcpkg`, `deps-cmake` and `rules-qt`, one function per |
| 3 | +# fixture, the same on every host. A CI step names the fixture: |
| 4 | +# |
| 5 | +# bash .github/scripts/check-deps-and-qt.sh vcpkg-consumer |
| 6 | +# |
| 7 | +# Each function fails with the reason it failed. Host differences are the |
| 8 | +# host's: a DLL is looked for on Windows, where a triplet builds fmt as one, and |
| 9 | +# nowhere else. |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +: "${MCPP:?MCPP names the mcpp under test}" |
| 13 | +ROOT=$(cd "$(dirname "$0")/../.." && pwd) |
| 14 | + |
| 15 | +fail() { echo "FAIL: $*"; exit 1; } |
| 16 | + |
| 17 | +is_windows() { case "$(uname -s)" in MINGW*|MSYS*|CYGWIN*) return 0 ;; *) return 1 ;; esac; } |
| 18 | +is_macos() { [ "$(uname -s)" = Darwin ]; } |
| 19 | + |
| 20 | +# The stamp an installation action leaves: the file mcpp writes when a `prepare` |
| 21 | +# action's command succeeds. Its modification time is the criterion for "the |
| 22 | +# installation did not run again". |
| 23 | +stamp_of() { find target -path "*$1*" -name '*.stamp' | head -1; } |
| 24 | + |
| 25 | +# The program as the build left it, started without `mcpp run`: on Windows the |
| 26 | +# engine has placed the DLLs it imports beside it (SPEC-007 R4.3), so it starts |
| 27 | +# from the build directory as it does from the packed tree. |
| 28 | +run_directly() { |
| 29 | + local exe; exe=$(find target -path '*/bin/*' -name "$1.exe" | head -1) |
| 30 | + [ -n "$exe" ] || fail "no $1.exe under target/" |
| 31 | + "$exe" |
| 32 | +} |
| 33 | + |
| 34 | +# A second build with nothing changed must not run the installation again. |
| 35 | +assert_not_rerun() { |
| 36 | + local stamp="$1" |
| 37 | + [ -n "$stamp" ] && [ -f "$stamp" ] || fail "no installation stamp under target/" |
| 38 | + mkdir -p target/ci |
| 39 | + touch -r "$stamp" target/ci/before-second-build |
| 40 | + sleep 1 |
| 41 | + # `--profile dev` names the default profile and declines mcpp's fast path, |
| 42 | + # so the second build is planned on every host, as it is on Windows and |
| 43 | + # macOS without the flag, and a host tool whose key moved is rebuilt. |
| 44 | + "$MCPP" build --profile dev > target/ci/second-build.log 2>&1 || |
| 45 | + { cat target/ci/second-build.log; fail "the second build failed"; } |
| 46 | + [ -z "$(find "$stamp" -newer target/ci/before-second-build)" ] || |
| 47 | + fail "the second build re-ran the installation ($stamp is newer)" |
| 48 | + echo "ok: a second build with nothing changed did not re-run the installation" |
| 49 | +} |
| 50 | + |
| 51 | +vcpkg_consumer() { |
| 52 | + cd "$ROOT/tests/vcpkg-consumer" |
| 53 | + rm -rf target vcpkg_installed |
| 54 | + # PLANNING NEVER INSTALLS, AND STILL STATES THE PATHS. An editor asks for |
| 55 | + # the build database on machines that never built; the build program must |
| 56 | + # succeed there and name the include directory the build will fill. |
| 57 | + mkdir -p target/ci |
| 58 | + "$MCPP" emit build-database --format json > target/ci/db.json 2> target/ci/emit.log || |
| 59 | + { cat target/ci/emit.log; fail "emit build-database failed before any installation"; } |
| 60 | + grep -q 'vcpkg_installed' target/ci/db.json || fail "the database names no vcpkg_installed include directory" |
| 61 | + [ ! -d target/vcpkg_installed ] || fail "emit build-database installed something" |
| 62 | + echo "ok: emit succeeded before the installation and named its include directory" |
| 63 | + |
| 64 | + "$MCPP" build 2>&1 | tee target/ci/build.log |
| 65 | + "$MCPP" run | tee target/ci/run.log |
| 66 | + grep -qE '^vcpkg-consumer: fmt [0-9]+ says 42$' target/ci/run.log || fail "the program did not print through fmt" |
| 67 | + assert_not_rerun "$(stamp_of deps-vcpkg)" |
| 68 | + |
| 69 | + if is_windows; then |
| 70 | + # The pack collects it from the runtime search directory. |
| 71 | + ls target/vcpkg_installed/x64-windows/bin/fmt.dll > /dev/null || fail "x64-windows built no fmt.dll" |
| 72 | + run_directly vcpkg-consumer | tee target/ci/direct.log |
| 73 | + grep -qE '^vcpkg-consumer: fmt [0-9]+ says 42$' target/ci/direct.log || |
| 74 | + fail "started from the build directory, the program did not find fmt.dll" |
| 75 | + "$MCPP" pack --format dir | tee target/ci/pack.log |
| 76 | + find target/dist -iname 'fmt.dll' | grep -q . || fail "the packed tree carries no fmt.dll" |
| 77 | + echo "ok: the packed tree carries fmt.dll" |
| 78 | + fi |
| 79 | +} |
| 80 | + |
| 81 | +vcpkg_workspace() { |
| 82 | + cd "$ROOT/tests/vcpkg-workspace" |
| 83 | + rm -rf target app-a/target app-b/target vcpkg_installed |
| 84 | + mkdir -p target/ci |
| 85 | + "$MCPP" build 2>&1 | tee target/ci/build.log |
| 86 | + "$MCPP" run -p app-a | tee target/ci/run-a.log |
| 87 | + "$MCPP" run -p app-b | tee target/ci/run-b.log |
| 88 | + grep -qE '^app-a: fmt [0-9]+$' target/ci/run-a.log || fail "app-a did not run" |
| 89 | + grep -qE '^app-b: fmt [0-9]+$' target/ci/run-b.log || fail "app-b did not run" |
| 90 | + # Each member builds into its own target/ and declares its own installation. |
| 91 | + [ "$(find . -path '*/target/*' -path '*deps-vcpkg*' -name '*.stamp' | wc -l)" -ge 2 ] || |
| 92 | + fail "each member did not declare its own installation" |
| 93 | + echo "ok: two members that share no dependency both installed and linked one prefix" |
| 94 | +} |
| 95 | + |
| 96 | +cmake_consumer() { |
| 97 | + cd "$ROOT/tests/cmake-consumer" |
| 98 | + rm -rf target |
| 99 | + mkdir -p target/ci |
| 100 | + "$MCPP" build 2>&1 | tee target/ci/build.log |
| 101 | + "$MCPP" run | tee target/ci/run.log |
| 102 | + grep -q '^cmake-consumer: greet says 42$' target/ci/run.log || fail "the program did not call the subproject's library" |
| 103 | + assert_not_rerun "$(stamp_of deps-cmake)" |
| 104 | + # The builds after an edit are planned as well. The subproject lies inside |
| 105 | + # this repository, the tree mcpp stamps for the plugins' host tool |
| 106 | + # (mcpp#705), so an edit also rebuilds `mcpp-deps`; the build that is |
| 107 | + # expected to re-run the installation absorbs that rebuild. |
| 108 | + touch greet/greet.c |
| 109 | + "$MCPP" build --profile dev > target/ci/third-build.log 2>&1 || { cat target/ci/third-build.log; fail "the rebuild failed"; } |
| 110 | + # The installed library is the product of the rebuild, whatever the engine |
| 111 | + # does with the action's stamp. |
| 112 | + [ -n "$(find target -path '*deps-cmake*/install/*' -name '*greet*' -newer target/ci/before-second-build)" ] || |
| 113 | + fail "an edited subproject source did not rebuild the subproject" |
| 114 | + echo "ok: an edited subproject source rebuilt the subproject" |
| 115 | + # And not again: the engine moves the stamp past the input that changed |
| 116 | + # (mcpp's SPEC-007 R3.5). |
| 117 | + assert_not_rerun "$(stamp_of deps-cmake)" |
| 118 | + |
| 119 | + # A file ADDED to the subproject is an input too: the build program watches |
| 120 | + # the tree, so the next plan names it and the installation runs again. |
| 121 | + trap 'rm -f "$ROOT/tests/cmake-consumer/greet/added.txt"' RETURN |
| 122 | + touch -r "$(stamp_of deps-cmake)" target/ci/before-added-file |
| 123 | + sleep 1 |
| 124 | + echo added > greet/added.txt |
| 125 | + "$MCPP" build --profile dev > target/ci/added-build.log 2>&1 || { cat target/ci/added-build.log; fail "the build after adding a file failed"; } |
| 126 | + [ -n "$(find "$(stamp_of deps-cmake)" -newer target/ci/before-added-file)" ] || |
| 127 | + fail "a file added to the subproject did not re-run its installation" |
| 128 | + echo "ok: a file added to the subproject re-ran its installation" |
| 129 | +} |
| 130 | + |
| 131 | +qt_consumer() { |
| 132 | + cd "$ROOT/tests/qt-consumer" |
| 133 | + rm -rf target |
| 134 | + mkdir -p target/ci |
| 135 | + "$MCPP" build 2>&1 | tee target/ci/build.log |
| 136 | + "$MCPP" run | tee target/ci/run.log |
| 137 | + grep -qE "^qt-consumer: signal 42, resource 'greetings from rcc', translation 'hallo', Qt 6\." target/ci/run.log || |
| 138 | + fail "moc, rcc or lrelease did not reach the program" |
| 139 | + find target -name 'qt_consumer_de.qm' | grep -q . || fail "no .qm was produced" |
| 140 | + echo "ok: moc (header and inline), rcc and lrelease reached the program" |
| 141 | +} |
| 142 | + |
| 143 | +qt_widgets_consumer() { |
| 144 | + cd "$ROOT/tests/qt-widgets-consumer" |
| 145 | + rm -rf target |
| 146 | + mkdir -p target/ci |
| 147 | + "$MCPP" build 2>&1 | tee target/ci/build.log |
| 148 | + QT_QPA_PLATFORM=offscreen "$MCPP" run | tee target/ci/run.log |
| 149 | + grep -q "^qt-widgets-consumer: platform offscreen, label 'made by uic'$" target/ci/run.log || |
| 150 | + fail "the platform plugin or the uic form did not reach the program" |
| 151 | + if is_macos; then |
| 152 | + find target -path '*/bin/platforms/libqoffscreen.dylib' | grep -q . || |
| 153 | + fail "no platforms/libqoffscreen.dylib was deployed beside the program" |
| 154 | + fi |
| 155 | + if is_windows; then |
| 156 | + QT_QPA_PLATFORM=offscreen run_directly qt-widgets-consumer | tee target/ci/direct.log |
| 157 | + grep -q "^qt-widgets-consumer: platform offscreen" target/ci/direct.log || |
| 158 | + fail "started from the build directory, the program did not find the Qt DLLs" |
| 159 | + "$MCPP" pack --format dir | tee target/ci/pack.log |
| 160 | + find target/dist -iname 'Qt6Widgets.dll' | grep -q . || fail "the packed tree carries no Qt6Widgets.dll" |
| 161 | + find target/dist -ipath '*platforms/qoffscreen.dll' | grep -q . || |
| 162 | + fail "the packed tree carries no platforms/qoffscreen.dll" |
| 163 | + echo "ok: the packed tree carries the Qt modules and the platform plugins" |
| 164 | + fi |
| 165 | +} |
| 166 | + |
| 167 | +case "${1:-}" in |
| 168 | + vcpkg-consumer) vcpkg_consumer ;; |
| 169 | + vcpkg-workspace) vcpkg_workspace ;; |
| 170 | + cmake-consumer) cmake_consumer ;; |
| 171 | + qt-consumer) qt_consumer ;; |
| 172 | + qt-widgets-consumer) qt_widgets_consumer ;; |
| 173 | + *) echo "usage: $0 vcpkg-consumer|vcpkg-workspace|cmake-consumer|qt-consumer|qt-widgets-consumer"; exit 2 ;; |
| 174 | +esac |
0 commit comments