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
12 changes: 11 additions & 1 deletion .github/workflows/ci-fresh-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,19 @@ jobs:
- distro: arch
image: archlinux:latest
setup: pacman -Syu --noconfirm curl bash tar gzip xz git findutils binutils file
# The refresh is its own command, retried once, and the install runs
# only after it succeeds (#523). `zypper install` refreshes too, but
# when that refresh fails it continues on stale or empty metadata,
# and the leg went red with `No provider of 'binutils' found` --
# naming a package instead of the repository that could not be read.
# A rolling image can meet a repository's new signing key, which
# `-n` alone rejects; --gpg-auto-import-keys accepts it.
- distro: tumbleweed
image: opensuse/tumbleweed:latest
setup: zypper -n install curl bash tar gzip xz git findutils binutils file
setup: >-
{ zypper -n --gpg-auto-import-keys refresh ||
{ sleep 15; zypper -n --gpg-auto-import-keys refresh; }; } &&
zypper -n install curl bash tar gzip xz git findutils binutils file
- distro: debian-testing
image: debian:testing
setup: apt-get update && apt-get -y install curl bash tar gzip xz-utils git ca-certificates binutils findutils file
Expand Down
6 changes: 6 additions & 0 deletions docs/05-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ and `"0.0"` is `>= 0.0.0, < 0.1.0` (before 2026.10.31.1 both matched 0.0.0
alone). The dependency conflict check and the address check of `--locked` read
requirements the same way.

A range matches a pre-release key (`1.0.0-rc.1`) only when it names a
pre-release of the same version, so `*` or `^0.0` reaches none of the keys of a
package that publishes only pre-releases (`compat.glad` publishes
`0.0.0-651a425`). The error states that cause for the highest pre-release whose
release the range admits, and its `help:` line is the exact pin to write.

### `visibility` — whether a dependency's usage crosses this package's own boundary

```toml
Expand Down
15 changes: 15 additions & 0 deletions docs/09-commands-by-scenario.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ them. Confusing them costs a full rebuild.
|---|---|---|---|
| `target/<triple>/<fingerprint>/`, `target/.build-mcpp/{out,host}/` | one project | a configuration fingerprint changes and opens a new directory; a build program's outputs and the build programs are kept per configuration | `mcpp clean`, `mcpp clean --stale` |
| the build cache (`mcpp cache dir`) | the whole machine | any project compiles a dependency or a `std` module, or builds a host tool, or compiles the `mcpp` module its build program imports | collected after a build when unused for `[cache] unused_days`; `mcpp cache gc`, `mcpp cache prune`, `mcpp cache clean` |
| the work directories of plans (`<home>/cache/{build-database,pack-formats,publish-plan}/`) | the whole machine, one per project | `mcpp emit build-database`, `mcpp pack --list-formats` or `mcpp publish` plans a project | collected with the build cache's entries, by last use; `mcpp cache clean --all` |

`mcpp clean` removes `target/` entirely, and the next build recompiles
everything. `mcpp clean --stale` removes only the fingerprint directories that
Expand Down Expand Up @@ -129,6 +130,20 @@ mcpp cache gc --older-than 60d --dry-run # what would go, cache and store
mcpp cache gc --older-than 60d
```

`mcpp emit build-database`, `mcpp pack --list-formats` and `mcpp publish`'s
check of a library's pins plan a project without writing into it, each in a work directory of the home, one
per project: `<home>/cache/build-database/`, `cache/pack-formats/` and
`cache/publish-plan/`. A plan records its use in the directory's `.mcpp-plan`,
whose one line is the project root. `mcpp cache list` shows each directory as
an entry of kind `work`, named by the command and that project; the
collection after a build, `mcpp cache prune`, `mcpp cache gc --older-than` and
`gc --max-size` collect it by last use, as they collect a package entry.
`mcpp cache clean --all` removes every entry of the cache, these and the
outputs of build programs, the units and the patched variants included; the
flags `--deps`, `--std` and `--tools` each remove one kind and leave them. A
directory written before the record is dated by its own time. Removing one costs the
next plan of that project nothing but writing it again (mcpp#969).

## The versions a package publishes

`mcpp search` matches a substring and appends what each hit publishes, merged
Expand Down
16 changes: 14 additions & 2 deletions docs/51-supported-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ error: --locked was given and this resolution differs from mcpp.lock:
```

A release build, an audit or a CI job should pass `--locked`. It disables the
build fast path, so the assertion always runs.
build fast path, so the assertion always runs. With no `mcpp.lock` there is no
record to assert against: `--locked` then fails saying so, rather than naming
every package as one that moved, and writes none.

The lock does not yet constrain resolution — it records and verifies it.
Pinning a resolution to the lock as an input is a separate change to the
Expand All @@ -112,10 +114,20 @@ resolution:
mcpp emit sbom -o sbom.json
```

A component's `name`, `group` and `purl` state the package, whichever way the
manifest that declared it spelled it: `cmdline` and `mcpplibs.cmdline` are both
`pkg:mcpp/mcpplibs/cmdline@<version>`. A variant keeps its digest in the name,
and a version only build programs hold is the package at that version, with one
`mcpp:build-program` property for each program. A purl percent-encodes its
segments, so `+` is written `%2B`.

It reads `mcpp.lock` rather than resolving again, because a document describing
a different graph from the one that was built is worse than no document. A
component whose licence mcpp does not know is emitted as `NOASSERTION` rather
than omitted: an absent field reads as "not examined".
than omitted: an absent field reads as "not examined". With no `mcpp.lock` the
document names the root package alone, and a note on standard error says that
nothing is recorded: that is the whole truth for a project with no dependencies,
and not for one that has never been built.

## Default versions (2026.11.21.1+)

Expand Down
4 changes: 4 additions & 0 deletions docs/zh/05-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ qux = ">=1.0, <2.0" # Range combination
不带运算符的部分写法同样按 caret 的通配规则:`"0"` 为 `>= 0.0.0, < 1.0.0`,`"0.0"` 为 `>= 0.0.0, < 0.1.0`(2026.10.31.1 之前
两者都只匹配 0.0.0)。依赖冲突检查与 `--locked` 的地址核对以同样的方式读取要求。

范围只在写出同一版本的预发布时才匹配预发布键(`1.0.0-rc.1`),因此对只发布预发布键的包
(`compat.glad` 只发布 `0.0.0-651a425`),`*` 或 `^0.0` 一个键也够不着。这时的错误针对范围所容许的
版本中最高的那个预发布键说明原因,并在 `help:` 行给出应写的精确版本。

### `visibility` —— 一个依赖的用法是否跨越本包自己的边界

```toml
Expand Down
11 changes: 11 additions & 0 deletions docs/zh/09-commands-by-scenario.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
|---|---|---|---|
| `target/<三元组>/<指纹>/`、`target/.build-mcpp/{out,host}/` | 单个工程 | 一个配置指纹变化,开出一个新目录;构建程序的输出与构建程序按配置保存 | `mcpp clean`、`mcpp clean --stale` |
| 构建缓存(`mcpp cache dir`) | 整台机器 | 任何工程编译一个依赖、一个 `std` 模块,或构建一个 host 工具,或编译其构建程序 import 的 `mcpp` 模块 | 构建后回收 `[cache] unused_days` 内未使用的条目;`mcpp cache gc`、`mcpp cache prune`、`mcpp cache clean` |
| 规划的工作目录(`<home>/cache/{build-database,pack-formats,publish-plan}/`) | 整台机器,每个工程一个 | `mcpp emit build-database`、`mcpp pack --list-formats` 或 `mcpp publish` 规划一个工程 | 与构建缓存的条目一同按最后使用时间回收;`mcpp cache clean --all` |

`mcpp clean` 整个删掉 `target/`,下次构建重编一切。`mcpp clean --stale`
只删已无构建记录使用的指纹目录,在用的配置保留。每个配置目录在 `uses.list` 中
Expand Down Expand Up @@ -102,6 +103,16 @@ mcpp cache gc --older-than 60d --dry-run # 会回收什么:缓存与存储
mcpp cache gc --older-than 60d
```

`mcpp emit build-database`、`mcpp pack --list-formats` 与 `mcpp publish` 对库的版本钉的检查规划工程而不写入工程,
各自在 home 的一个工作目录中进行,每个工程一个:`<home>/cache/build-database/`、`cache/pack-formats/`
与 `cache/publish-plan/`。规划把一次使用记在目录的 `.mcpp-plan` 上,该文件只有一行,即工程根。
`mcpp cache list` 把每个目录列为 `work` 类条目,以命令与该工程命名;构建后的回收、`mcpp cache prune`、
`mcpp cache gc --older-than` 与 `gc --max-size` 按最后使用时间回收它,与回收包条目相同。
`mcpp cache clean --all` 移除缓存的全部条目,包括这些目录以及构建程序的输出、编译单元与打过补丁的变体;
`--deps`、`--std`、`--tools` 各移除一类条目,不触及它们。
早于该记录写出的目录以目录自身的时间计。
移除一个目录,该工程的下一次规划只需重新写出它(mcpp#969)。

## 一个包已发布的版本

`mcpp search` 按子串匹配,并在每个命中行后附上该包发布的版本 —— 跨描述符
Expand Down
11 changes: 9 additions & 2 deletions docs/zh/51-supported-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ error: --locked was given and this resolution differs from mcpp.lock:
```

发布构建、审计或 CI 作业应当传入 `--locked`。它会关闭构建快路径,因此该断言
总会执行。
总会执行。没有 `mcpp.lock` 时没有可供断言的记录:此时 `--locked` 失败并说明这一点,
而不是把每个包都报成发生了变化,也不写出 lock。

锁尚不约束解析——它只记录并校验解析结果。把锁作为解析的输入来钉住结果,是对
解析器的另一项改动。
Expand All @@ -97,9 +98,15 @@ error: --locked was given and this resolution differs from mcpp.lock:
mcpp emit sbom -o sbom.json
```

组件的 `name`、`group` 与 `purl` 陈述的是包本身,与声明它的清单如何拼写无关:`cmdline` 与
`mcpplibs.cmdline` 都是 `pkg:mcpp/mcpplibs/cmdline@<版本>`。变体在名字中保留其摘要;只被构建程序
持有的版本就是该版本的这个包,并为每个构建程序带一条 `mcpp:build-program` 属性。purl 对各段做
百分号编码,因此 `+` 写作 `%2B`。

它读取 `mcpp.lock` 而不是重新解析,因为一份描述了与实际构建不同的依赖图的
文档,比没有文档更糟。许可证 mcpp 无法识别的组件会被写成 `NOASSERTION` 而不是
省略:缺失的字段读起来像「未检查」。
省略:缺失的字段读起来像「未检查」。没有 `mcpp.lock` 时,文档只列出根包,并在标准
错误上提示没有任何记录:这对没有依赖的工程是全部事实,对从未构建过的工程则不是。

## 缺省版本(2026.11.21.1 起)

Expand Down
9 changes: 7 additions & 2 deletions modules/versioning/src/version_req.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ bool is_constraint(std::string_view s);

bool matches(const Requirement& r, const Version& v);

// Whether `r` reaches the pre-release `v` at all: it names a pre-release of the
// same numbers. `matches` asks it first; a refusal asks it to tell a pre-release
// the range does not see from one it sees and excludes.
bool prerelease_visible(const Requirement& r, const Version& v);

// Indices of ALL versions in `available` that match `req` and tie for highest
// precedence. Normally one element. More than one means distinct entries
// compare EQUAL — only possible when they differ solely in build metadata
Expand Down Expand Up @@ -319,6 +324,8 @@ std::expected<Comparator, std::string> parse_comparator(std::string_view s) {
return Comparator{op, *v};
}

} // namespace

// SemVer/npm/Cargo pre-release visibility: a pre-release candidate is only
// eligible when the requirement itself names a pre-release at the SAME numeric
// tuple. Two bugs collapse into this one rule:
Expand All @@ -334,8 +341,6 @@ bool prerelease_visible(const Requirement& r, const Version& v) {
return false;
}

} // namespace

bool is_constraint(std::string_view s) {
if (s.empty()) return true; // "any version"
if (s == "*") return true;
Expand Down
101 changes: 101 additions & 0 deletions src/bmi_cache/maintenance.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// $MCPP_HOME/build-cache/v1/std/<identity>/std-module.json
// $MCPP_HOME/build-cache/v1/tool/<index>/<pkg>@<ver>/<key>/entry.json
// (a host tool, mcpp.build.tool_store; last use = the record's time)
// $MCPP_HOME/cache/{build-database,pack-formats,publish-plan}/<key>/.mcpp-plan
// (the work directory of a plan that describes; last use = the record's time)
//
// Two things this file did wrong before the layout change and that the new
// entry.json fixes:
Expand All @@ -23,6 +25,7 @@ export module mcpp.bmi_cache.maintenance;

import std;
import mcpp.home;
import mcpp.home.files; // mark_used
import nlohmann.json;
import mcpp.libs.toml;
import mcpp.ui;
Expand Down Expand Up @@ -95,6 +98,58 @@ export std::optional<std::uintmax_t> parse_size(std::string_view v) {
return std::nullopt;
}

// THE WORK DIRECTORIES OF PLANS THAT DESCRIBE (mcpp#969). `mcpp emit
// build-database`, `mcpp pack --list-formats` and the pin check of `mcpp
// publish` plan a project without writing into it (PrepareIntent::Describe),
// each in a directory of the home, `cache/<area>/<key>`, one per project.
// Nothing removed one: a home measured on 2026-11-19 held 626 of them, 3.4 GB,
// most of them for projects that no longer existed. A plan states its use on
// the directory's record, and `cache list`, `gc`, `prune` and the collection
// after a build treat each directory as an entry. Removing one costs nothing
// but the next plan's writing it again (SPEC-005 R2.1).
export enum class PlanArea { BuildDatabase, PackFormats, PublishPlan };

namespace {

struct PlanAreaInfo {
PlanArea area;
std::string_view dir; // under `<home>/cache/`
std::string_view command; // what plans there, as `cache list` names it
};

constexpr std::array<PlanAreaInfo, 3> kPlanAreas{{
{PlanArea::BuildDatabase, "build-database", "emit build-database"},
{PlanArea::PackFormats, "pack-formats", "pack --list-formats"},
{PlanArea::PublishPlan, "publish-plan", "publish"},
}};

// The record whose time is the directory's last use (mcpp::home::mark_used);
// its one line is the project root the directory plans.
constexpr std::string_view kPlanRecord = ".mcpp-plan";

std::filesystem::path plan_area_root(const PlanAreaInfo& area) {
return mcpp::home::root() / "cache" / area.dir;
}

} // namespace

// The work directory of a plan of `area` named `key`, created, with its use
// stated: the record is written when the directory is new and its time set to
// now otherwise. `project` is what `cache list` names the directory by.
export std::filesystem::path plan_work_dir(PlanArea area, std::string_view key,
const std::filesystem::path& project) {
const auto& info = *std::ranges::find(kPlanAreas, area, &PlanAreaInfo::area);
const auto dir = plan_area_root(info) / std::string(key);
std::error_code ec;
std::filesystem::create_directories(dir, ec);
const auto record = dir / kPlanRecord;
if (std::filesystem::exists(record, ec))
mcpp::home::mark_used(record);
else
std::ofstream(record, std::ios::binary) << mcpplibs::os::fs::generic_utf8(project) << '\n';
return dir;
}

namespace {

std::filesystem::path pkg_root() { return mcpp::home::cache_root() / "pkg"; }
Expand Down Expand Up @@ -382,6 +437,42 @@ std::vector<Entry> walk_program_out_entries() {
return out;
}

// The work directories of plans that describe (plan_work_dir): one per
// project and area, each last used when a plan last ran in it. Collected as
// the cache's entries are; like a build program's outputs and the units, the
// one flag of `cache clean` that removes them is `--all`.
std::vector<Entry> walk_plan_entries() {
std::vector<Entry> out;
for (const auto& area : kPlanAreas) {
std::error_code ec;
const auto root = plan_area_root(area);
for (auto& d : std::filesystem::directory_iterator(root, ec)) {
if (!d.is_directory()) continue;
Entry e;
e.dir = d.path();
e.kind = "work";
e.key = mcpplibs::os::fs::generic_utf8(d.path().filename());
const auto record = e.dir / kPlanRecord;
std::string project;
std::error_code fe;
if (std::filesystem::is_regular_file(record, fe)) {
e.accessed = dir_mtime_seconds(record);
if (std::ifstream is(record, std::ios::binary); is) std::getline(is, project);
} else {
// Written by an mcpp before the record: the directory's time is
// the last plan that wrote or removed a file directly in it.
e.accessed = dir_mtime_seconds(e.dir);
}
e.label = project.empty()
? std::format("{} (work directory)", area.command)
: std::format("{} (work directory of {})", area.command, project);
measure(e);
out.push_back(std::move(e));
}
}
return out;
}

// THE UNITS (design 2026-11-20 §5.3): one per compile key and manifest under
// `build-cache/v1/unit/<k>/<key>/<manifest>`, last used when a build last
// placed it (its `manifest.tsv` is touched then).
Expand Down Expand Up @@ -417,6 +508,7 @@ std::vector<Entry> walk_collectable() {
for (auto& e : walk_variant_entries()) out.push_back(std::move(e));
for (auto& e : walk_program_out_entries()) out.push_back(std::move(e));
for (auto& e : walk_unit_entries()) out.push_back(std::move(e));
for (auto& e : walk_plan_entries()) out.push_back(std::move(e));
return out;
}

Expand Down Expand Up @@ -759,6 +851,15 @@ export int cache_clean(bool deps, bool stds, bool tools, bool all, bool legacy)
std::filesystem::remove_all(tool_root(), ec);
std::println("Cleaned host tool entries ({})", human_bytes(n));
}
if (all) {
// `--all` is every kind `cache list` shows. The three roots above are
// gone; what is left are the kinds no flag names: patched variants, the
// outputs of build programs, the units and the work directories of
// plans (mcpp#969). Before, `--all` left them and stated nothing.
std::uintmax_t n = 0;
for (const auto& e : walk_collectable()) n += remove_entry(e);
std::println("Cleaned the entries of every other kind ({})", human_bytes(n));
}
if (legacy) {
auto legacyRoot = mcpp::home::legacy_bmi_root();
if (std::filesystem::exists(legacyRoot, ec)) {
Expand Down
Loading
Loading