Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / Collectors

C and C++ build

The C or C++ build in the project directory: which build system and package manager it uses, the C++ standard and CMake version it requires, the packages it declares and which of them are pinned, and the packages it expects the machine to carry. CMakeLists.txt is a script, so what it declares conditionally is not seen and scanned says so.

Facts keycpp
Versionv1
Scriptcpp.py
Timeout30 seconds

Inputs

InputDescriptionDefaultEnvironment
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

A guardrail that declares an input of the same name passes it through, so the guardrail's configuration in buildnote.json is what decides these values.

A guardrail asks for these facts by name, and reads them back the same way:

json
{
  "collect": ["cpp"]
}
python
cpp = guardrail.facts("cpp")

Facts

The document cpp collects. A path carrying [] is an entry of the list before it, and one carrying [path] is a key of the object before it.

FactMeaning
directoryThe projectDir input, as the guardrail configured it.
existsWhether that directory is there. Nothing else is collected when it is not.
manifestPath of the primary manifest, relative to projectDir: CMakeLists.txt when there is one, otherwise the package manifest that was found.
sourcesEvery manifest that was read and understood, in the order they were read. One the reader could not handle is in unparsed instead.
scannedEvery manifest that is a program rather than a declaration and was read by pattern. CMakeLists.txt and conanfile.py are scripts, so a target or a dependency added inside an if() or a function is not seen.
buildSystemWhich build system the checkout uses: cmake, meson, bazel, make, or null when none of them is there and only a package manifest was found.
packageManagerWhich package manager declares the dependencies: vcpkg, conan, both, or null when neither is there and dependencies are vendored or found on the system.
declaredThe C++ standard the build asks for, or null when it asks for none and the compiler's default decides.
declared.versionStandard as written, such as 20.
declared.sourceManifest declaring it, relative to projectDir.
declared.pinnedWhether the build requires that standard rather than treating it as a preference. CXX_STANDARD_REQUIRED off means the compiler may fall back to an older one.
cmakeMinimumThe version cmake_minimum_required names, such as 3.25, or null when the reader saw none. Below 3.5 modern CMake refuses to configure at all.
baselineThe builtin-baseline commit vcpkg.json pins, which is what makes a vcpkg build reproducible, or null when it pins none.
projectsEvery project the reader saw: each project() call in a CMakeLists.txt, or the package the manifest declares.
projects[].pathDirectory of the project, relative to projectDir, . for the project directory itself.
projects[].manifestThe manifest declaring it, relative to projectDir.
projects[].nameName it declares, or null when the reader could not see one.
dependenciesWhat the manifests declare, split by whether the build asks for it itself.
dependencies.directEvery dependency the package manifests name, in manifest order. A library found with find_package and no manifest entry is not one of these, because nothing in the checkout says which version it expects.
dependencies.direct[].namePackage name, such as fmt.
dependencies.direct[].versionVersion exactly as written, such as 10.2.1, or null when the entry names none and the registry baseline decides.
dependencies.direct[].scopesdefault, or test for a vcpkg feature named test and build for a Conan build requirement.
dependencies.direct[].sourceManifest declaring it, relative to projectDir.
dependencies.direct[].pinnedWhether the entry names one exact version. A vcpkg version>= is a floor rather than a pin, and an entry with no version at all is decided by the baseline.
dependencies.transitiveAlways empty. What a resolver settles on is not read: lockfiles says whether one is committed.
findPackagesEvery package a CMakeLists.txt looks for with find_package, which is what the build expects the machine to already carry.
languagesEvery language a project() call enables, such as C and CXX, in the order they are named. Empty when no call names any, which is CMake enabling C and C++ both, and ["NONE"] when a call disables them. A checkout whose only language is C has no C++ standard to declare.
lockfilesEvery lock file committed, relative to projectDir, such as conan.lock.
unparsedEvery manifest the reader could not handle, so a guardrail can tell a build that declares nothing from one nobody could read.
unparsed[].pathPath of that manifest, relative to projectDir.
unparsed[].reasonWhat stopped the reader.

A collector that cannot finish prints what it had along with an incomplete key saying why, so the facts below the point it stopped are absent. A check that cares reads incomplete before the rest.

Example facts

The example facts collected by cpp collector:

json
{
  "directory": ".",
  "exists": true,
  "manifest": "CMakeLists.txt",
  "sources": [
    "CMakeLists.txt",
    "vcpkg.json"
  ],
  "scanned": [
    "CMakeLists.txt"
  ],
  "buildSystem": "cmake",
  "packageManager": "vcpkg",
  "declared": {
    "version": "20",
    "source": "CMakeLists.txt",
    "pinned": true
  },
  "cmakeMinimum": "3.25",
  "baseline": "6f3a1c2d9b8e4f7a0c5d2e1b3a4f5c6d7e8f9a0b",
  "projects": [
    {
      "path": ".",
      "manifest": "CMakeLists.txt",
      "name": "widget"
    }
  ],
  "dependencies": {
    "direct": [
      {
        "name": "fmt",
        "version": null,
        "scopes": [
          "default"
        ],
        "source": "vcpkg.json",
        "pinned": false
      },
      {
        "name": "spdlog",
        "version": "1.13.0",
        "scopes": [
          "default"
        ],
        "source": "vcpkg.json",
        "pinned": false
      },
      {
        "name": "catch2",
        "version": null,
        "scopes": [
          "test"
        ],
        "source": "vcpkg.json",
        "pinned": false
      }
    ],
    "transitive": []
  },
  "findPackages": [
    "Threads",
    "fmt"
  ],
  "languages": [
    "CXX"
  ],
  "lockfiles": [],
  "unparsed": []
}

Collected for

GuardrailCategoryInputs
cpp/cmake-minimum-floorcppprojectDir
cpp/package-manager-declaredcppprojectDir
cpp/standard-declaredcppprojectDir
cpp/standard-requiredcppprojectDir

All collectors

Buildnote Limited
Registered in England and Wales, Reg: 16140412