Skip to content

Commit 5032751

Browse files
authored
2026.11.24.1: -o <directory>/ writes a provided format's distributable with the outputs it reads beside it (#1012)
1 parent c6e2f00 commit 5032751

8 files changed

Lines changed: 115 additions & 12 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
> Each `## [<version>]` section is that release's notes. Entries are written in English
55
> from 2026.9.28.3 on; earlier entries remain as written.
66

7+
## [2026.11.24.1] - 2026-11-24
8+
9+
### Fixed
10+
11+
- `mcpp pack --pkg-format <provided format> -o <directory>/` writes the distributable together
12+
with the outputs it consumed that lie below its own directory, at their places relative to it.
13+
Before, it wrote the distributable alone, so a web page (`--pkg-format web`) arrived without its
14+
`.js`, its `.wasm` and its deployed files and loaded nothing. Each destination is replaced, and
15+
nothing else in the directory is touched (SPEC-014 §6, v2.8).
16+
717
## [2026.11.23.1] - 2026-11-23
818

919
### Added

‎docs/30-build-mcpp.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,14 @@ second pass, the refusal lists the warnings it stated there (`mcpp::warning`,
11421142
`mcpp::report`) as its reasons, so a provider explains a decline with either and
11431143
not with its standard error, which mcpp shows only for a program that fails.
11441144
1145+
**`-o <directory>/` writes what the distributable reads beside it.** The
1146+
distributable is the output no other action consumes. With `-o <directory>/`, it
1147+
is written into that directory under its own name. The outputs it consumed that
1148+
lie below its own directory are written with it, at their places relative to it
1149+
(2026.11.24.1). For `web`, the page arrives with its `.js`, its `.wasm` and the
1150+
deployed files. Each destination is replaced, and nothing else in the directory
1151+
is touched.
1152+
11451153
**`mcpp pack --pkg-format <name>` prepares twice.** An `artifact` action is a ninja
11461154
edge and the staged tree is produced by mcpp *after* the link, so the tree
11471155
cannot be an input of the pass that built it. The first pass collects the

‎docs/specs/packaging.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
|---|---|
55
| 规范编号 | SPEC-014 |
66
| 标题 | 打包与分发:链接、闭包、容器三个维度与构建腿,腿的合并,暂存树与包元数据,运行覆盖、单文件、容器列表、签名、压缩、合并与分发描述 |
7-
| 状态 | 评审中 v2.7 |
8-
| 版本 | 2.7 |
9-
| 最后修改 | 2026-11-23 |
10-
| 对应实现 | 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 |
7+
| 状态 | 评审中 v2.8 |
8+
| 版本 | 2.8 |
9+
| 最后修改 | 2026-11-24 |
10+
| 对应实现 | 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 |
1111
| 相关设计文档 | `.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) |
1212
| 相关 issue | mcpp#847、mcpp#849、mcpp#860 |
1313
| 相关规范 | [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 目标的单文件:载体携带一条腿的映像本身(映像不引用
422422
(`mcpp::pack_stage_dir()`、`${mcpp.stage_dir}`)、其中的 `mcpp-package.json`、`MCPP_PACK_*` 环境;它报告的终端
423423
输出即产物。未知的名字被拒绝,消息列出图中可用的格式。
424424

425+
`-o <目录>/` 时,产物以其名字写入该目录,它消费的同一提供者的输出中位于产物所在目录之下的,按相对产物的位置一并写入
426+
(v2.8):产物在运行时从其旁读取的文件(网页的脚本与模块)随它交付。每个目标位置被替换,该目录中的其他内容不变。
427+
425428
提供者**可以**以 `mcpp::pack_program("<program>")` 陈述它从被打包的包的哪个程序组装产物(构建程序协议 19,
426429
2026.11.16.1)。陈述与 `provides_pack_format` 一样无条件给出:程序在打包的第二遍之前选定。未指名程序的
427430
`--pkg-format <name>` 打包该程序;命令行指名的程序优先;所请求格式的提供者陈述了不同的程序时拒绝并列出各项;
@@ -526,3 +529,4 @@ openkal 目标的单文件:载体携带一条腿的映像本身(映像不引用
526529
| 2.6 | 2026-11-17 | mcpp 2026.11.17.1(设计 2026-11-16 §4.3):新增 §4.5.1 许可证文件,全部打包方式按包放置并报告缺失,取代只在 `self-contained` 中按固定文件名查找且不报告的做法。 |
527530
| 2.5 | 2026-11-16 | mcpp 2026.11.16.1(设计 2026-11-15 N11、N20):§4.3 携带运行器的包不回落到 `PATH`,本机没有时以 126 退出并写出所含各项;`<os>` 取系统表的 `uname`;`--all-programs` 的树中每个程序有自己的启动器;§6 `mcpp::pack_program` 与提供者不提交的原因(N30)。 |
528531
| 2.7 | 2026-11-23 | mcpp 2026.11.23.1(mcpp#1011):§1.2 部署的对象是闭包的根,其需求按程序的规则解析与携带。 |
532+
| 2.8 | 2026-11-24 | mcpp 2026.11.24.1:§6 `-o <目录>/` 写入提供者的产物及其在产物目录下消费的输出。 |

‎docs/zh/30-build-mcpp.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,10 @@ mcpp::pack_program("app"); // 协议 19,mcpp 2026.11.16.1
963963
拒绝消息指名提供者。提供者在第二遍中什么也没有提交时,拒绝消息列出它在这一遍中陈述的警告(`mcpp::warning`、
964964
`mcpp::report`)作为原因。因此提供者以这两者说明为何不提交,而不写标准错误:mcpp 只在程序失败时显示标准错误。
965965
966+
**`-o <目录>/` 写入产物在其旁读取的文件。** 产物是没有被其他 action 消费的输出。`-o <目录>/` 时产物以其名字写入该
967+
目录;它消费的输出中位于产物所在目录之下的,按相对产物的位置一并写入(2026.11.24.1)。`web` 的页面因此与其 `.js`、
968+
`.wasm` 和部署的文件一同到达。每个目标位置被替换,目录中的其他内容不变。
969+
966970
**`mcpp pack --pkg-format <name>` 会 prepare 两次。** 一条 `artifact` action 是一条
967971
ninja 边,而那棵暂存树是 mcpp 在链接**之后**产出的,所以这棵树不可能成为构建出它自己
968972
那一次 pass 的输入。第一次 pass 收集声明,并在任何东西被编译之前拒绝未知的格式;随后

‎mcpp.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mcpp"
3-
version = "2026.11.23.1"
3+
version = "2026.11.24.1"
44
description = "Modern C++ build & package management tool"
55
license = "Apache-2.0"
66
authors = ["mcpp-community"]

‎modules/versioning/src/version.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ import std;
3131

3232
export namespace mcpp {
3333

34-
inline constexpr std::string_view MCPP_VERSION = "2026.11.23.1";
34+
inline constexpr std::string_view MCPP_VERSION = "2026.11.24.1";
3535

3636
} // namespace mcpp

‎src/pack/pipeline.cppm‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,31 @@ std::optional<Refusal> stage_member(PackRun& run, GroupJob& g, MemberJob& m) {
13561356
return std::nullopt;
13571357
}
13581358

1359+
// Copy a provider's distributable `product` into `dir` under its own name, with
1360+
// those of `beside` (outputs the product consumed) below the product's own
1361+
// directory, at their places relative to it. Each destination is replaced, and
1362+
// nothing else in `dir` is touched. Returns why it failed, or nothing.
1363+
std::string copy_distributable(const std::filesystem::path& product,
1364+
const std::vector<std::filesystem::path>& beside,
1365+
const std::filesystem::path& dir) {
1366+
namespace fs = std::filesystem;
1367+
const auto base = product.parent_path().lexically_normal();
1368+
std::vector<std::pair<fs::path, fs::path>> copies{{product, dir / product.filename()}};
1369+
for (auto const& b : beside) {
1370+
const auto rel = b.lexically_normal().lexically_relative(base);
1371+
if (rel.empty() || *rel.begin() == "..") continue;
1372+
copies.emplace_back(b, dir / rel);
1373+
}
1374+
std::error_code ec;
1375+
for (auto const& [from, to] : copies) {
1376+
fs::remove_all(to, ec);
1377+
if (to.has_parent_path()) fs::create_directories(to.parent_path(), ec);
1378+
fs::copy(from, to, fs::copy_options::recursive, ec);
1379+
if (ec) return std::format("cannot write {}: {}", to.string(), ec.message());
1380+
}
1381+
return {};
1382+
}
1383+
13591384
// ─── The dispatch pass ───────────────────────────────────────────────
13601385
//
13611386
// A `role = "artifact"` action is a ninja edge, and the staged tree is
@@ -1637,18 +1662,20 @@ std::optional<Refusal> dispatch_group(PackRun& run, GroupJob& g, mcpp::build::Ba
16371662
reported.push_back(std::move(abs));
16381663
}
16391664
if (!produced) continue;
1640-
// `-o <directory>/`: the distributable below it, under its own name.
1665+
// `-o <directory>/`: the distributable below it, under its own name,
1666+
// with the outputs it consumed that lie in its own directory, at their
1667+
// places relative to it. A page reads its script and module from beside
1668+
// it (dist-web's index.html, web-consumer.js, web-consumer.wasm); copied
1669+
// alone it loads nothing (2026.11.23.1 wrote dist/pack/index.html only).
16411670
if (!run.opts.outputDir.empty())
16421671
for (auto& r : reported) {
16431672
const auto into = std::filesystem::absolute(run.opts.outputDir / r.filename(), ec).lexically_normal();
16441673
// A provider may have written it there already (the okb is
16451674
// written beside the staged tree, in target/dist/): removing
16461675
// the destination would remove the product.
16471676
if (into == r.lexically_normal()) continue;
1648-
std::filesystem::remove_all(into, ec);
1649-
std::filesystem::copy(r, into, std::filesystem::copy_options::recursive, ec);
1650-
if (ec) {
1651-
mcpp::ui::error(about(run, m, std::format("cannot write {}: {}", into.string(), ec.message())));
1677+
if (auto why = copy_distributable(r, intermediate, into.parent_path()); !why.empty()) {
1678+
mcpp::ui::error(about(run, m, why));
16521679
m.result.rc = 1;
16531680
break;
16541681
}

‎tests/e2e/pack/formats.cpp‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// pack, stripping what the graph built, the JSON report and the profile shorthands, a summary
33
// of many outputs, the build a pack states and its job count, the three axes of a package,
44
// the compression a provided format is told (formerly tests/e2e/638, 689, 722, 723, 841, 871,
5-
// 954, 1008).
5+
// 954, 1008), and what `-o <directory>/` writes of a provided format's distributable.
66
import std;
77
import mcpplibs.mtest;
88
import mcpp.test.support;
@@ -926,6 +926,56 @@ int main() {
926926
expect(fatal(failed(r))) << "D: a directory was compressed\n" << s::text(r);
927927
expect(e2e::contains(s::text(r), "writes none")) << "D: the refusal\n" << s::text(r);
928928
};
929+
930+
"1160 a provided format's distributable is written to -o with what it reads beside it"_test[s::pack] = [] {
931+
// A provider's distributable is the output no other action consumes; a page is one, and
932+
// it reads the files it consumed from beside it. `-o <directory>/` writes the page with
933+
// those files at their places relative to it, and leaves the directory's other contents
934+
// (2026.11.23.1 wrote the page alone: dist-web's index.html without its .js and .wasm).
935+
const auto tmp = s::case_dir();
936+
s::project app{tmp / "app", {{"mcpp.toml", R"cpp([package]
937+
name = "app"
938+
version = "0.1.0"
939+
standard = "c++20"
940+
941+
[targets.app]
942+
kind = "bin"
943+
main = "src/main.cpp"
944+
)cpp"}, {"src/main.cpp", "int main() { return 0; }\n"}, {"build.mcpp", R"cpp(import mcpp;
945+
#include <string>
946+
#include <string_view>
947+
int main() {
948+
mcpp::provides_pack_format("site");
949+
if (std::string_view(mcpp::pack_format()) != "site") return 0;
950+
const std::string dir = std::string(mcpp::out_dir()) + "/site";
951+
const std::string data = dir + "/assets/data.txt", page = dir + "/page.txt";
952+
mcpp::action d;
953+
d.id = "data";
954+
d.role = "artifact";
955+
d.description = "data";
956+
d.arg("/bin/sh").arg("-c").arg(("mkdir -p " + dir + "/assets && printf data > " + data).c_str())
957+
.input("${mcpp.target_file:app}")
958+
.output(data.c_str())
959+
.submit();
960+
mcpp::action p;
961+
p.id = "page";
962+
p.role = "artifact";
963+
p.description = "page";
964+
p.arg("/bin/sh").arg("-c").arg(("printf page > " + page).c_str())
965+
.input(data.c_str())
966+
.output(page.c_str())
967+
.submit();
968+
return 0;
969+
}
970+
)cpp"}}};
971+
app.write("dist/other/keep.txt", "keep");
972+
auto r = app.mcpp({"pack", "--pkg-format", "site", "-o", "dist/site/"});
973+
expect(fatal(e2e::succeeded(r))) << "pack failed\n" << s::text(r);
974+
expect(fatal(s::read_file(app.at("dist/site/page.txt")) == "page")) << "the page\n" << s::text(r);
975+
expect(fatal(s::read_file(app.at("dist/site/assets/data.txt")) == "data"))
976+
<< "the file the page reads beside it was not written\n" << s::text(r);
977+
expect(fatal(s::read_file(app.at("dist/other/keep.txt")) == "keep")) << "another directory's file was touched";
978+
};
929979
}};
930980

931981
} // namespace

0 commit comments

Comments
 (0)