Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .scout/memory/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
19 changes: 19 additions & 0 deletions .scout/memory/knowledge/generated-ci-package-artifact-check.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions cmake/cpp-library-ci.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions cpp-library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
92 changes: 92 additions & 0 deletions docs/superpowers/plans/2026-11-14-ci-package-artifact-check.md
Original file line number Diff line number Diff line change
@@ -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
`<prefix>/<CMAKE_INSTALL_LIBDIR>/cmake/<PACKAGE_NAME>/` for
`<PACKAGE_NAME>Config.cmake`, `<PACKAGE_NAME>ConfigVersion.cmake`, and
`<PACKAGE_NAME>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.
Original file line number Diff line number Diff line change
@@ -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 `<PACKAGE_NAME>Config.cmake`,
`<PACKAGE_NAME>ConfigVersion.cmake`, and
`<PACKAGE_NAME>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.
27 changes: 4 additions & 23 deletions templates/.github/workflows/ci.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Comment thread
sean-parent marked this conversation as resolved.
Resolved

clang-tidy:
runs-on: ubuntu-latest
Expand Down
38 changes: 38 additions & 0 deletions templates/test-package.cmake.in
Original file line number Diff line number Diff line change
@@ -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}")
Comment thread
sean-parent marked this conversation as resolved.
Resolved
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}")
6 changes: 5 additions & 1 deletion tests/install/fixtures/nested/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:stlab::leaf>
Expand Down
5 changes: 5 additions & 0 deletions tests/install/fixtures/nested/leaf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions tests/install/fixtures/nested/leaf/extra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace stlab {
inline constexpr int extra_value = 0;
}
13 changes: 13 additions & 0 deletions tests/install/fixtures/single/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions tests/install/fixtures/single/include/stlab/single.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace stlab {
inline constexpr int single_value = 42;
}
Loading
Loading