Skip to content

Commit 1a970f0

Browse files
authored
Merge pull request #395 from zackees/feat/cpp-393
feat(ci-lint): C/C++ (CMake) support for the local gate, attestations and caches (#393)
2 parents 5e621ed + cd5d99c commit 1a970f0

50 files changed

Lines changed: 1738 additions & 49 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 10 additions & 8 deletions
Large diffs are not rendered by default.

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This combines a predictable CI interface with measured evidence. Shared reusable
1212

1313
## Policy at a glance
1414

15-
Each row is fleet-wide policy; where `ci_lint` checks it mechanically today, the row says so and names the rule ID (see [docs/policy-general.md](docs/policy-general.md)/[docs/policy-rust.md](docs/policy-rust.md) for the full rule tables).
15+
Each row is fleet-wide policy; where `ci_lint` checks it mechanically today, the row says so and names the rule ID (see [docs/policy-general.md](docs/policy-general.md)/[docs/policy-rust.md](docs/policy-rust.md)/[docs/policy-cpp.md](docs/policy-cpp.md) for the full rule tables).
1616

1717
| Area | Fleet rule |
1818
| --- | --- |
@@ -43,6 +43,7 @@ The exact Dylint command is not a text-match rule. For example, `soldr cargo dyl
4343

4444
- [General code repository policy](docs/policy-general.md): quick gate, the `ci.toml`/`ci-lint` contract, caching, secrets/publishing, local CI, the local gate first rule (`GATE-001..004`: the remote quick gate is a subset of one local command, and a PR head must carry a tree-bound `Local-Gate:` attestation before remote CI runs), remote-only checks that never gate a PR (`GATE-012`: CodeRabbit suppressed, act-impossible actions confined to non-PR events, zero wait on app checks), timing, and exceptions — with a full rule-ID table marking what `ci_lint` enforces today versus what remains a candidate.
4545
- [Rust repository policy](docs/policy-rust.md): common Rust checks, the Soldr/platform-facade/Dylint/private-crate decisions, libraries, and apps published to PyPI or npm.
46+
- [C/C++ (CMake) repository policy](docs/policy-cpp.md): `cpp/...` attestation gates, C/C++ lane-key pins and compiler identity, ccache/zccache cache families, no CMake build trees in caches, the cmake/ctest `GEN-005` allowlist, parallel `ctest` (`CPP-001`), and the format-lane and native-leg patterns ([#393](https://github.com/zackees/ci.yml/issues/393)).
4647
- [`docs/ci-toml.md`](docs/ci-toml.md): the field-by-field schema-3 reference and rule catalog for `ci_lint`, the source of truth this repository's policy docs are checked against.
4748
- [`ci_lint/`](ci_lint/): the checker itself (stdlib-only Python) — static precheck, the tag/flow planner, runtime build/wheel/units checks, cache key/save-ok/audit/janitor commands, the live settings/secrets audit, the OIDC mock-publish check, and the release-candidate gate.
4849
- [`examples/rust-pypi-app/ci.toml`](examples/rust-pypi-app/ci.toml): the canonical `ci.toml`, identical (apart from repo-specific values) to the one in the reference repository, [`zackees/template-python-rust-cmd`](https://github.com/zackees/template-python-rust-cmd).

‎ci_lint/attestations.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
1515
Gate paths follow the platform schema pattern `<ecosystem>/<platform>/<check>`:
1616
`rust/<target triple | all>/<check>` first, then `python/...`, then
17-
`general/...`. The file is parsed with `ci_lint.mini_yaml` (restricted YAML,
17+
`cpp/<os-arch | target triple | all>/<check>` (C/C++, CMake; zackees/ci.yml#393,
18+
docs/policy-cpp.md), then `general/...`. The file is parsed with `ci_lint.mini_yaml` (restricted YAML,
1819
standard library only), so a bare developer host can read it.
1920
2021
**Attestation (compact JSON, the transit form).** `ci-lint local-gate run`
@@ -56,10 +57,15 @@
5657
TRAILER_KEY = "Ci-Attestation"
5758
VERSION = 1
5859
STAMP_HEX = 32
59-
ECOSYSTEMS: tuple[str, ...] = ("rust", "python", "general")
60+
ECOSYSTEMS: tuple[str, ...] = ("rust", "python", "cpp", "general")
6061
FIDELITIES: tuple[str, ...] = ("native", "vm", "emulation")
6162
_GATE = re.compile(r"^(?P<eco>[a-z]+)/(?P<platform>[A-Za-z0-9_.-]+)/(?P<check>[a-z0-9][a-z0-9-]*)$")
6263
_TRIPLE = re.compile(r"^[a-z0-9_]+(-[a-z0-9_]+){2,3}$")
64+
# C/C++ platforms (#393): `all`, `<os>-<arch>` (the CMake-preset / runner
65+
# spelling, e.g. `linux-x64`, `windows-arm64`), or a target triple.
66+
CPP_OSES: tuple[str, ...] = ("linux", "windows", "macos", "freebsd", "android", "ios")
67+
CPP_ARCHES: tuple[str, ...] = ("x64", "x86", "arm64", "armv7", "riscv64", "universal")
68+
_CPP_OS_ARCH = re.compile(rf"^(?:{'|'.join(CPP_OSES)})-(?:{'|'.join(CPP_ARCHES)})$")
6369
_TRAILER = re.compile(rf"^{TRAILER_KEY}:\s*(?P<body>\{{.*\}})\s*$", re.MULTILINE)
6470
_JOB = re.compile(r"^[^/:]+:[^:]+$")
6571

@@ -122,6 +128,8 @@ def validate_gate_path(path: str) -> str | None:
122128
plat = match.group("platform")
123129
if match.group("eco") == "rust" and plat != "all" and not _TRIPLE.match(plat):
124130
return f"Rust platform '{plat}' is not 'all' or a target triple"
131+
if match.group("eco") == "cpp" and plat != "all" and not (_CPP_OS_ARCH.match(plat) or _TRIPLE.match(plat)):
132+
return f"C/C++ platform '{plat}' is not 'all', '<os>-<arch>' (e.g. linux-x64) or a target triple"
125133
return None
126134

127135

‎ci_lint/cache/families.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,24 @@ class FamilyShape:
180180
# setup-soldr:dylint to the schema's allowed via values"; amended same
181181
# round to add "setup-uv" (astral-sh/setup-uv's own built-in cache is a
182182
# real, declarable family -- not a permanent CACHE-001 finding).
183-
ALLOWED_VIA_VALUES: frozenset[str] = frozenset({CI_LINT_VIA, *EXTERNAL_SHAPES_BY_VIA})
183+
# C/C++ compiler object caches (zackees/ci.yml#393, docs/policy-cpp.md):
184+
# `ccache`'s and `zccache`'s own cache directories (CCACHE_DIR /
185+
# ZCCACHE_DIR), saved through the sanctioned actions/cache wrapper. Neither
186+
# tool writes GitHub cache keys itself, so the key is ci-lint's own
187+
# convention exactly like `via = "ci-lint"`: `<family>-v1-<components>`,
188+
# built by `ci-lint cache key`. Writer rules are the same as every base
189+
# layer (CACHE-008 rule 2: saved only on a `[cache].write-on` flow,
190+
# restored on PRs; CACHE-027 for a family no writer ever saves).
191+
TOOL_OWNED_VIA: frozenset[str] = frozenset({"ccache", "zccache"})
192+
193+
ALLOWED_VIA_VALUES: frozenset[str] = frozenset({CI_LINT_VIA, *TOOL_OWNED_VIA, *EXTERNAL_SHAPES_BY_VIA})
194+
195+
196+
def is_ci_lint_keyed(via: str) -> bool:
197+
"""True when ci-lint builds the family's whole key (`ci-lint` or a
198+
tool-owned object cache), so its declared `key` components apply."""
199+
200+
return via == CI_LINT_VIA or via in TOOL_OWNED_VIA
184201

185202

186203
def resolve_prefix(via: str, family_id: str) -> str | None:
@@ -189,7 +206,7 @@ def resolve_prefix(via: str, family_id: str) -> str | None:
189206
should already have rejected it as CT-002; this function just must
190207
never fabricate a prefix for something it doesn't know."""
191208

192-
if via == CI_LINT_VIA:
209+
if is_ci_lint_keyed(via):
193210
return f"{family_id}-{CI_LINT_KEY_VERSION}-"
194211
shape = EXTERNAL_SHAPES_BY_VIA.get(via)
195212
return shape.prefix if shape is not None else None

‎ci_lint/cache/keys.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from dataclasses import dataclass
2222
from pathlib import Path
2323

24-
from ci_lint.cache.families import CI_LINT_VIA, DELTA_KEY_VERSION, resolve_prefix
24+
from ci_lint.cache.families import DELTA_KEY_VERSION, is_ci_lint_keyed, resolve_prefix
2525
from ci_lint.schema import CiToml
2626

2727
# Components a [cache.family.<id>].key entry may name besides a literal
@@ -91,7 +91,7 @@ def build_family_key(ci: CiToml, family_id: str, *, platform_id: str | None, rep
9191
raise CacheKeyError(
9292
f"[cache.family.{family_id}].via = {fam.via!r} is not a recognized via value"
9393
)
94-
if fam.via != CI_LINT_VIA:
94+
if not is_ci_lint_keyed(fam.via):
9595
return FamilyKey(family=family_id, prefix=prefix, components=())
9696
components = tuple(
9797
_resolve_component(c, ci=ci, platform_id=platform_id, repo_root=repo_root) for c in (fam.key or ())

‎ci_lint/cache/payload_classify.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""CACHE-007 (round M2-20, zackees/ci.yml#44 part A): classify a cache
22
payload's declared/actual paths against `[cache].never`'s forbidden content
33
classes -- linked test binaries, nextest archives, `incremental/`, and a
4-
whole `target/` directory (zackees/zccache#1525, soldr#2931-#2938).
4+
whole `target/` directory (zackees/zccache#1525, soldr#2931-#2938), and a
5+
CMake build tree (zackees/ci.yml#393).
56
67
`ci.toml` schema 3 already accepts `[cache].never` as a *declaration*
78
(policy-general.md's Cache policy); this module is the first place that
@@ -37,9 +38,29 @@
3738
"whole target/ directory",
3839
re.compile(r"(?:^|/)target/?$"),
3940
),
41+
# zackees/ci.yml#393 (docs/policy-cpp.md): a CMake build tree is per-run
42+
# output keyed on absolute paths and configure state; the compiler's
43+
# object cache (ccache/zccache) is the reusable part. A whole build
44+
# directory (`build/`, `build-<x>/`, `build_<x>/`, `cmake-build-<x>/`,
45+
# `out/build/<preset>/`), or any path inside CMake's own `CMakeFiles/` or
46+
# `CMakeCache.txt`, is the build tree.
47+
(
48+
"CMake build tree",
49+
re.compile(
50+
r"(?:^|/)(?:_?build|build[-_][A-Za-z0-9._-]+|cmake-build-[A-Za-z0-9._-]+|out/build(?:/[^/]+)?)/?$"
51+
r"|(?:^|/)CMakeFiles(?:/|$)|(?:^|/)CMakeCache\.txt$"
52+
),
53+
),
4054
)
4155

4256

57+
def is_cmake_build_tree(path: str) -> bool:
58+
"""True when `path` is (or is inside the metadata of) a CMake build tree."""
59+
60+
pattern = dict(_NEVER_CLASS_PATTERNS)["CMake build tree"]
61+
return pattern.search(path.strip().replace("\\", "/")) is not None
62+
63+
4364
@dataclass(frozen=True)
4465
class PayloadViolation:
4566
path: str

‎ci_lint/cache/save_ok.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""`ci-lint cache save-ok <family>`: issue #6 §6's "when we do NOT save"
2-
table, rule ID CACHE-008, evaluated in order 1-10 (round-4A brief,
2+
table, rule ID CACHE-008, evaluated in order 1-11 (11: a CMake build tree,
3+
zackees/ci.yml#393) (round-4A brief,
34
deliverable 3). Prints the first rule that blocks the save, or "save:
45
yes"; a skipped save is always explainable by its rule number.
56
"""
@@ -8,6 +9,7 @@
89

910
from dataclasses import dataclass
1011

12+
from ci_lint.cache.payload_classify import is_cmake_build_tree
1113
from ci_lint.rules.cache_static import parse_size
1214
from ci_lint.schema import CiToml
1315

@@ -37,6 +39,9 @@ class SaveOkRequest:
3739
lockfile_changed: bool = False
3840
tags: tuple[str, ...] = ()
3941
rerun_saved: bool = False
42+
# The paths the save would archive (`--path`, repeatable). Only rule 11
43+
# reads them; empty means "not supplied", never "an empty payload".
44+
paths: tuple[str, ...] = ()
4045

4146

4247
@dataclass(frozen=True)
@@ -156,4 +161,16 @@ def evaluate_save_ok(ci: CiToml, req: SaveOkRequest) -> SaveOkResult: # noqa: C
156161
if req.rerun_saved:
157162
return SaveOkResult(False, 10, "this exact key was already saved by a previous attempt this run")
158163

159-
return SaveOkResult(True, None, "no rule 1-10 applies")
164+
# Rule 11 (zackees/ci.yml#393, docs/policy-cpp.md): the payload is a CMake build tree.
165+
# The compiler's object cache (a ccache/zccache directory) is the reusable layer; the build
166+
# tree is per-run configure/link output bound to absolute paths -- never a cross-run cache.
167+
tree = [p for p in req.paths if is_cmake_build_tree(p)]
168+
if tree:
169+
return SaveOkResult(
170+
False,
171+
11,
172+
f"the payload includes a CMake build tree ({', '.join(tree)}); save the ccache/zccache "
173+
"object store instead",
174+
)
175+
176+
return SaveOkResult(True, None, "no rule 1-11 applies")

‎ci_lint/cli.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ def _cmd_cache_save_ok(args: argparse.Namespace) -> int:
923923
lockfile_changed=args.lockfile_changed,
924924
tags=_parse_tags_arg(args.tags),
925925
rerun_saved=args.rerun_saved,
926+
paths=tuple(args.path or ()),
926927
)
927928
try:
928929
result = evaluate_save_ok(ci, req)
@@ -1390,6 +1391,10 @@ def build_parser() -> argparse.ArgumentParser:
13901391
p_cache_save_ok.add_argument("--lockfile-changed", action="store_true")
13911392
p_cache_save_ok.add_argument("--tags", default=None)
13921393
p_cache_save_ok.add_argument("--rerun-saved", action="store_true")
1394+
p_cache_save_ok.add_argument(
1395+
"--path", action="append", default=None,
1396+
help="a path the save would archive (repeatable); rule 11 refuses a CMake build tree",
1397+
)
13931398
p_cache_save_ok.add_argument("--json", action="store_true")
13941399
p_cache_save_ok.set_defaults(func=_cmd_cache_save_ok)
13951400

‎ci_lint/lane_cache.py‎

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,44 @@
6161
class EcosystemPins:
6262
"""Lockfiles and toolchain pins a lane must treat as inputs when it
6363
drives any of `tools` (design revision 3, #177: soldr's Python-lint lane
64-
was invalidated by every Cargo.lock bump it cannot be affected by)."""
64+
was invalidated by every Cargo.lock bump it cannot be affected by).
65+
66+
`globs` are repository-path patterns for pins that are not one file name
67+
(a CMake module tree, `conanfile.*`); `identity` names extra tools whose
68+
`--version` joins the key whenever the ecosystem matches -- the compiler
69+
a CMake lane resolves (`cc`/`c++`) without the lane naming it (#393)."""
6570

6671
tools: frozenset[str]
6772
basenames: frozenset[str]
68-
73+
globs: tuple[str, ...] = ()
74+
identity: tuple[str, ...] = ()
75+
# The subset of `tools` that compiles; `identity` is probed only for a
76+
# lane declaring one of these (a clang-format-only lane never compiles).
77+
identity_when: frozenset[str] = frozenset()
78+
79+
80+
# C/C++ (CMake) tools a lane may declare (zackees/ci.yml#393, docs/policy-cpp.md).
81+
CPP_TOOLS: frozenset[str] = frozenset(
82+
{
83+
"cmake", "ctest", "cpack", "ninja", "make", "gmake", "meson",
84+
"cc", "c++", "gcc", "g++", "clang", "clang++", "clang-cl", "cl",
85+
"clang-format", "clang-tidy", "gersemi", "ccache", "zccache", "sccache",
86+
"vcpkg", "conan",
87+
}
88+
) # fmt: skip
89+
CPP_PIN_BASENAMES: frozenset[str] = frozenset(
90+
{
91+
"CMakeLists.txt", "CMakePresets.json", "CMakeUserPresets.json",
92+
"vcpkg.json", "vcpkg-configuration.json", "conanfile.txt", "conanfile.py",
93+
"buildspec.json", ".gitmodules", ".clang-format", ".clang-tidy",
94+
".gersemirc", "toolchain.cmake",
95+
}
96+
) # fmt: skip
97+
# Root-anchored: `cmake/**` is the conventional CMake module directory; the
98+
# `*.cmake` glob catches modules and toolchain files kept anywhere else.
99+
CPP_PIN_GLOBS: tuple[str, ...] = ("cmake/**", "**/*.cmake", "**/conanfile.*")
100+
CPP_COMPILER_IDENTITY: tuple[str, ...] = ("cc", "c++")
101+
CPP_FORMAT_TOOLS: frozenset[str] = frozenset({"clang-format", "gersemi"})
69102

70103
ECOSYSTEM_PINS: tuple[EcosystemPins, ...] = (
71104
EcosystemPins(
@@ -80,21 +113,44 @@ class EcosystemPins:
80113
frozenset({"node", "npm", "npx", "pnpm", "yarn"}),
81114
frozenset({"package-lock.json", "pnpm-lock.yaml", "yarn.lock"}),
82115
),
116+
EcosystemPins(CPP_TOOLS, CPP_PIN_BASENAMES, CPP_PIN_GLOBS, CPP_COMPILER_IDENTITY, CPP_TOOLS - CPP_FORMAT_TOOLS),
83117
)
84118
ALL_PIN_BASENAMES: frozenset[str] = frozenset().union(*(e.basenames for e in ECOSYSTEM_PINS))
85119

86120

121+
def _matched_ecosystems(tools: tuple[str, ...]) -> tuple[EcosystemPins, ...]:
122+
return tuple(e for e in ECOSYSTEM_PINS if e.tools & set(tools))
123+
124+
87125
def pin_basenames(tools: tuple[str, ...]) -> frozenset[str]:
88126
"""The pins a lane's tools make mandatory. A lane that declares no
89127
recognized tool gets every pin: the safe default when the gate cannot
90128
tell what the lane resolves."""
91129

92-
matched = [e.basenames for e in ECOSYSTEM_PINS if e.tools & set(tools)]
130+
matched = [e.basenames for e in _matched_ecosystems(tools)]
93131
if not matched:
94132
return ALL_PIN_BASENAMES
95133
return frozenset().union(*matched)
96134

97135

136+
def pin_globs(tools: tuple[str, ...]) -> tuple[str, ...]:
137+
"""Path-pattern pins (`cmake/**`, `**/*.cmake`, ...), with the same
138+
every-pin default as `pin_basenames` for a lane with no recognized tool."""
139+
140+
matched = _matched_ecosystems(tools) or ECOSYSTEM_PINS
141+
return tuple(g for e in matched for g in e.globs)
142+
143+
144+
def key_tools(tools: tuple[str, ...]) -> tuple[str, ...]:
145+
"""The tools whose `--version` a lane's key covers: the declared ones
146+
plus each matched ecosystem's identity tools (a compiling C/C++ lane's
147+
`cc`/`c++`, #393). Only for recognized compiling tools: an unknown-tool
148+
or format-only lane is not assumed to compile anything."""
149+
150+
implied = {t for e in _matched_ecosystems(tools) if e.identity_when & set(tools) for t in e.identity}
151+
return tuple(sorted(set(tools) | implied))
152+
153+
98154
@dataclass(frozen=True)
99155
class LaneConfig:
100156
id: str
@@ -195,6 +251,9 @@ def mandatory_paths(lane: LaneConfig, gate_run: tuple[str, ...], gate_source: st
195251
named.add(gate_source)
196252
always = DECLARATION_BASENAMES | pin_basenames(lane.tools)
197253
named.update(p for p in paths if p.rsplit("/", 1)[-1] in always)
254+
globs = [glob_to_regex(g) for g in pin_globs(lane.tools)]
255+
if globs:
256+
named.update(p for p in paths if any(r.match(p) for r in globs))
198257
return named & paths
199258

200259

@@ -290,7 +349,7 @@ def lane_key(
290349
header = KeyHeader(
291350
v=KEY_VERSION,
292351
run=lane.run,
293-
tools=tuple(versions.get(tool) for tool in sorted(set(lane.tools))),
352+
tools=tuple(versions.get(tool) for tool in key_tools(lane.tools)),
294353
env=tuple(EnvValue(name, env.get(name, "")) for name in sorted(set(lane.env))),
295354
provider=provider,
296355
)

‎ci_lint/local_gate_cli.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
from ci_lint.github_api import GitHubApiError, default_fetch
3333
from ci_lint.gate_bare_tools import check_no_bare_rust
3434
from ci_lint.remote_only import check_gate_012
35+
from ci_lint.rules.cpp_ctest import check_cpp_001
3536
from ci_lint.rules.swatinem_ban import check_cache_025
37+
from ci_lint.rules.tools import CI_SCRIPT_RE
3638
from ci_lint.gate_trust import TrustDecision, TrustInput
3739
from ci_lint.gate_trust import decide as decide_trust
3840
from ci_lint.lane_cache import ToolVersions, lane_key, lookup, run_audit, simulate, tree_entries
@@ -258,6 +260,10 @@ def _cmd_lint(args: argparse.Namespace) -> int:
258260
if config is not None:
259261
findings = findings + check_gate_static(config, repo) + check_no_bare_rust(repo, config.run) + check_gate_012(repo)
260262
findings = findings + check_cache_025(repo)
263+
gate_scripts = tuple(
264+
tok for argv in (config.run, *(lane.run for lane in config.lanes)) for tok in argv if CI_SCRIPT_RE.match(tok)
265+
)
266+
findings = findings + check_cpp_001(repo, extra_scripts=gate_scripts)
261267
for finding in findings:
262268
print(finding.render())
263269
violations = [f for f in findings if f.status == Status.VIOLATION]

0 commit comments

Comments
 (0)