diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b61e62..efb3913 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,9 @@ jobs: - name: Run nested installation round-trip tests run: cmake -P tests/install/test_nested_install.cmake + - name: Run generated packaging checks + run: cmake -P tests/install/test_package_ci.cmake + - name: Run target type tests run: cmake -P tests/setup/test_target_type.cmake @@ -53,6 +56,9 @@ jobs: - name: Run nested static and shared installation round trips run: cmake -P tests/install/test_nested_install.cmake + - name: Run generated packaging checks + run: cmake -P tests/install/test_package_ci.cmake + clangd: name: clangd (${{ matrix.os }}) strategy: diff --git a/.scout/memory/index.md b/.scout/memory/index.md index c289aeb..a28079d 100644 --- a/.scout/memory/index.md +++ b/.scout/memory/index.md @@ -7,6 +7,7 @@ - [[knowledge/deferred-install-dependency-validation-and-config-generation.md|Deferred Install Dependency Validation and Config Generation]] (pattern, 0.75) `deferred-install` `install-validation` `untracked-dependencies` `cmake-language-defer` `find-dependency` - [[knowledge/dependency-tracking-lifecycle-and-provider-ordering.md|Dependency Tracking Lifecycle and Provider Ordering]] (observation, 0.75) `dependency-tracking` `dependency-provider` `cpp-library-enable-dependency-tracking` `cmake-project-top-level-includes` `set-dependency-provider` - [[knowledge/documentation-setup-and-theme-integration-with-build-docs.md|Documentation Setup and Theme Integration with BUILD_DOCS]] (pattern, 0.75) `build-docs` `doxygen` `doxygen-awesome-css` `documentation-generation` `docs-target` +- [[knowledge/generated-ci-package-artifact-check.md|Generated CI package artifact check]] (decision, 0.95) `ci` `packaging` `cmake` - [[knowledge/target-naming-and-alias-deduplication-convention.md|Target Naming and Alias Deduplication Convention]] (pattern, 0.75) `target-naming` `alias-deduplication` `package-name` `clean-name` `cmake-alias-convention` - [[knowledge/testing-and-example-executable-target-generation-gated-by-build-testing.md|Testing and Example Executable Target Generation Gated by BUILD_TESTING]] (pattern, 0.75) `build-testing` `doctest` `testing-setup` `negative-compilation-tests` `runtime-dll-copy` diff --git a/.scout/memory/knowledge/generated-ci-package-artifact-check.md b/.scout/memory/knowledge/generated-ci-package-artifact-check.md new file mode 100644 index 0000000..0d7d9d8 --- /dev/null +++ b/.scout/memory/knowledge/generated-ci-package-artifact-check.md @@ -0,0 +1,19 @@ +--- +title: "Generated CI package artifact check" +entity_type: decision +confidence: 0.95 +created: 2026-11-15T04:12:07Z +last_accessed: 2026-11-15T04:27:16Z +last_reinforced: 2026-11-15T04:27:16Z +access_count: 2 +sources: + - "templates/.github/workflows/ci.yml.in:76-79" + - "templates/test-package.cmake.in:8-35" + - "cmake/cpp-library-ci.cmake:41-54" +tags: ["ci", "packaging", "cmake"] +tier: knowledge +--- + +# Generated CI package artifact check + +Generated consumer CI deliberately verifies only the root package's installed Config, ConfigVersion and Targets artifacts; dependency installation and downstream find_package resolution remain the consumer's responsibility. The checker requires both file existence and membership in the current CMake install manifest, so stale absolute-destination artifacts cannot pass. Absolute library destinations do not require the otherwise unused install prefix to exist. The deferred generator captures CPP_LIBRARY_ROOT when scheduled because setup may run inside a function whose scope ends before deferred calls execute. Sources: templates/.github/workflows/ci.yml.in:76-79, templates/test-package.cmake.in:8-35, cmake/cpp-library-ci.cmake:41-54. diff --git a/cmake/cpp-library-ci.cmake b/cmake/cpp-library-ci.cmake index 348159a..833ed50 100644 --- a/cmake/cpp-library-ci.cmake +++ b/cmake/cpp-library-ci.cmake @@ -37,3 +37,18 @@ function(_cpp_library_setup_ci PACKAGE_NAME force_init) message(WARNING "CI template file not found: ${ci_template}") endif() endfunction() + +# Generates an installed-artifact check after the project's directories are configured. +function(_cpp_library_generate_package_test package root) + include(GNUInstallDirs) + set(PACKAGE_TEST_NAME "${package}") + set(PACKAGE_TEST_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}") + configure_file("${root}/templates/test-package.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cpp-library-test-package.cmake" @ONLY) +endfunction() + +# Schedules artifact-check generation without changing install rules. +function(_cpp_library_setup_package_test package) + cmake_language(EVAL CODE + "cmake_language(DEFER CALL _cpp_library_generate_package_test [[${package}]] [[${CPP_LIBRARY_ROOT}]])") +endfunction() diff --git a/cpp-library.cmake b/cpp-library.cmake index 1023504..17bfde9 100644 --- a/cpp-library.cmake +++ b/cpp-library.cmake @@ -301,6 +301,8 @@ function(cpp_library_setup) return() # Early return for lightweight consumer mode endif() + _cpp_library_setup_package_test("${PACKAGE_NAME}") + # Copy static template files (like .clang-format, .gitignore, CMakePresets.json, etc.) if(DEFINED CPP_LIBRARY_FORCE_INIT AND CPP_LIBRARY_FORCE_INIT) _cpp_library_copy_templates("${PACKAGE_NAME}" FORCE_INIT) diff --git a/docs/superpowers/plans/2026-11-14-ci-package-artifact-check.md b/docs/superpowers/plans/2026-11-14-ci-package-artifact-check.md new file mode 100644 index 0000000..94e7de5 --- /dev/null +++ b/docs/superpowers/plans/2026-11-14-ci-package-artifact-check.md @@ -0,0 +1,92 @@ +# CI Package Artifact Check Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Replace generated downstream-consumer testing with a check that the normal CI install produced the root package's config, version, and target-export files. + +**Architecture:** Keep the workflow's existing `cmake --install` step and pass its prefix to the generated check script. The script verifies the three local package artifacts under the configured CMake install directory without staging dependencies or configuring a consumer. + +**Tech Stack:** CMake script mode, CMake install rules, generated GitHub Actions workflow. + +**Spec:** `docs/superpowers/specs/2026-11-14-ci-package-artifact-check-design.md` + +## Global Constraints + +- Do not recursively install subdirectories, build a downstream consumer, or call `find_package()`. +- Do not require additional client configuration. +- Leave dependency installation and discovery to the client. +- Keep the existing workflow install step responsible for install-time errors. + +## Review Focus + +- A missing prefix must fail with a useful error rather than succeeding through a self-staged install. +- A missing config, version, or targets file must fail the artifact check. +- A prefix containing spaces must work when passed from the generated workflow. +- A non-default `CMAKE_INSTALL_LIBDIR` must be honored. +- An absolute `CMAKE_INSTALL_LIBDIR` must not let stale files bypass a missing-prefix failure. +- The check must not configure or build a downstream consumer. + +--- + +### Task 1: Check installed package artifacts in generated CI + +**Files:** +- Modify: `cmake/cpp-library-ci.cmake` +- Modify: `cpp-library.cmake` +- Modify: `templates/test-package.cmake.in` +- Modify: `templates/.github/workflows/ci.yml.in` +- Modify: `tests/install/test_package_ci.cmake` + +**Interfaces:** +- The generated script accepts `PACKAGE_TEST_PREFIX` as a `cmake -D` variable. +- The workflow passes the same `${{ runner.temp }}/install` prefix used by + `cmake --install`. +- The generated script checks + `//cmake//` for + `Config.cmake`, `ConfigVersion.cmake`, and + `Targets.cmake`. + +- [x] **Step 1: Rewrite the regression around the normal install prefix** + +Replace the dependency-staging, external-dependency, and shadow-install cases +in `tests/install/test_package_ci.cmake` with focused artifact-check cases. +Configure the `single` fixture with `CMAKE_INSTALL_LIBDIR=lib64` and use an +install prefix whose path contains spaces. Before installing, invoke the +generated check with `PACKAGE_TEST_PREFIX` and require it to fail. Install the +fixture by executing the generated workflow's install command and require the +check to pass. For each required artifact, copy the install tree to a separate +prefix, remove that artifact, and require the check to fail. Also configure a +second fixture with an absolute `CMAKE_INSTALL_LIBDIR`, create stale artifact +files there, and verify a nonexistent install prefix still fails. Do not +configure or build a consumer. + +- [x] **Step 2: Run the regression to confirm it exposes the old behavior** + +Run: `cmake -P tests/install/test_package_ci.cmake` + +Expected: FAIL because the current generated script ignores the supplied prefix +and stages its own package instead of rejecting the missing artifacts. + +- [x] **Step 3: Generate a check script that verifies only local artifacts** + +In `cmake/cpp-library-ci.cmake`, remove recursive install-list generation and +change the internal package-test helper and its `cpp-library.cmake` call site +to pass only the package name. Pass the configured `CMAKE_INSTALL_LIBDIR` to +`templates/test-package.cmake.in`. Replace the staging, consumer configure, +build, and CTest logic in that template with validation of `PACKAGE_TEST_PREFIX` +and explicit existence checks for the three required files. Report the missing +path in each failure. + +- [x] **Step 4: Pass the workflow's existing install prefix to the check** + +Update `templates/.github/workflows/ci.yml.in` so both install steps quote the +`${{ runner.temp }}/install` argument, and the artifact-check step passes that +same prefix as `PACKAGE_TEST_PREFIX`. + +- [x] **Step 5: Run the focused packaging regression** + +Run: `cmake -P tests/install/test_package_ci.cmake` + +Expected: PASS for artifact presence and FAIL cases, including the absent +pre-install prefix, each missing artifact, a path containing spaces, `lib64`, +and stale artifacts under an absolute library directory. diff --git a/docs/superpowers/specs/2026-11-14-ci-package-artifact-check-design.md b/docs/superpowers/specs/2026-11-14-ci-package-artifact-check-design.md new file mode 100644 index 0000000..7e86642 --- /dev/null +++ b/docs/superpowers/specs/2026-11-14-ci-package-artifact-check-design.md @@ -0,0 +1,36 @@ +# CI Package Artifact Check — Design + +## Goal + +Replace the generated downstream-consumer test with a check that the normal CI +install produced the root package's config, version, and exported-target files. +This keeps CI independent of how clients install dependencies; it does not +claim to validate downstream `find_package()` resolution. + +## Scope + +- Keep the generated workflow's normal `cmake --install` step. +- Pass its install prefix to the generated package-check script. +- Check for `Config.cmake`, + `ConfigVersion.cmake`, and + `Targets.cmake` under the package's configured CMake install + directory. +- Add focused regression coverage for present and missing artifacts. + +## Approaches + +- **Stage dependencies and configure a consumer.** Rejected because CI cannot + infer how arbitrary dependencies are installed or discovered without + client-specific inputs. +- **Rely on install success alone.** Simpler, but does not detect a successful + install that omitted the local package files. +- **Check local package artifacts.** Selected because it verifies the root + package's install output without requiring dependency configuration. + +## Constraints and non-goals + +The check must not recursively install subdirectories, build a downstream +consumer, call `find_package()`, or require additional client configuration. +Dependency installation and discovery remain the client's responsibility. +The existing install step remains responsible for reporting install-time +errors. diff --git a/templates/.github/workflows/ci.yml.in b/templates/.github/workflows/ci.yml.in index e76aba3..2a1f00c 100644 --- a/templates/.github/workflows/ci.yml.in +++ b/templates/.github/workflows/ci.yml.in @@ -61,7 +61,7 @@ jobs: run: | cmake --preset=default cmake --build --preset=default - cmake --install build/default --prefix ${{ runner.temp }}/install + cmake --install build/default --prefix "${{ runner.temp }}/install" env: CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} @@ -71,31 +71,12 @@ jobs: run: | cmake --preset=default cmake --build --preset=default - cmake --install build/default --prefix ${{ runner.temp }}/install + cmake --install build/default --prefix "${{ runner.temp }}/install" if: ${{ !matrix.cc }} - - name: Test find_package - shell: bash + - name: Check installed package artifacts run: | - # Create a minimal test to verify the installation works with find_package - mkdir -p ${{ runner.temp }}/test-find-package - cd ${{ runner.temp }}/test-find-package - - # Create test CMakeLists.txt - cat > CMakeLists.txt << EOF - cmake_minimum_required(VERSION 3.20) - project(test-find-package CXX) - - find_package(@PACKAGE_NAME@ REQUIRED) - - message(STATUS "Successfully found @PACKAGE_NAME@") - EOF - - # Convert paths to forward slashes for CMake (works on all platforms) - INSTALL_PREFIX=$(echo '${{ runner.temp }}/install' | sed 's|\\|/|g') - - # Test find_package with CMAKE_PREFIX_PATH - cmake -B build -S . -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}" + cmake "-DPACKAGE_TEST_PREFIX=${{ runner.temp }}/install" -P build/default/cpp-library-test-package.cmake clang-tidy: runs-on: ubuntu-latest diff --git a/templates/test-package.cmake.in b/templates/test-package.cmake.in new file mode 100644 index 0000000..24124f5 --- /dev/null +++ b/templates/test-package.cmake.in @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: BSL-1.0 +# Auto-generated by cpp-library. Run after installing the package. +cmake_minimum_required(VERSION 3.24) + +if(NOT DEFINED PACKAGE_TEST_PREFIX OR PACKAGE_TEST_PREFIX STREQUAL "") + message(FATAL_ERROR "PACKAGE_TEST_PREFIX must name the install prefix") +endif() +set(package_install_dir "@PACKAGE_TEST_INSTALL_LIBDIR@/cmake/@PACKAGE_TEST_NAME@") +if(IS_ABSOLUTE "${package_install_dir}") + set(package_dir "${package_install_dir}") +else() + if(NOT IS_DIRECTORY "${PACKAGE_TEST_PREFIX}") + message(FATAL_ERROR "Package install prefix does not exist: ${PACKAGE_TEST_PREFIX}") + endif() + set(package_dir "${PACKAGE_TEST_PREFIX}/${package_install_dir}") +endif() + +set(manifest "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +if(NOT EXISTS "${manifest}") + message(FATAL_ERROR "Package install manifest is missing: ${manifest}") +endif() +file(STRINGS "${manifest}" installed_files) + +foreach(artifact IN ITEMS + "@PACKAGE_TEST_NAME@Config.cmake" + "@PACKAGE_TEST_NAME@ConfigVersion.cmake" + "@PACKAGE_TEST_NAME@Targets.cmake") + set(artifact_path "${package_dir}/${artifact}") + if(NOT EXISTS "${artifact_path}") + message(FATAL_ERROR "Installed package artifact is missing: ${artifact_path}") + endif() + cmake_path(NORMAL_PATH artifact_path) + if(NOT artifact_path IN_LIST installed_files) + message(FATAL_ERROR "Package artifact was not installed: ${artifact_path}") + endif() +endforeach() + +message(STATUS "Installed @PACKAGE_TEST_NAME@ artifacts found in ${package_dir}") diff --git a/tests/install/fixtures/nested/CMakeLists.txt b/tests/install/fixtures/nested/CMakeLists.txt index ef901c0..de9b222 100644 --- a/tests/install/fixtures/nested/CMakeLists.txt +++ b/tests/install/fixtures/nested/CMakeLists.txt @@ -19,7 +19,11 @@ cpp_library_setup( NAMESPACE stlab HEADERS parent.hpp ${install_args}) -add_subdirectory(leaf) +if(EXCLUDE_LEAF_FROM_ALL) + add_subdirectory(leaf EXCLUDE_FROM_ALL) +else() + add_subdirectory(leaf) +endif() # Resolve the installed target downstream, even when leaf is not exported in this build. target_link_libraries(parent INTERFACE $ diff --git a/tests/install/fixtures/nested/leaf/CMakeLists.txt b/tests/install/fixtures/nested/leaf/CMakeLists.txt index c37dd13..7586bea 100644 --- a/tests/install/fixtures/nested/leaf/CMakeLists.txt +++ b/tests/install/fixtures/nested/leaf/CMakeLists.txt @@ -11,6 +11,11 @@ cpp_library_setup( HEADERS leaf.hpp SOURCES leaf.cpp ${install_args}) +if(PACKAGE_TEST_EXTRA) + add_subdirectory(extra EXCLUDE_FROM_ALL) + target_link_libraries(leaf PUBLIC stlab::extra) + cpp_library_map_dependency("stlab::extra" "stlab-extra 1.0.0") +endif() get_target_property(leaf_type leaf TYPE) set(LEAF_SHARED 0) if(leaf_type STREQUAL "SHARED_LIBRARY") diff --git a/tests/install/fixtures/nested/leaf/extra/CMakeLists.txt b/tests/install/fixtures/nested/leaf/extra/CMakeLists.txt new file mode 100644 index 0000000..b93986a --- /dev/null +++ b/tests/install/fixtures/nested/leaf/extra/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.24) +include("${TOOLKIT_SOURCE}/cpp-library.cmake") +project(extra LANGUAGES CXX) +set(CPP_LIBRARY_VERSION 1.0.0) +cpp_library_setup( + DESCRIPTION "Transitive packaging dependency fixture" + NAMESPACE stlab + HEADERS extra.hpp + INSTALL_OPTION STLAB_LEAF_INSTALL) diff --git a/tests/install/fixtures/nested/leaf/extra/include/stlab/extra.hpp b/tests/install/fixtures/nested/leaf/extra/include/stlab/extra.hpp new file mode 100644 index 0000000..ef98066 --- /dev/null +++ b/tests/install/fixtures/nested/leaf/extra/include/stlab/extra.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace stlab { +inline constexpr int extra_value = 0; +} diff --git a/tests/install/fixtures/single/CMakeLists.txt b/tests/install/fixtures/single/CMakeLists.txt new file mode 100644 index 0000000..ea7788d --- /dev/null +++ b/tests/install/fixtures/single/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.24) +include("${TOOLKIT_SOURCE}/cpp-library.cmake") +cpp_library_enable_dependency_tracking() +project(single LANGUAGES CXX) +set(CPP_LIBRARY_VERSION 1.0.0) +cpp_library_setup( + DESCRIPTION "Dependency-free packaging fixture" + NAMESPACE stlab + HEADERS single.hpp) +if(EXTERNAL_PACKAGE) + find_package(stlab-extra 1.0.0 CONFIG REQUIRED) + target_link_libraries(single INTERFACE stlab::extra) +endif() diff --git a/tests/install/fixtures/single/include/stlab/single.hpp b/tests/install/fixtures/single/include/stlab/single.hpp new file mode 100644 index 0000000..72f3a9b --- /dev/null +++ b/tests/install/fixtures/single/include/stlab/single.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace stlab { +inline constexpr int single_value = 42; +} diff --git a/tests/install/test_package_ci.cmake b/tests/install/test_package_ci.cmake new file mode 100644 index 0000000..16a0a66 --- /dev/null +++ b/tests/install/test_package_ci.cmake @@ -0,0 +1,189 @@ +# SPDX-License-Identifier: BSL-1.0 +# +# Run as: cmake -P tests/install/test_package_ci.cmake +cmake_minimum_required(VERSION 3.24) + +get_filename_component(toolkit_source "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) +string(RANDOM LENGTH 16 ALPHABET 0123456789abcdef test_id) +set(test_root "${toolkit_source}/build/package-ci-${test_id}") + +function(run_command) + execute_process(COMMAND ${ARGN} + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Command failed (${result}): ${ARGN}\n${out}\n${err}") + endif() +endfunction() + +function(expect_check_failure check prefix missing_file) + execute_process( + COMMAND "${CMAKE_COMMAND}" "-DPACKAGE_TEST_PREFIX=${prefix}" -P "${check}" + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + if(result EQUAL 0 OR NOT "${out}\n${err}" MATCHES "${missing_file}") + message(FATAL_ERROR + "Expected package check to report ${missing_file} as missing:\n${out}\n${err}") + endif() +endfunction() + +function(run_workflow_install workflow binary prefix) + file(READ "${workflow}" workflow_text) + string(REGEX MATCH "cmake --install build/default --prefix [^\n]*" + install_command "${workflow_text}") + if(NOT install_command) + message(FATAL_ERROR "Generated workflow has no install command: ${workflow}") + endif() + string(REPLACE "build/default" "\"${binary}\"" install_command "${install_command}") + string(REPLACE "\${{ runner.temp }}/install" "${prefix}" install_command "${install_command}") + + if(WIN32) + find_program(shell NAMES pwsh powershell REQUIRED) + execute_process(COMMAND "${shell}" -NoProfile -Command "${install_command}" + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + else() + execute_process(COMMAND /bin/sh -c "${install_command}" + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + endif() + if(NOT result EQUAL 0) + message(FATAL_ERROR "Generated workflow install failed (${result}):\n${install_command}\n${out}\n${err}") + endif() +endfunction() + +function(run_single) + set(root "${test_root}/single") + set(source "${root}/source") + set(binary "${root}/build") + set(prefix "${root}/install prefix") + file(MAKE_DIRECTORY "${source}") + file(COPY "${CMAKE_CURRENT_LIST_DIR}/fixtures/single/" DESTINATION "${source}") + run_command("${CMAKE_COMMAND}" -S "${source}" -B "${binary}" -G Ninja + "-DTOOLKIT_SOURCE=${toolkit_source}" -DCMAKE_BUILD_TYPE=Release + -DCMAKE_INSTALL_LIBDIR=lib64) + run_command("${CMAKE_COMMAND}" --build "${binary}") + + set(workflow "${source}/.github/workflows/ci.yml") + if(NOT EXISTS "${workflow}") + message(FATAL_ERROR "Missing generated CI workflow: ${workflow}") + endif() + set(check "${binary}/cpp-library-test-package.cmake") + if(NOT EXISTS "${check}") + message(FATAL_ERROR "Missing generated packaging check: ${check}") + endif() + + expect_check_failure("${check}" "${prefix}" "Package install prefix does not exist") + run_workflow_install("${workflow}" "${binary}" "${prefix}") + run_command("${CMAKE_COMMAND}" "-DPACKAGE_TEST_PREFIX=${prefix}" -P "${check}") + + set(package_dir "lib64/cmake/stlab-single") + foreach(artifact IN ITEMS + stlab-singleConfig.cmake + stlab-singleConfigVersion.cmake + stlab-singleTargets.cmake) + set(path "${prefix}/${package_dir}/${artifact}") + file(RENAME "${path}" "${path}.backup") + expect_check_failure("${check}" "${prefix}" "${artifact}") + file(RENAME "${path}.backup" "${path}") + endforeach() + + message(STATUS "PASS single: installed package artifacts are checked") +endfunction() + +function(run_absolute_libdir) + set(root "${test_root}/absolute libdir") + set(source "${root}/source") + set(binary "${root}/build") + set(prefix "${root}/missing prefix") + set(libdir "${root}/absolute install lib") + file(MAKE_DIRECTORY "${source}") + file(COPY "${CMAKE_CURRENT_LIST_DIR}/fixtures/single/" DESTINATION "${source}") + run_command("${CMAKE_COMMAND}" -S "${source}" -B "${binary}" -G Ninja + "-DTOOLKIT_SOURCE=${toolkit_source}" "-DCMAKE_INSTALL_LIBDIR=${libdir}") + + set(check "${binary}/cpp-library-test-package.cmake") + set(package_dir "${libdir}/cmake/stlab-single") + file(MAKE_DIRECTORY "${package_dir}") + foreach(artifact IN ITEMS + stlab-singleConfig.cmake + stlab-singleConfigVersion.cmake + stlab-singleTargets.cmake) + file(WRITE "${package_dir}/${artifact}" "stale artifact") + endforeach() + expect_check_failure("${check}" "${prefix}" "install_manifest.txt") +endfunction() + +function(run_function_scope) + set(root "${test_root}/function scope") + set(source "${root}/source") + set(binary "${root}/build") + file(MAKE_DIRECTORY "${source}") + file(COPY "${CMAKE_CURRENT_LIST_DIR}/fixtures/single/" DESTINATION "${source}") + file(WRITE "${source}/CMakeLists.txt" [=[ +cmake_minimum_required(VERSION 3.24) +project(single LANGUAGES CXX) +set(CPP_LIBRARY_VERSION 1.0.0) +function(setup_library) + include("${TOOLKIT_SOURCE}/cpp-library.cmake") + cpp_library_setup(DESCRIPTION "fixture" NAMESPACE stlab HEADERS single.hpp) +endfunction() +setup_library() +]=]) + run_command("${CMAKE_COMMAND}" -S "${source}" -B "${binary}" -G Ninja + "-DTOOLKIT_SOURCE=${toolkit_source}") + message(STATUS "PASS function scope: package check is generated") +endfunction() + +function(run_absolute_install stale) + set(root "${test_root}/absolute install ${stale}") + set(source "${root}/source") + set(binary "${root}/build") + set(prefix "${root}/prefix") + set(libdir "${root}/absolute lib") + set(includedir "${root}/absolute include") + file(MAKE_DIRECTORY "${source}") + file(COPY "${CMAKE_CURRENT_LIST_DIR}/fixtures/single/" DESTINATION "${source}") + set(args) + if(stale) + list(APPEND args -DSTLAB_INSTALL=OFF) + file(APPEND "${source}/CMakeLists.txt" [=[ +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/unrelated.txt" "unrelated") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unrelated.txt" DESTINATION ".") +]=]) + set(package_dir "${libdir}/cmake/stlab-single") + file(MAKE_DIRECTORY "${package_dir}") + foreach(artifact IN ITEMS stlab-singleConfig.cmake stlab-singleConfigVersion.cmake stlab-singleTargets.cmake) + file(WRITE "${package_dir}/${artifact}" "stale") + endforeach() + endif() + run_command("${CMAKE_COMMAND}" -S "${source}" -B "${binary}" -G Ninja + "-DTOOLKIT_SOURCE=${toolkit_source}" "-DCMAKE_INSTALL_LIBDIR=${libdir}" + "-DCMAKE_INSTALL_INCLUDEDIR=${includedir}" ${args}) + run_command("${CMAKE_COMMAND}" --install "${binary}" --prefix "${prefix}") + set(check "${binary}/cpp-library-test-package.cmake") + if(stale) + expect_check_failure("${check}" "${prefix}" "stlab-singleConfig.cmake") + message(STATUS "PASS absolute install: stale artifacts rejected") + else() + if(EXISTS "${prefix}") + message(FATAL_ERROR "Absolute installation unexpectedly created ${prefix}") + endif() + run_command("${CMAKE_COMMAND}" "-DPACKAGE_TEST_PREFIX=${prefix}" -P "${check}") + message(STATUS "PASS absolute install: installed artifacts accepted") + endif() +endfunction() + +if(CASE STREQUAL "scope") + run_function_scope() +elseif(CASE STREQUAL "stale") + run_absolute_install(TRUE) +elseif(CASE STREQUAL "absolute") + run_absolute_install(FALSE) +elseif(DEFINED CASE) + message(FATAL_ERROR "Unknown case: ${CASE}") +else() + run_single() + run_absolute_libdir() + run_function_scope() + run_absolute_install(TRUE) + run_absolute_install(FALSE) +endif() +file(REMOVE_RECURSE "${test_root}") +message(STATUS "Generated package artifact checks passed!")