From e4e1af93cb2d3375fa8ec813d64f7a48498b8411 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 24 Nov 2026 11:59:32 +0900 Subject: [PATCH 1/3] fix: -o / writes a provided format's distributable with the outputs it reads beside it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A provider's distributable is the output no other action consumes. Copied alone into the -o directory, a web page arrived without its .js, its .wasm and its deployed files. The distributable is now written with the outputs it consumed that lie below its own directory, at their places relative to it (SPEC-014 §6, v2.8; e2e formats/1160). --- CHANGELOG.md | 10 ++++++++ docs/30-build-mcpp.md | 8 ++++++ docs/specs/packaging.md | 12 ++++++--- docs/zh/30-build-mcpp.md | 4 +++ src/pack/pipeline.cppm | 38 ++++++++++++++++++++++++---- tests/e2e/pack/formats.cpp | 52 +++++++++++++++++++++++++++++++++++++- 6 files changed, 114 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a585307cb..088502fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ > Each `## []` section is that release's notes. Entries are written in English > from 2026.9.28.3 on; earlier entries remain as written. +## [2026.11.24.1] - 2026-11-24 + +### Fixed + +- `mcpp pack --pkg-format -o /` writes the distributable together + with the outputs it consumed that lie below its own directory, at their places relative to it. + Before, it wrote the distributable alone, so a web page (`--pkg-format web`) arrived without its + `.js`, its `.wasm` and its deployed files and loaded nothing. Each destination is replaced, and + nothing else in the directory is touched (SPEC-014 §6, v2.8). + ## [2026.11.23.1] - 2026-11-23 ### Added diff --git a/docs/30-build-mcpp.md b/docs/30-build-mcpp.md index 0004e5fc8..859065f93 100644 --- a/docs/30-build-mcpp.md +++ b/docs/30-build-mcpp.md @@ -1142,6 +1142,14 @@ second pass, the refusal lists the warnings it stated there (`mcpp::warning`, `mcpp::report`) as its reasons, so a provider explains a decline with either and not with its standard error, which mcpp shows only for a program that fails. +**`-o /` writes what the distributable reads beside it.** The +distributable is the output no other action consumes. With `-o /`, it +is written into that directory under its own name. The outputs it consumed that +lie below its own directory are written with it, at their places relative to it +(2026.11.24.1). For `web`, the page arrives with its `.js`, its `.wasm` and the +deployed files. Each destination is replaced, and nothing else in the directory +is touched. + **`mcpp pack --pkg-format ` prepares twice.** An `artifact` action is a ninja edge and the staged tree is produced by mcpp *after* the link, so the tree cannot be an input of the pass that built it. The first pass collects the diff --git a/docs/specs/packaging.md b/docs/specs/packaging.md index 8b9d73338..027c48a61 100644 --- a/docs/specs/packaging.md +++ b/docs/specs/packaging.md @@ -4,10 +4,10 @@ |---|---| | 规范编号 | SPEC-014 | | 标题 | 打包与分发:链接、闭包、容器三个维度与构建腿,腿的合并,暂存树与包元数据,运行覆盖、单文件、容器列表、签名、压缩、合并与分发描述 | -| 状态 | 评审中 v2.7 | -| 版本 | 2.7 | -| 最后修改 | 2026-11-23 | -| 对应实现 | mcpp >= 2026.10.31.1;v2.2 条款 mcpp >= 2026.11.10.1;v2.3 条款 mcpp >= 2026.11.12.1;v2.4 条款 mcpp >= 2026.11.13.1;v2.5 条款 mcpp >= 2026.11.16.1;v2.6 条款 mcpp >= 2026.11.17.1;v2.7 条款 mcpp >= 2026.11.23.1 | +| 状态 | 评审中 v2.8 | +| 版本 | 2.8 | +| 最后修改 | 2026-11-24 | +| 对应实现 | mcpp >= 2026.10.31.1;v2.2 条款 mcpp >= 2026.11.10.1;v2.3 条款 mcpp >= 2026.11.12.1;v2.4 条款 mcpp >= 2026.11.13.1;v2.5 条款 mcpp >= 2026.11.16.1;v2.6 条款 mcpp >= 2026.11.17.1;v2.7 条款 mcpp >= 2026.11.23.1;v2.8 条款 mcpp >= 2026.11.24.1 | | 相关设计文档 | `.agents/docs/2026-11-15-ecosystem-gap-supplement-design.md`(§5)、`.agents/docs/2026-10-30-ecosystem-part2-ide-and-language-service-design.md`(§19.6)、`.agents/docs/2026-10-29-ecosystem-target-sets-packaging-and-editors-design.md`(§4、§13)、`.agents/docs/2026-10-28-platforms-part2-packaging-and-distribution-design.md`(§2–§7、§14)、`.agents/docs/2026-10-28-platforms-design.md`(§4.7)、`.agents/docs/2026-10-29-openkal-run-test-pack-design.md`(§2.2、§2.6) | | 相关 issue | mcpp#847、mcpp#849、mcpp#860 | | 相关规范 | [SPEC-007](build-plugins.md)(包格式提供者、artifact action)、[SPEC-011](concurrency.md)(原子发布)、[SPEC-013](platforms.md)(平台、运行器、载体)、[SPEC-015](target-sets.md)(目标集合与腿) | @@ -422,6 +422,9 @@ openkal 目标的单文件:载体携带一条腿的映像本身(映像不引用 (`mcpp::pack_stage_dir()`、`${mcpp.stage_dir}`)、其中的 `mcpp-package.json`、`MCPP_PACK_*` 环境;它报告的终端 输出即产物。未知的名字被拒绝,消息列出图中可用的格式。 +`-o <目录>/` 时,产物以其名字写入该目录,它消费的同一提供者的输出中位于产物所在目录之下的,按相对产物的位置一并写入 +(v2.8):产物在运行时从其旁读取的文件(网页的脚本与模块)随它交付。每个目标位置被替换,该目录中的其他内容不变。 + 提供者**可以**以 `mcpp::pack_program("")` 陈述它从被打包的包的哪个程序组装产物(构建程序协议 19, 2026.11.16.1)。陈述与 `provides_pack_format` 一样无条件给出:程序在打包的第二遍之前选定。未指名程序的 `--pkg-format ` 打包该程序;命令行指名的程序优先;所请求格式的提供者陈述了不同的程序时拒绝并列出各项; @@ -526,3 +529,4 @@ openkal 目标的单文件:载体携带一条腿的映像本身(映像不引用 | 2.6 | 2026-11-17 | mcpp 2026.11.17.1(设计 2026-11-16 §4.3):新增 §4.5.1 许可证文件,全部打包方式按包放置并报告缺失,取代只在 `self-contained` 中按固定文件名查找且不报告的做法。 | | 2.5 | 2026-11-16 | mcpp 2026.11.16.1(设计 2026-11-15 N11、N20):§4.3 携带运行器的包不回落到 `PATH`,本机没有时以 126 退出并写出所含各项;`` 取系统表的 `uname`;`--all-programs` 的树中每个程序有自己的启动器;§6 `mcpp::pack_program` 与提供者不提交的原因(N30)。 | | 2.7 | 2026-11-23 | mcpp 2026.11.23.1(mcpp#1011):§1.2 部署的对象是闭包的根,其需求按程序的规则解析与携带。 | +| 2.8 | 2026-11-24 | mcpp 2026.11.24.1:§6 `-o <目录>/` 写入提供者的产物及其在产物目录下消费的输出。 | diff --git a/docs/zh/30-build-mcpp.md b/docs/zh/30-build-mcpp.md index e639f7e1c..60d14b477 100644 --- a/docs/zh/30-build-mcpp.md +++ b/docs/zh/30-build-mcpp.md @@ -963,6 +963,10 @@ mcpp::pack_program("app"); // 协议 19,mcpp 2026.11.16.1 拒绝消息指名提供者。提供者在第二遍中什么也没有提交时,拒绝消息列出它在这一遍中陈述的警告(`mcpp::warning`、 `mcpp::report`)作为原因。因此提供者以这两者说明为何不提交,而不写标准错误:mcpp 只在程序失败时显示标准错误。 +**`-o <目录>/` 写入产物在其旁读取的文件。** 产物是没有被其他 action 消费的输出。`-o <目录>/` 时产物以其名字写入该 +目录;它消费的输出中位于产物所在目录之下的,按相对产物的位置一并写入(2026.11.24.1)。`web` 的页面因此与其 `.js`、 +`.wasm` 和部署的文件一同到达。每个目标位置被替换,目录中的其他内容不变。 + **`mcpp pack --pkg-format ` 会 prepare 两次。** 一条 `artifact` action 是一条 ninja 边,而那棵暂存树是 mcpp 在链接**之后**产出的,所以这棵树不可能成为构建出它自己 那一次 pass 的输入。第一次 pass 收集声明,并在任何东西被编译之前拒绝未知的格式;随后 diff --git a/src/pack/pipeline.cppm b/src/pack/pipeline.cppm index 91c9355be..35966a54f 100644 --- a/src/pack/pipeline.cppm +++ b/src/pack/pipeline.cppm @@ -1378,6 +1378,32 @@ std::optional stage_member(PackRun& run, GroupJob& g, MemberJob& m) { // One pass serves every member of the group: each member has its own stage, // the programs act for the member they belong to (`BuildOverrides:: // pack_stages`), and one ninja drive builds every member's edges. + +// Copy a provider's distributable `product` into `dir` under its own name, with +// those of `beside` (outputs the product consumed) below the product's own +// directory, at their places relative to it. Each destination is replaced, and +// nothing else in `dir` is touched. Returns why it failed, or nothing. +std::string copy_distributable(const std::filesystem::path& product, + const std::vector& beside, + const std::filesystem::path& dir) { + namespace fs = std::filesystem; + const auto base = product.parent_path().lexically_normal(); + std::vector> copies{{product, dir / product.filename()}}; + for (auto const& b : beside) { + const auto rel = b.lexically_normal().lexically_relative(base); + if (rel.empty() || *rel.begin() == "..") continue; + copies.emplace_back(b, dir / rel); + } + std::error_code ec; + for (auto const& [from, to] : copies) { + fs::remove_all(to, ec); + if (to.has_parent_path()) fs::create_directories(to.parent_path(), ec); + fs::copy(from, to, fs::copy_options::recursive, ec); + if (ec) return std::format("cannot write {}: {}", to.string(), ec.message()); + } + return {}; +} + std::optional dispatch_group(PackRun& run, GroupJob& g, mcpp::build::Backend& be) { // WHICH ARTIFACT ACTIONS THIS BUILD ALREADY HAD, before a format was // requested. The dispatch below reports what the REQUEST introduced, @@ -1637,7 +1663,11 @@ std::optional dispatch_group(PackRun& run, GroupJob& g, mcpp::build::Ba reported.push_back(std::move(abs)); } if (!produced) continue; - // `-o /`: the distributable below it, under its own name. + // `-o /`: the distributable below it, under its own name, + // with the outputs it consumed that lie in its own directory, at their + // places relative to it. A page reads its script and module from beside + // it (dist-web's index.html, web-consumer.js, web-consumer.wasm); copied + // alone it loads nothing (2026.11.23.1 wrote dist/pack/index.html only). if (!run.opts.outputDir.empty()) for (auto& r : reported) { const auto into = std::filesystem::absolute(run.opts.outputDir / r.filename(), ec).lexically_normal(); @@ -1645,10 +1675,8 @@ std::optional dispatch_group(PackRun& run, GroupJob& g, mcpp::build::Ba // written beside the staged tree, in target/dist/): removing // the destination would remove the product. if (into == r.lexically_normal()) continue; - std::filesystem::remove_all(into, ec); - std::filesystem::copy(r, into, std::filesystem::copy_options::recursive, ec); - if (ec) { - mcpp::ui::error(about(run, m, std::format("cannot write {}: {}", into.string(), ec.message()))); + if (auto why = copy_distributable(r, intermediate, into.parent_path()); !why.empty()) { + mcpp::ui::error(about(run, m, why)); m.result.rc = 1; break; } diff --git a/tests/e2e/pack/formats.cpp b/tests/e2e/pack/formats.cpp index 2a2085cd9..122996c1e 100644 --- a/tests/e2e/pack/formats.cpp +++ b/tests/e2e/pack/formats.cpp @@ -2,7 +2,7 @@ // pack, stripping what the graph built, the JSON report and the profile shorthands, a summary // of many outputs, the build a pack states and its job count, the three axes of a package, // the compression a provided format is told (formerly tests/e2e/638, 689, 722, 723, 841, 871, -// 954, 1008). +// 954, 1008), and what `-o /` writes of a provided format's distributable. import std; import mcpplibs.mtest; import mcpp.test.support; @@ -926,6 +926,56 @@ int main() { expect(fatal(failed(r))) << "D: a directory was compressed\n" << s::text(r); expect(e2e::contains(s::text(r), "writes none")) << "D: the refusal\n" << s::text(r); }; + + "1160 a provided format's distributable is written to -o with what it reads beside it"_test[s::pack] = [] { + // A provider's distributable is the output no other action consumes; a page is one, and + // it reads the files it consumed from beside it. `-o /` writes the page with + // those files at their places relative to it, and leaves the directory's other contents + // (2026.11.23.1 wrote the page alone: dist-web's index.html without its .js and .wasm). + const auto tmp = s::case_dir(); + s::project app{tmp / "app", {{"mcpp.toml", R"cpp([package] +name = "app" +version = "0.1.0" +standard = "c++20" + +[targets.app] +kind = "bin" +main = "src/main.cpp" +)cpp"}, {"src/main.cpp", "int main() { return 0; }\n"}, {"build.mcpp", R"cpp(import mcpp; +#include +#include +int main() { + mcpp::provides_pack_format("site"); + if (std::string_view(mcpp::pack_format()) != "site") return 0; + const std::string dir = std::string(mcpp::out_dir()) + "/site"; + const std::string data = dir + "/assets/data.txt", page = dir + "/page.txt"; + mcpp::action d; + d.id = "data"; + d.role = "artifact"; + d.description = "data"; + d.arg("/bin/sh").arg("-c").arg(("mkdir -p " + dir + "/assets && printf data > " + data).c_str()) + .input("${mcpp.target_file:app}") + .output(data.c_str()) + .submit(); + mcpp::action p; + p.id = "page"; + p.role = "artifact"; + p.description = "page"; + p.arg("/bin/sh").arg("-c").arg(("printf page > " + page).c_str()) + .input(data.c_str()) + .output(page.c_str()) + .submit(); + return 0; +} +)cpp"}}}; + app.write("dist/other/keep.txt", "keep"); + auto r = app.mcpp({"pack", "--pkg-format", "site", "-o", "dist/site/"}); + expect(fatal(e2e::succeeded(r))) << "pack failed\n" << s::text(r); + expect(fatal(s::read_file(app.at("dist/site/page.txt")) == "page")) << "the page\n" << s::text(r); + expect(fatal(s::read_file(app.at("dist/site/assets/data.txt")) == "data")) + << "the file the page reads beside it was not written\n" << s::text(r); + expect(fatal(s::read_file(app.at("dist/other/keep.txt")) == "keep")) << "another directory's file was touched"; + }; }}; } // namespace From acc00d6a97e58041fd15c23bcb95723fcf68acb0 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 24 Nov 2026 11:59:32 +0900 Subject: [PATCH 2/3] 2026.11.24.1: the version --- mcpp.toml | 2 +- modules/versioning/src/version.cppm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mcpp.toml b/mcpp.toml index c5453e4dc..458d90296 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,6 +1,6 @@ [package] name = "mcpp" -version = "2026.11.23.1" +version = "2026.11.24.1" description = "Modern C++ build & package management tool" license = "Apache-2.0" authors = ["mcpp-community"] diff --git a/modules/versioning/src/version.cppm b/modules/versioning/src/version.cppm index e81e4c3bd..c8a0973fd 100644 --- a/modules/versioning/src/version.cppm +++ b/modules/versioning/src/version.cppm @@ -31,6 +31,6 @@ import std; export namespace mcpp { -inline constexpr std::string_view MCPP_VERSION = "2026.11.23.1"; +inline constexpr std::string_view MCPP_VERSION = "2026.11.24.1"; } // namespace mcpp From fd0a1b17a266e41816a91e97f34171d08b2e6fbe Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 24 Nov 2026 13:11:11 +0900 Subject: [PATCH 3/3] fix: copy_distributable stands before the dispatch pass's section comment, which introduces dispatch_group --- src/pack/pipeline.cppm | 45 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/pack/pipeline.cppm b/src/pack/pipeline.cppm index 35966a54f..2192c1fd7 100644 --- a/src/pack/pipeline.cppm +++ b/src/pack/pipeline.cppm @@ -1356,29 +1356,6 @@ std::optional stage_member(PackRun& run, GroupJob& g, MemberJob& m) { return std::nullopt; } -// ─── The dispatch pass ─────────────────────────────────────────────── -// -// A `role = "artifact"` action is a ninja edge, and the staged tree is -// produced here, in C++, AFTER ninja has finished. So an artifact action -// cannot depend on the staged tree in the pass that built it, and a -// single-pass `--format ` is not expressible. Two passes are, and -// every value this one needs was answered by the first: -// -// `ov` the overrides that produced the build above -// `plan->stagingRoot` from make_plan, which resolved the triple -// `opts.formatName` the request, already checked against the graph -// -// NOTHING IS RE-DERIVED, and that is the whole discipline of this block. -// `stagingRoot` is a function of the package name, the version, the resolved -// triple and the mode; the resolved triple is not known until a prepare has -// run, so computing it a second time before prepare -- from the host triple, -// say -- is the shape where two derivations of one value agree on every -// machine the author has and disagree on one they do not. -// -// One pass serves every member of the group: each member has its own stage, -// the programs act for the member they belong to (`BuildOverrides:: -// pack_stages`), and one ninja drive builds every member's edges. - // Copy a provider's distributable `product` into `dir` under its own name, with // those of `beside` (outputs the product consumed) below the product's own // directory, at their places relative to it. Each destination is replaced, and @@ -1404,6 +1381,28 @@ std::string copy_distributable(const std::filesystem::path& product, return {}; } +// ─── The dispatch pass ─────────────────────────────────────────────── +// +// A `role = "artifact"` action is a ninja edge, and the staged tree is +// produced here, in C++, AFTER ninja has finished. So an artifact action +// cannot depend on the staged tree in the pass that built it, and a +// single-pass `--format ` is not expressible. Two passes are, and +// every value this one needs was answered by the first: +// +// `ov` the overrides that produced the build above +// `plan->stagingRoot` from make_plan, which resolved the triple +// `opts.formatName` the request, already checked against the graph +// +// NOTHING IS RE-DERIVED, and that is the whole discipline of this block. +// `stagingRoot` is a function of the package name, the version, the resolved +// triple and the mode; the resolved triple is not known until a prepare has +// run, so computing it a second time before prepare -- from the host triple, +// say -- is the shape where two derivations of one value agree on every +// machine the author has and disagree on one they do not. +// +// One pass serves every member of the group: each member has its own stage, +// the programs act for the member they belong to (`BuildOverrides:: +// pack_stages`), and one ninja drive builds every member's edges. std::optional dispatch_group(PackRun& run, GroupJob& g, mcpp::build::Backend& be) { // WHICH ARTIFACT ACTIONS THIS BUILD ALREADY HAD, before a format was // requested. The dispatch below reports what the REQUEST introduced,