Files
Build-System/tests/CliContracts.cmake
T
faumaray 3b5d28d7b0
VoidBuildSystem CI / 1 · Requirements (push) Successful in 5s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m50s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 3m29s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m7s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m53s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m22s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m22s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m57s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m0s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 19s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 18s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 7m8s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 7m24s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
feat(profiles): per-dependency overrides, toolchain pin and profile CLI (G3)
- Dependency::profile(name, DependencyProfileOptions) records per-profile
  compile/link options, defines, LTO and sanitizers. The native provider
  applies the matching override to the dependency's own ProfileContext and
  hashes the overrides into the provider input hash, so changing them
  invalidates cached dependency builds.
- vbs-toolchain.toml pins compiler, minimum version, C/C++ standards and
  sysroot (optional strict); it is loaded once and checked after every
  toolchain probe. Drift warns by default and fails with
  --locked-toolchain or strict = true; malformed pins fail with the TOML
  diagnostic.
- vbs profile list|show|diff lists declared profiles with parents, prints
  a resolved profile (flags, standards, LTO, sanitizers, sysroot) or the
  fields that differ between two.

Verified: dependency_profile_overrides_apply_to_native_builds (a define
from the override is required by the dependency source),
toolchain_pin_detects_and_enforces_drift and
profile_commands_list_show_and_diff pass; vbs_core_tests 8/8; CLI
contracts pass; clang-format clean.
2026-12-06 20:09:50 +03:00

281 lines
15 KiB
CMake

cmake_minimum_required(VERSION 4.0)
# Captured output must be plain text: the CLI colorizes help when colors are allowed.
set(ENV{NO_COLOR} "1")
function(check_process expected_code expected_out_regex expected_err_regex)
execute_process(COMMAND "${VBS}" ${ARGN}
RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err TIMEOUT 15)
if(NOT "${code}" STREQUAL "${expected_code}")
message(FATAL_ERROR "vbs ${ARGN}: expected exit ${expected_code}, got ${code}\nstdout=[${out}]\nstderr=[${err}]")
endif()
if(NOT "${expected_out_regex}" STREQUAL "" AND NOT out MATCHES "${expected_out_regex}")
message(FATAL_ERROR "vbs ${ARGN}: stdout did not match [${expected_out_regex}]\nactual=[${out}]")
endif()
if(NOT "${expected_err_regex}" STREQUAL "" AND NOT err MATCHES "${expected_err_regex}")
message(FATAL_ERROR "vbs ${ARGN}: stderr did not match [${expected_err_regex}]\nactual=[${err}]")
endif()
endfunction()
check_process(0 "Usage: vbs .*<command>.*Commands:" "" )
check_process(0 "Usage: vbs .*<command>.*Commands:" "" --help)
check_process(0 "Usage: vbs .*<command>.*Commands:" "" -h)
check_process(0 "^vbs ${VBS_VERSION}\n$" "" --version)
check_process(0 "^vbs ${VBS_VERSION}\n$" "" -V)
check_process(2 "" "unknown option: --invalid" --version --invalid)
check_process(2 "" "--version cannot be combined with subcommands" --version build)
check_process(2 "" "unknown subcommand: invalid" invalid)
check_process(0 "Usage: vbs build .*--native-foreign.*--profile.*\\(repeatable\\)" "" build --help)
check_process(0 "Usage: vbs test " "" test --help)
check_process(2 "" "invalid --test-timeout" test --test-timeout 0)
check_process(0 "Usage: vbs test .*--repeat" "" test --help)
check_process(0 "--shuffle" "" test --help)
check_process(0 "--stop-on-failure" "" test --help)
check_process(0 "Usage: vbs explain " "" explain --help)
check_process(0 "--format" "" explain --help)
check_process(2 "" "unsupported --format" explain --format xml)
check_process(0 "--trace" "" build --help)
check_process(0 "Usage: vbs completions " "" completions --help)
check_process(2 "" "unsupported --shell" completions --shell tcsh)
check_process(0 "Usage: vbs man " "" man --help)
check_process(0 "--from" "" migrate --help)
check_process(2 "" "invalid value 'bazel' for '--from'" migrate --from bazel)
check_process(2 "" "invalid value 'bogus' for '--template'" init --template bogus)
check_process(0 "--template" "" init --help)
check_process(0 "--export" "" presets --help)
check_process(0 "Usage: vbs attest " "" attest --help)
check_process(0 "Usage: vbs attest create " "" attest create --help)
check_process(0 "Usage: vbs attest verify " "" attest verify --help)
check_process(0 "Usage: vbs audit " "" audit --help)
check_process(2 "" "missing subcommand" attest)
check_process(2 "" "--artifact, --output and --signing-key are required" attest create)
check_process(2 "" "--attestation is required" attest verify)
check_process(2 "" "--advisories FILE is required" audit)
check_process(2 "" "invalid --severity-threshold" audit --advisories x --severity-threshold nope)
check_process(0 "Usage: vbs run " "" run --help)
check_process(0 "Usage: vbs metadata " "" metadata --help)
check_process(0 "Usage: vbs why " "" why --help)
check_process(0 "Usage: vbs add " "" add --help)
check_process(0 "Usage: vbs remove " "" remove --help)
check_process(0 "--frozen" "" build --help)
check_process(0 "--native-cache" "" build --help)
check_process(0 "--bep" "" build --help)
check_process(0 "--sandbox" "" build --help)
check_process(0 "--features" "" build --help)
check_process(0 "--no-default-features" "" build --help)
check_process(0 "--show-features" "" explain --help)
check_process(0 "--locked-toolchain" "" build --help)
check_process(0 "Usage: vbs profile " "" profile --help)
check_process(0 "Usage: vbs profile list " "" profile list --help)
check_process(0 "Usage: vbs profile show " "" profile show --help)
check_process(0 "Usage: vbs profile diff " "" profile diff --help)
check_process(2 "" "exactly two profile names" profile diff debug)
check_process(2 "" "invalid value 'bogus' for '--sandbox'" build --sandbox bogus)
check_process(0 "Usage: vbs new " "" new --help)
check_process(2 "" "unsupported --native-cache" build --native-cache bogus)
check_process(2 "" "invalid version range" add fmt@bad --no-lock)
check_process(0 "Usage: vbs fmt " "" fmt --help)
check_process(0 "Usage: vbs lint " "" lint --help)
check_process(0 "Usage: vbs tree " "" tree --help)
check_process(0 "Usage: vbs install-binary " "" install-binary --help)
check_process(2 "" "missing required argument" install-binary)
check_process(2 "" "--registry and a package name are required" install-binary foo)
check_process(2 "" "invalid --repeat mode" test --repeat bogus)
check_process(2 "" "invalid --repeat count" test --repeat until-pass:0)
check_process(2 "" "invalid --retry value" test --retry 99)
check_process(2 "" "invalid --shuffle-seed" test --shuffle --shuffle-seed abc)
check_process(0 "Usage: vbs init " "" init --help)
check_process(0 "Usage: vbs clean " "" clean --help)
check_process(0 "Usage: vbs doctor " "" doctor --help)
check_process(0 "host platform: (Linux|Windows)" "" doctor)
check_process(0 "Void::Sqlite: (enabled|disabled)" "" doctor)
check_process(0 "hermetic sandbox: (user namespaces available|unavailable)" "" doctor)
check_process(0 "Usage: vbs graph " "" graph --help)
check_process(2 "" "unsupported --format" graph --format xml)
check_process(2 "" "multi-profile build requires --editor-profile" build --profile debug --profile release)
check_process(2 "" "must be one of the requested profiles" build --profile debug --profile release --editor-profile custom)
check_process(0 "Usage: vbs compdb <command>.*Commands:.*use.*show.*export.*watch" "" compdb --help)
check_process(0 "Usage: vbs compdb use " "" compdb use --help)
check_process(2 "" "missing subcommand for 'vbs compdb'" compdb)
check_process(2 "" "unknown subcommand: bogus" compdb bogus)
check_process(0 "Usage: vbs deps <command>.*Commands:.*resolve.*update" "" deps --help)
check_process(0 "Usage: vbs deps resolve " "" deps resolve --help)
check_process(2 "" "missing subcommand for 'vbs deps'" deps)
check_process(2 "" "--request and --output are required" bridge)
check_process(0 "Usage: vbs install " "" install --help)
check_process(2 "" "--prefix is required" install)
check_process(2 "" "--prefix is required" uninstall)
check_process(2 "" "--input and --output-dir are required" gen-tests)
check_process(0 "Usage: vbs publish " "" publish --help)
check_process(0 "Usage: vbs publish-binary " "" publish-binary --help)
check_process(0 "Usage: vbs binaries <command>.*Commands:.*list.*fetch" "" binaries --help)
check_process(0 "Usage: vbs binaries list " "" binaries list --help)
check_process(0 "Usage: vbs binaries show " "" binaries show --help)
check_process(0 "Usage: vbs releases list " "" releases list --help)
check_process(0 "Usage: vbs releases yank " "" releases yank --help)
check_process(2 "" "--registry, --name, and --version are required" releases yank)
check_process(0 "Usage: vbs tokens list " "" tokens list --help)
check_process(0 "Usage: vbs lock show " "" lock show --help)
check_process(0 "Usage: vbs presets " "" presets --help)
check_process(0 "Usage: vbs migrate " "" migrate --help)
check_process(1 "" "vbs migrate" migrate --input "${CMAKE_CURRENT_BINARY_DIR}/no-such-CMakeLists.txt")
check_process(0 "Usage: vbs verify " "" verify --help)
check_process(0 "Usage: vbs compdb-entries " "" compdb-entries --help)
check_process(1 "" "no compilation database is published" compdb-entries --project
"${CMAKE_CURRENT_BINARY_DIR}/no-lock-project")
check_process(2 "" "--name, --version, --file, --signature, and --public-key are required" verify)
check_process(1 "" "public key is not trusted" verify --name demo --version 1.0.0
--file CMakeLists.txt
--signature 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--public-key 0000000000000000000000000000000000000000000000000000000000000000
--trusted-public-key aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
check_process(1 "" "" verify --name demo --version 1.0.0 --file CMakeLists.txt
--signature 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--public-key 0000000000000000000000000000000000000000000000000000000000000000)
check_process(0 "no vbs.lock in" "" lock show --project "${CMAKE_CURRENT_BINARY_DIR}/no-lock-project")
check_process(2 "" "vbs tokens: --registry is required" tokens list)
check_process(0 "Usage: vbs tokens revoke .*--token-id" "" tokens revoke --help)
check_process(2 "" "--registry and --name are required" releases list)
check_process(0 "Usage: vbs releases show " "" releases show --help)
check_process(2 "" "--registry, --name, and --version are required" releases show)
check_process(0 "Usage: vbs binaries fetch " "" binaries fetch --help)
check_process(2 "" "--registry, --name, and --version are required" binaries list)
check_process(2 "" "--variant and --output are required" binaries fetch --registry http://127.0.0.1:1 --name p --version 1.0.0)
check_process(2 "" "--registry, --name, --version, --variant, and --file are required" publish-binary)
check_process(2 "" "--registry, --name, and --version are required" publish)
check_process(0 "Usage: vbs daemon <command>.*Commands:.*run.*status.*stop.*recover.*gc.*describe" "" daemon --help)
check_process(0 "Usage: vbs daemon run " "" daemon run --help)
check_process(0 "Usage: vbs daemon describe .*--profile" "" daemon describe --help)
check_process(0 "Usage: vbs daemon build .*--profile.*--target.*--jobs" "" daemon build --help)
check_process(0 "Usage: vbs daemon ide query .*--profile" "" daemon ide query --help)
check_process(0 "Usage: vbs daemon compdb export .*--profile" "" daemon compdb export --help)
check_process(0 "Usage: vbs daemon compdb use .*--profile" "" daemon compdb use --help)
check_process(0 "Usage: vbs daemon compdb entries .*--file.*--limit" "" daemon compdb entries --help)
check_process(0 "Usage: vbs daemon ide generate " "" daemon ide generate --help)
check_process(0 "--force" "" daemon ide generate --help)
check_process(0 "--profile" "" daemon ide generate --help)
check_process(0 "--editor" "" daemon ide generate --help)
check_process(0 "Usage: vbs daemon ide poll " "" daemon ide poll --help)
check_process(0 "Usage: vbs daemon ide status " "" daemon ide status --help)
check_process(0 "Usage: vbs daemon graph .*--format" "" daemon graph --help)
check_process(0 "Usage: vbs daemon test .*--profile.*--target.*--jobs" "" daemon test --help)
check_process(0 "Usage: vbs daemon workspace members " "" daemon workspace members --help)
check_process(0 "Usage: vbs daemon ide configs " "" daemon ide configs --help)
check_process(0 "Usage: vbs daemon compdb generations .*--profile" "" daemon compdb generations --help)
check_process(0 "Usage: vbs daemon deps .*--profile" "" daemon deps --help)
check_process(0 "Usage: vbs daemon info " "" daemon info --help)
check_process(0 "Usage: vbs daemon clean " "" daemon clean --help)
check_process(0 "Usage: vbs daemon target info .*--name" "" daemon target info --help)
check_process(0 "Usage: vbs daemon target flags .*--name.*--file" "" daemon target flags --help)
check_process(0 "Usage: vbs daemon pack .*--output" "" daemon pack --help)
check_process(0 "Usage: vbs daemon actions .*--limit" "" daemon actions --help)
check_process(0 "Usage: vbs daemon install " "" daemon install --help)
check_process(0 "--prefix" "" daemon install --help)
check_process(0 "--component" "" daemon install --help)
check_process(0 "--no-cmake-export" "" daemon install --help)
check_process(0 "--no-native-export" "" daemon install --help)
check_process(0 "Usage: vbs daemon uninstall .*--prefix" "" daemon uninstall --help)
check_process(0 "Usage: vbs daemon gen-tests .*--input.*--output-dir" "" daemon gen-tests --help)
check_process(0 "Usage: vbs daemon init .*--dir" "" daemon init --help)
check_process(0 "Usage: vbs daemon ide wait .*--timeout-ms" "" daemon ide wait --help)
check_process(2 "" "missing subcommand for 'vbs daemon'" daemon)
if(NOT VBS_WINDOWS)
# Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over
# the Unix socket, then stop it (Unix-only; the Windows transport is Track C3).
set(daemon_contract_root "${CMAKE_CURRENT_BINARY_DIR}/daemon_contract")
file(REMOVE_RECURSE "${daemon_contract_root}")
file(MAKE_DIRECTORY "${daemon_contract_root}/project")
file(WRITE "${daemon_contract_root}/project/build.cpp" [=[#include <Void/Build.hpp>
void build(Void::Build::Project &project) {
auto app = project.executable("app");
app.sources({"main.cpp"});
}
]=])
file(WRITE "${daemon_contract_root}/project/main.cpp" "int main() { return 0; }\n")
set(daemon_contract_script [=[
set -u
vbs="$1"
project="$2"
build="$3"
out="$4"
log="$5"
"$vbs" daemon run -C "$project" -B "$build" --max-requests 2 >"$log" 2>&1 &
pid=$!
cleanup() {
kill "$pid" 2>/dev/null || true
}
trap cleanup EXIT
socket="$build/.vbs/vbs-daemon.sock"
i=0
while [ ! -S "$socket" ]; do
i=$((i + 1))
if [ "$i" -gt 400 ]; then
echo "daemon socket did not appear" >&2
exit 1
fi
sleep 0.05
done
"$vbs" daemon describe -C "$project" -B "$build" >"$out"
status=$?
"$vbs" daemon stop -C "$project" -B "$build" >/dev/null 2>&1 || true
i=0
while kill -0 "$pid" 2>/dev/null; do
i=$((i + 1))
if [ "$i" -gt 100 ]; then
break
fi
sleep 0.05
done
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
trap - EXIT
exit "$status"
]=])
execute_process(
COMMAND sh -c "${daemon_contract_script}" sh "${VBS}"
"${daemon_contract_root}/project" "${daemon_contract_root}/build"
"${daemon_contract_root}/describe.json" "${daemon_contract_root}/daemon.log"
RESULT_VARIABLE daemon_contract_code
TIMEOUT 180)
set(daemon_contract_log "")
if(EXISTS "${daemon_contract_root}/daemon.log")
file(READ "${daemon_contract_root}/daemon.log" daemon_contract_log)
endif()
if(NOT "${daemon_contract_code}" STREQUAL "0")
message(FATAL_ERROR "vbs daemon describe failed: exit ${daemon_contract_code}\ndaemon log=[${daemon_contract_log}]")
endif()
file(READ "${daemon_contract_root}/describe.json" daemon_describe_out)
if(NOT daemon_describe_out MATCHES "\"ok\":true" OR
NOT daemon_describe_out MATCHES "\"op\":\"describe\"" OR
NOT daemon_describe_out MATCHES "\"target_names\":\\[[^]]*\"app\"")
message(FATAL_ERROR "vbs daemon describe: unexpected response [${daemon_describe_out}]")
endif()
message(STATUS "daemon describe response: ${daemon_describe_out}")
endif()
check_process(0 "Usage: vbs ide <command>.*Commands:.*generate.*query" "" ide --help)
check_process(0 "Usage: vbs ide generate " "" ide generate --help)
check_process(0 "Usage: vbs ide query " "" ide query --help)
check_process(0 "Usage: vbs ide plugin .*--editor.*--output" "" ide plugin --help)
check_process(2 "" "--output is required" ide plugin)
check_process(2 "" "missing subcommand for 'vbs ide'" ide)
check_process(2 "" "unknown IDE kind" ide generate --editor invalid_ide)
if(VBS_REGISTRY)
execute_process(COMMAND "${VBS_REGISTRY}" --help
RESULT_VARIABLE reg_code OUTPUT_VARIABLE reg_out ERROR_VARIABLE reg_err TIMEOUT 15)
if(NOT "${reg_code}" STREQUAL "0" OR NOT reg_out MATCHES "Usage: vbs-registry")
message(FATAL_ERROR "vbs-registry --help failed: code=${reg_code}\nstdout=[${reg_out}]\nstderr=[${reg_err}]")
endif()
endif()
message(STATUS "CLI and auto-generated Argparse help contracts verified (including daemon describe round-trip)")