From 48b797d00392730a7fc28898a49f2a54c270c0d3 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Thu, 19 Nov 2026 19:05:06 +0900 Subject: [PATCH 1/4] 0.27.0: tools-steps runs a step program with the collection's own runner The runner of a step program is this package's program `steps` (tools/steps_main.cpp), which the feature tools-steps declares as its tool (`tools = ["steps"]`): the engine builds it once for the machine that builds and gives its path to every build program that links mcpp.plugins with the feature active. `command` writes the program as a step file of counted values (`mcpp::plugins::steps` in the lib root, shared by the writer and the runner) and returns `{runner, file}`, both declared as inputs. The cmake -P backend, `runner_spec` and the `options::cmake` of dist-apk and dist-apple are removed. The runner keeps the semantics of 0.25.0 and 0.26.0 as CMake 4 implemented them: matches sorted and spelled from the pattern's directory, names matched without case on Windows and macOS, no link entered by a recursive glob, a copied tree keeping links, times and permissions, and read-only entries removed and replaced. A value that holds `;` stays one value, and a list is empty only when it holds no value. tests/steps-consumer runs every operation under a root whose name holds a space, a semicolon and non-ASCII text, over a link to a directory and read-only entries, and checks `require` on an empty list, a failing program, and that an unchanged step does not run again. --- .github/scripts/check-toolchain-lanes.sh | 1 + .github/workflows/ci.yml | 21 + dist/apk.cppm | 24 +- dist/apple.cppm | 25 +- mcpp.toml | 32 +- src/plugins.cppm | 218 +++++++ tests/all-rules-compile/build.mcpp | 54 +- .../check-apple-plan.sh | 76 ++- tests/steps-consumer/build.mcpp | 117 ++++ tests/steps-consumer/check-steps.sh | 57 ++ tests/steps-consumer/mcpp.toml | 29 + tests/steps-consumer/probe/mcpp.toml | 23 + tests/steps-consumer/probe/src/main.cpp | 160 +++++ tests/steps-consumer/src/main.cpp | 8 + tools/steps.cppm | 243 ++----- tools/steps_main.cpp | 608 ++++++++++++++++++ 16 files changed, 1423 insertions(+), 273 deletions(-) create mode 100644 tests/steps-consumer/build.mcpp create mode 100755 tests/steps-consumer/check-steps.sh create mode 100644 tests/steps-consumer/mcpp.toml create mode 100644 tests/steps-consumer/probe/mcpp.toml create mode 100644 tests/steps-consumer/probe/src/main.cpp create mode 100644 tests/steps-consumer/src/main.cpp create mode 100644 tools/steps_main.cpp diff --git a/.github/scripts/check-toolchain-lanes.sh b/.github/scripts/check-toolchain-lanes.sh index ab6b6fc..7883700 100755 --- a/.github/scripts/check-toolchain-lanes.sh +++ b/.github/scripts/check-toolchain-lanes.sh @@ -47,6 +47,7 @@ llvm_full=( "island-interface|^all ok" "archive-consumer|^archive-consumer: 'greetings from the archive'" "spirv-module-consumer|^all ok" + "steps-consumer|^steps-consumer ok" ) llvm_configure_only=(qt-consumer qt-widgets-consumer qt-sdk-consumer qt-import-only) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e98e573..2a81678 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1197,6 +1197,18 @@ jobs: done echo "ok: N inputs, one header, one table" + # tools-steps (0.27.0): every operation of a step program, run by the + # collection's own runner `steps`, which the feature carries to the build + # program, under a root whose name holds a space, a semicolon and a + # non-ASCII character, over a link to a directory and read-only entries; + # `require` on an empty list and a program that exits 3, each failing the + # step by name; and an unchanged step not run again. + # The fixture declares no `xim:cmake`, so nothing but the runner can run + # the steps. + - name: tools-steps runs every operation with the collection's own runner + working-directory: tests/steps-consumer + run: MCPP="$MCPP" bash check-steps.sh + # ── dist: what comes out of the LINK ──────────────────────────────── # # Every step above asserts what reaches a COMPILE. These assert what @@ -2246,6 +2258,15 @@ jobs: fi echo "ok: the boundary is generated and namespaced on this host" + # The step programs on this host (0.27.0), with the Linux job's criteria: + # the runner starts each program with no shell, so its arguments arrive + # as the member wrote them on Windows too, and its names reach the file + # system in UTF-8. + - name: tools-steps runs every operation with the collection's own runner on this host + if: ${{ !cancelled() }} + working-directory: tests/steps-consumer + run: MCPP="$MCPP" bash check-steps.sh + # ── dist, on the platform each member serves ──────────────────────── # # A PLAN-LEVEL ASSERTION IS NOT A MEASUREMENT. `plan_for()` returning diff --git a/dist/apk.cppm b/dist/apk.cppm index 5d9f785..ca020e8 100644 --- a/dist/apk.cppm +++ b/dist/apk.cppm @@ -205,10 +205,6 @@ struct options { // `platform` is a root carrying `android.jar`; `keystore_package` above // stays the way a keystore package is named. mcpp::plugins::tool::choice build_tools, platform, jdk, bundletool_dir, kotlin, coursier; - // The runner of the steps of more than one command (0.25.0, - // `mcpp.tools.steps`; `cmake` until mcpp#955): the `xim:cmake` payload, - // asked for when a package is planned, or a program named here. - mcpp::plugins::tool::choice cmake; std::string keystore_alias; // The NAME of an environment variable `apksigner` itself reads // (`--ks-pass env:`) -- this member never reads the secret; only @@ -2271,21 +2267,13 @@ inline plan plan_for(options opt = {}) { // runs; the linked archive gains the native libraries, the assets and every // `classes*.dex` d8 wrote; an App Bundle's base module is the linked archive // laid out as bundletool reads it. Each is a step program - // (`mcpp.tools.steps`): this member describes it, and its runner runs it, - // so no step needs a shell on any host and the runner and the written - // program are inputs of the step. + // (`mcpp.tools.steps`): this member describes it, and the runner `steps`, + // this package's program, runs it (0.27.0), so no step needs a shell on any + // host and the runner and the written program are inputs of the step. namespace steps = mcpp::tools::steps; - // Resolved here, once the project's own inputs have been checked, so a - // refusal about them is not hidden behind a tool that is still to come. - const auto runnerSpec = steps::runner_spec("mcpp.dist.apk"); - const auto runnerTool = mcpp::plugins::tool::resolve(runnerSpec, opt.cmake); - if (runnerTool.pending()) return refuse(p, "cmake requested", {}); - if (!runnerTool) { - return refuse(p, "cmake not found", - mcpp::plugins::tool::describe_missing(runnerSpec, runnerTool) - + "\n So this plan packs nothing."); - } - const std::string runner = runnerTool.program; + const std::string runner = steps::runner(); + if (runner.empty()) + return refuse(p, "no step runner", steps::missing_runner("mcpp.dist.apk") + "\n So this plan packs nothing."); const auto attach = [&](step& s, std::string_view name, const steps::program& program) { const auto how = steps::command(runner, outDir / "steps" / std::string(name), "mcpp.dist.apk", program); s.argv = how.argv; diff --git a/dist/apple.cppm b/dist/apple.cppm index e2a9d75..08e7224 100644 --- a/dist/apple.cppm +++ b/dist/apple.cppm @@ -192,7 +192,6 @@ export module mcpp.dist.apple; import std; import mcpp; import mcpp.plugins; -import mcpp.plugins.tool; import mcpp.tools.steps; // Nothing here uses `std::println`, and that is not a style choice: both of @@ -337,12 +336,6 @@ struct options { std::string volume_name; std::string dmg; - // The runner of the steps of more than one command (0.25.0, - // `mcpp.tools.steps`; `cmake` until mcpp#955): the `xim:cmake` payload, - // asked for only when a plan copies a framework or stages a disk image, - // or a program named here. - mcpp::plugins::tool::choice cmake; - std::string out_dir = std::string(mcpp::out_dir()); }; @@ -1307,21 +1300,15 @@ inline plan plan_for(options opt = {}) { } } - // `cmake` runs the steps of more than one command (0.25.0): a framework's - // copy and signature, and a disk image's staging. Asked for only when the - // plan has one. + // The runner `steps`, this package's program (0.27.0), runs the steps of + // more than one command: a framework's copy and signature, and a disk + // image's staging. Asked for only when the plan has one. namespace steps = mcpp::tools::steps; std::string runner; if (!frameworks.empty() || dmg) { - const auto runnerSpec = steps::runner_spec("mcpp.dist.apple"); - const auto runnerTool = mcpp::plugins::tool::resolve(runnerSpec, opt.cmake); - if (runnerTool.pending()) { p.reason = "cmake requested"; return p; } - if (!runnerTool) { - return refuse(p, "cmake not found", - mcpp::plugins::tool::describe_missing(runnerSpec, runnerTool) - + "\n So this plan bundles nothing."); - } - runner = runnerTool.program; + runner = steps::runner(); + if (runner.empty()) + return refuse(p, "no step runner", steps::missing_runner("mcpp.dist.apple") + "\n So this plan bundles nothing."); } // THE FRAMEWORKS: each copied from the staged tree and, when the bundle is diff --git a/mcpp.toml b/mcpp.toml index ebe6f53..a5b9464 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -363,12 +363,31 @@ sources = ["tools/island.cppm"] implies = ["plugins-core"] # An action whose work is more than one command (0.25.0): the member describes -# the step and a backend runs it, `cmake -P` until the engine runs step -# programs itself (mcpp-community/mcpp#955). `dist-apk` and `dist-apple` imply -# it; each declares the runner, `xim:cmake`, on its own table, on request. +# the step and a runner runs it. `dist-apk` and `dist-apple` imply it. +# +# THE RUNNER IS THIS PACKAGE'S PROGRAM `steps`, AND THE FEATURE CARRIES IT +# (0.27.0). An edge that activates this feature acts as if it had written +# `tools = ["steps"]`: the program is built once for the machine that builds, +# kept in the tool store, and its path reaches every build program that links +# this library with the feature active, a framework's user included (mcpp +# 2026.11.19.1, SPEC-007 R6.3). Until 0.27.0 the runner was `cmake -P`, and each +# member that ran steps declared `xim:cmake` for it; mcpp-community/mcpp#955 +# asked the engine to run the operations instead, and the engine gave a plugin +# this way to carry its own program. [features.tools-steps] sources = ["tools/steps.cppm"] implies = ["plugins-core"] +tools = ["steps"] + +# The dependency only the runner's own build needs: mcpplibs.os, which starts +# each program with its argument vector and no shell on Linux, macOS and +# Windows. The runner names this feature in `required_features`, and the build +# that makes a target as a tool activates the target's required features, so +# only that build has it and a consumer never names `steps-runner`. +[features.steps-runner] + +[feature-deps.steps-runner] +mcpplibs.os = "0.4.5" # ── The environment each rule needs (mcpp 2026.9.6.6+) ────────────────────── # @@ -750,3 +769,10 @@ kind = "lib" kind = "bin" main = "tools/embed_main.cpp" +# steps -- the runner of a step program (`mcpp.tools.steps`), which +# `[features.tools-steps] tools` brings to a build program; see that feature. +[targets.steps] +kind = "bin" +main = "tools/steps_main.cpp" +required_features = ["steps-runner"] + diff --git a/src/plugins.cppm b/src/plugins.cppm index 68f1b50..83877de 100644 --- a/src/plugins.cppm +++ b/src/plugins.cppm @@ -1643,3 +1643,221 @@ inline bool build_output(const std::filesystem::path& dir) { } } // namespace mcpp::plugins::tree + +// mcpp::plugins::steps -- a step program as the file that carries it from the +// build program that plans the step to the runner that performs it (0.27.0). +// +// SHARED BECAUSE TWO PROGRAMS READ ONE FORMAT. `mcpp.tools.steps` writes the +// file while a build program plans, and `steps` (tools/steps_main.cpp), this +// package's runner, reads it when the action runs. One definition here keeps +// the writer and the reader from drifting, which is why `surface` lives here +// for `mcpp-embed` as well. +// +// EVERY VALUE IS COUNTED, NOT QUOTED. A value is its length in bytes, a colon +// and the bytes, so a path keeps its spaces, semicolons, backslashes, quotes, +// line breaks and non-ASCII text on every host, and no character is escaped on +// one side to be restored on the other. One record per operation, one line +// each unless a value holds a line break, after the line that names the format: +// +// mcpp-steps 1 +// # Written by mcpp.dist.apk through mcpp.tools.steps. Do not edit. +// remove - 16:/out/classes dir 0: 0: 0 +// run - 0: 0: 0: 4 10:/jdk/javac 2:-d 16:/out/classes dir 6:A.java +// +// A record is the operation's name; its flags, `-` for none or `r` (recursive) +// and `e` (if_exists) in that order; the operands `a` and `b`; the list it +// reads or extends; and the count of its values, then each value. A line that +// begins with `#` where a record could begin is a comment. +// +// Loops here index rather than iterate, for the GCC 16.1 defect +// tools/steps.cppm records. +export namespace mcpp::plugins::steps { + +enum class op_kind { + run, touch, mkdir, remove, remove_glob, copy_file, copy_tree, copy_glob, + rename, symlink, glob, append, require, +}; + +// One operation. `values` is the argument vector of `run`, the values of +// `append` and the exclusions of `glob`; `a` and `b` are an operation's +// operands; `list` names the list an operation reads or extends. +struct op { + op_kind kind = op_kind::run; + std::vector values; + std::string a, b, list; + bool recursive = false; + bool if_exists = false; + + bool operator==(const op&) const = default; +}; + +// Each kind's name in a file, which is the member's call that makes it. +inline constexpr std::array kind_names = { + "run", "touch", "mkdir", "remove", "remove_glob", "copy_file", "copy_tree", + "copy_glob", "rename", "symlink", "glob", "append", "require", +}; + +inline std::string_view name_of(op_kind k) { return kind_names[static_cast(k)]; } + +// A list is named by letters, digits and `_`. +inline bool valid_list_name(std::string_view name) { + if (name.empty()) return false; + for (std::size_t i = 0; i < name.size(); ++i) { + const unsigned char c = static_cast(name[i]); + if (!std::isalnum(c) && c != '_') return false; + } + return true; +} + +// The first line of every step file: the format and its version. +inline constexpr std::string_view format_line = "mcpp-steps 1"; + +namespace detail { + +inline void put(std::string& out, std::string_view value) { + out += std::to_string(value.size()); + out += ':'; + out += value; +} + +// What is wrong with an operation's list, or nothing. `glob`, `append` and +// `require` name the list they extend or read; `run` may name one to read. +inline std::string list_problem(const op& o) { + const bool needs = o.kind == op_kind::glob || o.kind == op_kind::append || o.kind == op_kind::require; + if (o.list.empty() ? !needs : valid_list_name(o.list)) return {}; + return std::format("list name '{}' of {} is not letters, digits and _", o.list, name_of(o.kind)); +} + +// A cursor over a file's text: each call reads one token and leaves the +// cursor after it, or answers nothing and leaves `at` where the token failed. +struct cursor { + std::string_view text; + std::size_t at = 0; + + bool eat(char c) { + if (at >= text.size() || text[at] != c) return false; + ++at; + return true; + } + std::string_view word() { + const std::size_t from = at; + while (at < text.size() && text[at] != ' ' && text[at] != '\n') ++at; + return text.substr(from, at - from); + } + std::optional count() { + const std::size_t from = at; + std::size_t n = 0; + while (at < text.size() && text[at] >= '0' && text[at] <= '9') { + const auto digit = static_cast(text[at] - '0'); + if (n > (std::numeric_limits::max() - digit) / 10) return std::nullopt; + n = n * 10 + digit; + ++at; + } + if (at == from) return std::nullopt; + return n; + } + std::optional value() { + const auto n = count(); + if (!n || !eat(':') || *n > text.size() - at) return std::nullopt; + std::string v(text.substr(at, *n)); + at += *n; + return v; + } +}; + +} // namespace detail + +// The text of a step file; `comment` says what wrote it, on the second line. A +// list name outside letters, digits and `_` is the member's mistake and is +// refused here, while its build program plans, rather than written for the +// runner to refuse when the action runs. +inline std::string write(const std::vector& ops, std::string_view comment) { + std::string out(format_line); + out += "\n# "; + for (std::size_t i = 0; i < comment.size(); ++i) + out += (comment[i] == '\n' || comment[i] == '\r') ? ' ' : comment[i]; + out += '\n'; + for (std::size_t i = 0; i < ops.size(); ++i) { + const op& o = ops[i]; + if (const std::string problem = detail::list_problem(o); !problem.empty()) + throw std::invalid_argument("mcpp.tools.steps: " + problem); + out += name_of(o.kind); + out += ' '; + if (!o.recursive && !o.if_exists) out += '-'; + if (o.recursive) out += 'r'; + if (o.if_exists) out += 'e'; + out += ' '; + detail::put(out, o.a); + out += ' '; + detail::put(out, o.b); + out += ' '; + detail::put(out, o.list); + out += ' '; + out += std::to_string(o.values.size()); + for (std::size_t k = 0; k < o.values.size(); ++k) { + out += ' '; + detail::put(out, o.values[k]); + } + out += '\n'; + } + return out; +} + +// The operations a step file holds, or what makes it unreadable, naming the +// operation and the byte where reading stopped. +inline std::expected, std::string> read(std::string_view text) { + detail::cursor in{ text }; + if (in.word() != "mcpp-steps" || !in.eat(' ')) + return std::unexpected(std::string("not a step file: it does not begin with 'mcpp-steps'")); + if (const std::string_view version = in.word(); version != "1") + return std::unexpected(std::format( + "a step file of format '{}', and this runner reads format 1", version)); + if (!in.eat('\n')) + return std::unexpected(std::string("the line 'mcpp-steps 1' does not end")); + std::vector ops; + while (in.at < text.size()) { + if (text[in.at] == '#') { + const std::size_t end = text.find('\n', in.at); + in.at = end == std::string_view::npos ? text.size() : end + 1; + continue; + } + const auto bad = [&](std::string_view what) { + return std::unexpected(std::format("operation {} (byte {}): {}", ops.size() + 1, in.at, what)); + }; + op o; + const std::string_view kind = in.word(); + std::size_t k = 0; + while (k < kind_names.size() && kind_names[k] != kind) ++k; + if (k == kind_names.size()) return bad(std::format("'{}' is not an operation", kind)); + o.kind = static_cast(k); + if (!in.eat(' ')) return bad("the flags are missing"); + const std::string_view flags = in.word(); + if (flags != "-") { + std::size_t f = 0; + if (f < flags.size() && flags[f] == 'r') { o.recursive = true; ++f; } + if (f < flags.size() && flags[f] == 'e') { o.if_exists = true; ++f; } + if (f == 0 || f != flags.size()) return bad(std::format("'{}' are not flags", flags)); + } + std::optional a, b, list; + if (!in.eat(' ') || !(a = in.value()) || !in.eat(' ') || !(b = in.value()) + || !in.eat(' ') || !(list = in.value()) || !in.eat(' ')) + return bad("an operand is not a counted value"); + o.a = std::move(*a); + o.b = std::move(*b); + o.list = std::move(*list); + const auto n = in.count(); + if (!n) return bad("the count of values is missing"); + for (std::size_t v = 0; v < *n; ++v) { + std::optional value; + if (!in.eat(' ') || !(value = in.value())) + return bad(std::format("value {} of {} is not a counted value", v + 1, *n)); + o.values.push_back(std::move(*value)); + } + if (!in.eat('\n')) return bad("the operation does not end its line"); + if (const std::string problem = detail::list_problem(o); !problem.empty()) return bad(problem); + ops.push_back(std::move(o)); + } + return ops; +} + +} // namespace mcpp::plugins::steps diff --git a/tests/all-rules-compile/build.mcpp b/tests/all-rules-compile/build.mcpp index bebcc60..df34299 100644 --- a/tests/all-rules-compile/build.mcpp +++ b/tests/all-rules-compile/build.mcpp @@ -5,6 +5,7 @@ // someone's project. import std; import mcpp; +import mcpp.plugins; import mcpp.rules.ascendc; import mcpp.rules.cuda; import mcpp.rules.hip; @@ -59,32 +60,41 @@ int main() { // Same question of the island generator: the one call that writes // nothing. `entry_name` is where its only parsing lives. ok = ok && mcpp::tools::island::entry_name("int f(int a)") == "f"; - // And of the step programs: what the backend renders, which writes - // nothing itself. A value keeps its space and semicolon, and a list built - // when the step runs follows the command's own arguments. + // And of the step programs (0.27.0): the file `command` writes, which + // writes nothing itself here, read back as the runner reads it. Every value + // is counted, so a space, a semicolon, a backslash, a quote, a line break + // and non-ASCII text survive; so do the flags, the operands, the list a + // command reads and an exclusion; and the text is the format + // docs/tools-steps.md states. { + namespace st = mcpp::plugins::steps; mcpp::tools::steps::program s; - s.glob("found", "d/*.class", { .recursive = true }) - .run({"a b", "c;d"}, { .working_directory = "w", .append_list = "found" }); - ok = ok && mcpp::tools::steps::cmake_backend::render(s) - == "set(mcpp_steps_found)\n" - "file(GLOB_RECURSE mcpp_steps_matched LIST_DIRECTORIES false [==[d/*.class]==])\n" - "list(APPEND mcpp_steps_found ${mcpp_steps_matched})\n" - "execute_process(COMMAND [==[a b]==] [==[c;d]==] ${mcpp_steps_found}\n" - " WORKING_DIRECTORY [==[w]==]\n COMMAND_ERROR_IS_FATAL ANY)\n"; + s.glob("found", "d/*.class", { .recursive = true, .relative_to = "d", .exclude = { "*/x/*" } }) + .run({"a b", "c;d", "e\\f", "\"q\"\n", "\xC3\xBC"}, { .working_directory = "w", .append_list = "found" }) + .copy_tree("from", "to", true) + .require("found", "none found"); + const std::string text = st::write(s.ops(), "a test"); + const auto back = st::read(text); + ok = ok && back && *back == s.ops() + && text == "mcpp-steps 1\n# a test\n" + "glob r 9:d/*.class 1:d 5:found 1 5:*/x/*\n" + "run - 1:w 0: 5:found 5 3:a b 3:c;d 3:e\\f 4:\"q\"\n 2:\xC3\xBC\n" + "copy_tree e 4:from 2:to 0: 0\n" + "require - 10:none found 0: 5:found 0\n"; } - // An exclusion applies to the whole path: `*` crosses a `/`, a character - // a regular expression gives meaning to stands for itself, and `[!...]` - // is a negated set. + // A list named outside letters, digits and `_` is refused while the build + // program plans; a file of another format, or with a value whose count + // does not hold, is refused by the reader. { - mcpp::tools::steps::program s; - s.glob("objects", "obj/*.o", { .recursive = true, .exclude = { "*/platform/ios/App/*", "a.b+[!x]?" } }); - ok = ok && mcpp::tools::steps::cmake_backend::render(s) - == "set(mcpp_steps_objects)\n" - "file(GLOB_RECURSE mcpp_steps_matched LIST_DIRECTORIES false [==[obj/*.o]==])\n" - "list(FILTER mcpp_steps_matched EXCLUDE REGEX [==[^.*/platform/ios/App/.*$]==])\n" - "list(FILTER mcpp_steps_matched EXCLUDE REGEX [==[^a\\.b\\+[^x].$]==])\n" - "list(APPEND mcpp_steps_objects ${mcpp_steps_matched})\n"; + namespace st = mcpp::plugins::steps; + bool refused = false; + try { + (void)st::write(mcpp::tools::steps::program{}.append("a-b", {"x"}).ops(), ""); + } catch (const std::invalid_argument&) { + refused = true; + } + ok = ok && refused && !st::read("mcpp-steps 2\n") && !st::read("mcpp-steps 1\nrun - 3:ab 0: 0: 0\n") + && !st::read("mcpp-steps 1\nexecute - 0: 0: 0: 0\n"); } // `dist-wix`, `dist-apple` and `dist-web` are neither rules nor tools, but the same diff --git a/tests/app-framework-consumer/check-apple-plan.sh b/tests/app-framework-consumer/check-apple-plan.sh index 69877b9..f033296 100755 --- a/tests/app-framework-consumer/check-apple-plan.sh +++ b/tests/app-framework-consumer/check-apple-plan.sh @@ -51,15 +51,15 @@ stage_tree() { } # run_program -# The runner of the step programs (0.25.0, `tools-steps`): a plan names it and -# never runs it, so a file where the payload keeps `cmake` is enough. -RUNNER=$(mktemp -d) -mkdir -p "$RUNNER/bin" && : > "$RUNNER/bin/cmake" && chmod +x "$RUNNER/bin/cmake" +# The runner of the step programs (0.27.0, `steps`), which the engine hands a +# build program through `tools-steps`' tool: a plan names it and never runs it, +# so the path is enough. +RUNNER=/plan-check/tool-store/bin/steps run_program() { local out out=$(mktemp -d) - env -i PATH="$PATH" MCPP_XPKG_XIM_CMAKE_DIR="$RUNNER" \ + env -i PATH="$PATH" MCPP_DEP_MCPP_PLUGINS_BIN_STEPS="$RUNNER" \ MCPP_PACK_FORMAT="$1" MCPP_TARGET_OS="$2" MCPP_TARGET_ENV="$3" \ MCPP_PACK_STAGE_DIR="$4" MCPP_MANIFEST_DIR="$PWD" \ MCPP_PKG_NAME=app-framework-consumer MCPP_PKG_VERSION=0.1.0 \ @@ -83,15 +83,56 @@ def fail(msg): print("--- " + log + " ---") print("\n".join(lines)) sys.exit(1) -# A step of more than one command is ` -P `, with the runner -# and the program among its inputs; this returns the program the step runs. +# A step of more than one command is ` .steps`, with the runner +# and the file among its inputs; this returns the operations the file holds, +# read as the runner reads them (src/plugins.cppm, `mcpp::plugins::steps`): +# after the format line and comments, one record per operation -- its name, its +# flags, the operands a and b, its list, the count of its values and each value, +# every value `:`. def program(a): c = a["command"] - if len(c) != 3 or not c[0].endswith("/bin/cmake") or c[1] != "-P" or not c[2].endswith(".cmake"): + if len(c) != 2 or not c[0].endswith("/steps") or not c[1].endswith(".steps"): fail(a["id"] + " is not a step program run by the runner: " + repr(c)) - if c[0] not in a["inputs"] or c[2] not in a["inputs"]: + if c[0] not in a["inputs"] or c[1] not in a["inputs"]: fail(a["id"] + " does not declare the runner and its program as inputs") - return open(c[2]).read() + data = open(c[1], "rb").read() + if not data.startswith(b"mcpp-steps 1\n"): + fail(c[1] + " is not a step file of format 1") + at = len(b"mcpp-steps 1\n") + def word(): + nonlocal at + end = at + while end < len(data) and data[end:end + 1] not in (b" ", b"\n"): end += 1 + w, at = data[at:end].decode("utf-8"), end + return w + def counted(): + nonlocal at + colon = data.index(b":", at) + n = int(data[at:colon]) + v, at = data[colon + 1:colon + 1 + n].decode("utf-8"), colon + 1 + n + return v + def skip(ch): + nonlocal at + if data[at:at + 1] != ch: fail(c[1] + ": expected " + repr(ch) + " at byte " + str(at)) + at += 1 + ops = [] + while at < len(data): + if data[at:at + 1] == b"#": + at = data.index(b"\n", at) + 1 + continue + o = {"kind": word()} + skip(b" "); o["flags"] = word() + for k in ("a", "b", "list"): + skip(b" "); o[k] = counted() + skip(b" "); n = int(word()) + o["values"] = [] + for _ in range(n): + skip(b" "); o["values"].append(counted()) + skip(b"\n") + ops.append(o) + return ops +def runs(ops): + return [o["values"] for o in ops if o["kind"] == "run"] exec(code) PY } @@ -109,9 +150,11 @@ fw = actions.get("mcpp.dist.apple.framework.libapp-framework-dep.dylib") if not fw: fail("no framework step for the staged dylib") if not fw["outputs"] or not fw["outputs"][0].endswith("/AppFrameworkConsumer.app/Contents/Frameworks/libapp-framework-dep.dylib"): fail("the framework step does not write Contents/Frameworks/libapp-framework-dep.dylib") -fwp = program(fw) -if "ditto" not in fwp or "[==[codesign]==] [==[--force]==] [==[--sign]==] [==[-]==]" not in fwp or "--timestamp" in fwp: - fail("the framework step does not copy and sign ad hoc:\n" + fwp) +fwr = runs(program(fw)) +dest = fw["outputs"][0] +if not any(r[0] == "ditto" and r[-1] == dest for r in fwr) \ + or ["codesign", "--force", "--sign", "-", dest] not in fwr or any("--timestamp" in r for r in fwr): + fail("the framework step does not copy and sign ad hoc: " + repr(fwr)) if any(i.startswith("mcpp.dist.apple.resource.libapp") for i in actions): fail("the staged dylib is also planned as a resource") if "mcpp.dist.apple.resource.data" not in actions: @@ -143,8 +186,9 @@ img = actions.get("mcpp.dist.apple.dmg") if not (bundle and st and img): fail("the disk image steps are not planned") if bundle["outputs"][0] not in st["inputs"]: fail("the image staging does not take the bundle") stp = program(st) -if "ditto" not in stp or "file(CREATE_LINK [==[/Applications]==]" not in stp: - fail("the image staging does not copy the bundle beside an Applications link:\n" + stp) +if not any(r[0] == "ditto" for r in runs(stp)) \ + or not any(o["kind"] == "symlink" and o["a"] == "/Applications" for o in stp): + fail("the image staging does not copy the bundle beside an Applications link: " + repr(stp)) if st["outputs"][0] not in img["inputs"]: fail("hdiutil does not take the staging directory") cmd = img["command"] if cmd[:2] != ["hdiutil", "create"] or "UDZO" not in cmd or not cmd[-1].endswith("/AppFrameworkConsumer.dmg"): @@ -182,7 +226,7 @@ check /tmp/apple-plan-ios.log ' fw = actions.get("mcpp.dist.apple.framework.libapp-framework-dep.dylib") if not fw or not fw["outputs"][0].endswith("/AppFrameworkConsumer.app/Frameworks/libapp-framework-dep.dylib"): fail("the simulator bundle does not carry the dylib in Frameworks/") -if "codesign" in program(fw): fail("the simulator framework is signed") +if any(r[0] == "codesign" for r in runs(program(fw))): fail("the simulator framework is signed") if "mcpp.dist.apple.codesign" in actions: fail("the simulator bundle is signed") if "mcpp:link-flag=-Wl,-rpath,@executable_path/Frameworks" not in lines: fail("no iOS framework rpath was emitted") diff --git a/tests/steps-consumer/build.mcpp b/tests/steps-consumer/build.mcpp new file mode 100644 index 0000000..0fb3a78 --- /dev/null +++ b/tests/steps-consumer/build.mcpp @@ -0,0 +1,117 @@ +// Every operation of `mcpp.tools.steps`, run by the runner `tools-steps` +// carries (0.27.0), on the host that builds. The operations work under a root +// whose name holds a space, a semicolon and a non-ASCII character, over a tree +// with a link to a directory and read-only entries; `steps-probe` sets the +// permissions, records the arguments a step passes and, last, checks what the +// operations left. `STEPS_CONSUMER_CASE` adds a step that must fail: `require` +// on an empty list (`require`), or a program that exits 3 (`status`). +import std; +import mcpp; +import mcpp.tools.steps; + +namespace steps = mcpp::tools::steps; + +namespace { + +// One step, written beside the others. Its output is the file its last +// operation writes, so a step that stopped early leaves the output missing. +void submit(const std::string& runner, const std::string& name, const steps::program& program, + const std::vector& inputs, const std::string& output) { + const auto how = steps::command(runner, std::string(mcpp::out_dir()) + "/steps/" + name, + "steps-consumer", program); + const std::string id = "steps-consumer:" + name; + const std::string description = "STEPS " + name; + mcpp::action a; + a.id = id.c_str(); + a.role = mcpp::roles::artifact; + a.description = description.c_str(); + for (auto const& t : how.argv) a.arg(t.c_str()); + for (auto const& i : how.inputs) a.input(i.c_str()); + for (auto const& i : inputs) a.input(i.c_str()); + a.output(output.c_str()); + a.submit(); +} + +} // namespace + +int main() { + const std::string runner = steps::runner(); + if (runner.empty()) { + std::cerr << steps::missing_runner("steps-consumer") << '\n'; + return 1; + } + const std::string probe = mcpp::dep_bin("steps-probe", "steps-probe"); + if (probe.empty()) { + std::cerr << "steps-consumer: the tool steps-probe is not available to this build program\n"; + return 1; + } + const std::string out = mcpp::out_dir(); + // A space, a semicolon and `ü`, and a value with `ü 漢`, each written as its + // UTF-8 bytes so that the source's encoding cannot alter them. + const std::string root = out + "/steps root; \xC3\xBC"; + const std::string han = "\xC3\xBC \xE6\xBC\xA2"; + + steps::program ops; + ops.remove(root) + .touch(root + "/src/b.txt") + .touch(root + "/src/a.txt") + .touch(root + "/src/c.log") + .touch(root + "/src/sub/d.txt") + .touch(root + "/src/platform/ios/App/e.txt") + .touch(root + "/src/ro/f.txt") + .symlink("sub", root + "/src/linked.txt") + .mkdir(root + "/src/empty") + .mkdir(root + "/doomed/inner") + .touch(root + "/doomed/inner/f.txt") + .run({ probe, "mode", "444", root + "/src/ro/f.txt", root + "/doomed/inner/f.txt" }) + .run({ probe, "mode", "555", root + "/doomed/inner" }) + .run({ probe, "mode", "700", root + "/src/ro" }) + .glob("flat", root + "/src/*.txt") + .glob("deep", root + "/src/*.txt", { .recursive = true, .relative_to = root + "/src", + .exclude = { "platform/*" } }) + .append("deep", { "x y;z", han }) + .glob("picked", root + "/src/[!a]?t[a-z]t") + .glob("cased", root + "/src/A.TXT") + .run({ probe, "args", root + "/args-flat.txt", "a b", "c;d", "e\\f", "g h\\", "\"q\"", "", han }, + { .append_list = "flat" }) + .run({ probe, "args", root + "/args-deep.txt" }, { .append_list = "deep" }) + .run({ probe, "args", root + "/args-picked.txt" }, { .append_list = "picked" }) + .run({ probe, "args", root + "/args-cased.txt" }, { .append_list = "cased" }) + .run({ probe, "cwd", "cwd.txt" }, { .working_directory = root + "/src/sub" }) + .copy_file(root + "/args-flat.txt", root + "/copy/deep/args.txt") + .copy_file(root + "/src/ro/f.txt", root + "/copy/ro.txt") + .copy_file(root + "/args-flat.txt", root + "/copy/ro.txt") + .copy_tree(root + "/src", root + "/tree") + .copy_tree(root + "/src", root + "/tree") + .copy_tree(root + "/absent", root + "/tree2", true) + .copy_tree(root + "/src/sub", root + "/tree3", true) + .copy_glob(root + "/src/*.txt", root + "/globbed") + .rename(root + "/globbed/a.txt", root + "/globbed/renamed.txt") + .symlink("src", root + "/link") + .remove_glob(root + "/tree/*.txt") + .remove(root + "/doomed") + .remove(root + "/never-was") + .require("flat", "steps-consumer: the glob of src/*.txt found nothing") + .run({ probe, "verify", root, out + "/steps-verified.txt", out + "/steps-runs.txt" }); + submit(runner, "operations", ops, { probe }, out + "/steps-verified.txt"); + + mcpp::rerun_if_env_changed("STEPS_CONSUMER_CASE"); + const char* chosen = std::getenv("STEPS_CONSUMER_CASE"); + const std::string which = chosen ? chosen : ""; + if (which == "require") { + submit(runner, "require", steps::program{} + .glob("none", root + "/src/*.none") + .require("none", "steps-consumer: the list 'none' is empty, as this case intends") + .touch(out + "/steps-require.txt"), + {}, out + "/steps-require.txt"); + } else if (which == "status") { + submit(runner, "status", steps::program{} + .run({ probe, "exit", "3" }) + .touch(out + "/steps-status.txt"), + { probe }, out + "/steps-status.txt"); + } else if (!which.empty()) { + std::cerr << "steps-consumer: STEPS_CONSUMER_CASE names no case: " << which << '\n'; + return 1; + } + return 0; +} diff --git a/tests/steps-consumer/check-steps.sh b/tests/steps-consumer/check-steps.sh new file mode 100755 index 0000000..367ac92 --- /dev/null +++ b/tests/steps-consumer/check-steps.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# tools-steps on this host (0.27.0): a step program run by the runner the +# feature carries, `steps`, with no shell and no `xim:cmake`. +# +# 1. Every operation, under a root whose name holds a space, a semicolon and +# a non-ASCII character, over a link to a directory and read-only entries: +# the build succeeds only when `steps-probe`'s check of the tree holds, +# since only that check writes the step's output. +# 2. An unchanged step program does not run again. +# 3. `require` on an empty list fails the step with the member's message, and +# the operation after it does not run. +# 4. A program that exits 3 fails the step, named with its status, and the +# operation after it does not run. +# 5. The build program running again with another case does not rewrite the +# first step's file, so that step still does not run again. +# +# Usage: MCPP= ./check-steps.sh (run from this directory) +set -e + +MCPP="${MCPP:-mcpp}" +fail() { echo "FAIL: $1"; shift; for f in "$@"; do echo "--- $f ---"; cat "$f" 2>/dev/null; done; exit 1; } +runs() { wc -l < "$out/steps-runs.txt" | tr -d ' '; } + +# A run that failed inside the step can leave its read-only directory behind. +if [ -d target ]; then chmod -R u+w target; fi +rm -rf target +unset STEPS_CONSUMER_CASE +"$MCPP" build > steps-build.log 2>&1 || fail "the operations did not all do what they say" steps-build.log +out=$(sh ../out-dir.sh) +grep -qE '^verified [0-9]+ checks$' "$out/steps-verified.txt" \ + || fail "the step's check wrote no report" "$out/steps-verified.txt" steps-build.log +[ "$(runs)" = 1 ] || fail "the step ran $(runs) times in one build" "$out/steps-runs.txt" +echo "ok: every operation, $(cat "$out/steps-verified.txt")" + +"$MCPP" build > steps-rebuild.log 2>&1 || fail "the second build failed" steps-rebuild.log +[ "$(runs)" = 1 ] || fail "an unchanged step program ran again" steps-rebuild.log +echo "ok: an unchanged step program does not run again" + +STEPS_CONSUMER_CASE=require "$MCPP" build > steps-require.log 2>&1 \ + && fail "require on an empty list did not fail the step" steps-require.log +grep -q "the list 'none' is empty, as this case intends" steps-require.log \ + || fail "the failed require does not print the member's message" steps-require.log +[ ! -e "$out/steps-require.txt" ] || fail "an operation after the failed require ran" +echo "ok: require on an empty list fails the step with its message" + +STEPS_CONSUMER_CASE=status "$MCPP" build > steps-status.log 2>&1 \ + && fail "a program that exits 3 did not fail the step" steps-status.log +grep -q "exited with status 3" steps-status.log \ + || fail "the failed run does not name the status" steps-status.log +[ ! -e "$out/steps-status.txt" ] || fail "an operation after the failed run ran" +echo "ok: a program's non-zero status fails the step, named" + +"$MCPP" build > steps-again.log 2>&1 || fail "the build without a case failed" steps-again.log +[ "$(runs)" = 1 ] || fail "the step ran again after the build program ran with another case" steps-again.log +"$MCPP" run > steps-run.log 2>&1 || fail "the program does not run" steps-run.log +grep -q '^steps-consumer ok' steps-run.log || fail "the program printed nothing" steps-run.log +echo "PASS: tools-steps runs every operation with its own runner on this host" diff --git a/tests/steps-consumer/mcpp.toml b/tests/steps-consumer/mcpp.toml new file mode 100644 index 0000000..ce3faa5 --- /dev/null +++ b/tests/steps-consumer/mcpp.toml @@ -0,0 +1,29 @@ +# Fixture: every operation of `mcpp.tools.steps`, run on the host that builds +# by the runner `tools-steps` carries (0.27.0), and checked by `steps-probe`, a +# program this fixture builds as a tool. The build program is the test: the +# step that checks the operations' tree writes the action's output only when +# every check holds. `check-steps.sh` adds the runs that must fail and the run +# that must not run the step again. +[package] +name = "steps-consumer" +version = "0.1.0" +description = "Fixture: step programs run by the collection's own runner" +license = "Apache-2.0" +authors = ["mcpp-community"] + +[language] +standard = "c++23" +modules = true +import_std = true + +[build-dependencies] +steps-probe = { path = "probe", tools = ["steps-probe"] } + +# Only `tools-steps`: the runner arrives through the feature, and nothing here +# declares `xim:cmake`. +[build-dependencies.mcpp] +plugins = { path = "../..", features = ["tools-steps"], host-module = true } + +[targets.steps-consumer] +kind = "bin" +main = "src/main.cpp" diff --git a/tests/steps-consumer/probe/mcpp.toml b/tests/steps-consumer/probe/mcpp.toml new file mode 100644 index 0000000..a5a06f6 --- /dev/null +++ b/tests/steps-consumer/probe/mcpp.toml @@ -0,0 +1,23 @@ +# The program the step programs of tests/steps-consumer run: it records the +# arguments a step passes, the directory it runs in, exits with a status it is +# given, and checks what the operations left (src/main.cpp). The fixture builds +# it as a tool, so a step names it by its path. +[package] +name = "steps-probe" +version = "0.1.0" +description = "Fixture: the program a step program of tests/steps-consumer runs" +license = "Apache-2.0" +authors = ["mcpp-community"] + +[language] +standard = "c++23" +modules = true +import_std = true + +# Its arguments in UTF-8 on every host, and the names it checks. +[dependencies] +mcpplibs.os = "0.4.5" + +[targets.steps-probe] +kind = "bin" +main = "src/main.cpp" diff --git a/tests/steps-consumer/probe/src/main.cpp b/tests/steps-consumer/probe/src/main.cpp new file mode 100644 index 0000000..fc3f471 --- /dev/null +++ b/tests/steps-consumer/probe/src/main.cpp @@ -0,0 +1,160 @@ +// steps-probe -- the program the step programs of tests/steps-consumer run, and +// the check of what they leave. +// +// steps-probe args ... writes each argument as `:\n` +// steps-probe cwd writes the directory it runs in +// steps-probe exit exits with the status +// steps-probe mode ... sets the permissions of each path +// steps-probe verify checks the tree under ; when +// every check holds, writes +// and appends a line to +// +// Its arguments are read in UTF-8 through mcpplibs.os, so on Windows it records +// what the runner passed rather than the code page's rendering of it. +import std; +import mcpplibs.os; + +namespace { + +namespace os = mcpplibs::os; +namespace fs = std::filesystem; + +fs::path path_of(std::string_view utf8) { return os::fs::from_utf8(utf8); } + +void say(std::string_view text) { (void)os::stdio::write_error(text); } + +std::string counted(const std::vector& values) { + std::string out; + for (auto const& v : values) out += std::format("{}:{}\n", v.size(), v); + return out; +} + +// What build.mcpp passes, stated here again on purpose: an expectation that +// travelled the channel it checks would agree with whatever arrived. `ü 漢` is +// written as its UTF-8 bytes, so the source's encoding cannot alter it. +const std::string han = "\xC3\xBC \xE6\xBC\xA2"; +const std::vector fixed = { "a b", "c;d", "e\\f", "g h\\", "\"q\"", "", han }; + +int verify(const std::string& root, const std::string& report, const std::string& runs) { + int checks = 0; + std::vector failed; + const auto expect = [&](bool holds, std::string what) { + ++checks; + if (!holds) failed.push_back(std::move(what)); + }; + const auto at = [&](std::string_view rel) { return path_of(root + "/" + std::string(rel)); }; + const auto file = [&](std::string_view rel) { std::error_code ec; return fs::is_regular_file(at(rel), ec); }; + const auto dir = [&](std::string_view rel) { std::error_code ec; return fs::is_directory(at(rel), ec); }; + const auto absent = [&](std::string_view rel) { + std::error_code ec; + return !fs::exists(fs::symlink_status(at(rel), ec)); + }; + const auto text = [&](std::string_view rel) { + const auto r = os::fs::read(at(rel)); + return r ? *r : std::string("(unreadable)"); + }; + const auto time = [&](std::string_view rel) { + std::error_code ec; + return fs::last_write_time(at(rel), ec); + }; + const auto mode = [&](std::string_view rel) { + std::error_code ec; + return fs::symlink_status(at(rel), ec).permissions(); + }; + const auto link = [&](std::string_view rel) { + std::error_code ec; + return fs::is_symlink(fs::symlink_status(at(rel), ec)); + }; + + for (const char* rel : { "src/a.txt", "src/b.txt", "src/c.log", "src/sub/d.txt", "src/platform/ios/App/e.txt" }) + expect(file(rel), std::format("touch did not create {}", rel)); + expect(dir("src/empty"), "mkdir did not create src/empty"); + expect(absent("doomed"), "remove left the tree doomed/, whose directory inner/ and file are read-only"); + + // glob (sorted, spelled from the pattern's directory), append, and run + // with a list after its own arguments: every value as it was passed. A + // flat pattern passes over the link src/linked.txt, to a directory; a + // recursive one matches it by its name and does not enter it. + std::vector flat = fixed; + flat.push_back(root + "/src/a.txt"); + flat.push_back(root + "/src/b.txt"); + expect(text("args-flat.txt") == counted(flat), "run did not pass its arguments and the list 'flat' verbatim:\n" + + text("args-flat.txt")); + const std::vector deep = { "a.txt", "b.txt", "linked.txt", "ro/f.txt", "sub/d.txt", "x y;z", han }; + expect(text("args-deep.txt") == counted(deep), "a recursive, relative glob with an exclusion, then append, " + "did not give the list 'deep':\n" + text("args-deep.txt")); + expect(text("args-picked.txt") == counted({ root + "/src/b.txt" }), + "a negated set, `?` and a range did not pick src/b.txt alone:\n" + text("args-picked.txt")); + // A name is matched without case where the host compares names without it, + // and is spelled as the directory holds it. + const std::vector cased = os::conventions().case_insensitive_names + ? std::vector{ root + "/src/a.txt" } : std::vector{}; + expect(text("args-cased.txt") == counted(cased), "A.TXT was not matched as this host compares names:\n" + + text("args-cased.txt")); + { + std::string cwd = text("src/sub/cwd.txt"); + std::error_code ec; + expect(fs::equivalent(path_of(cwd), at("src/sub"), ec), "run did not start in its working_directory: " + cwd); + } + + expect(file("copy/deep/args.txt") && text("copy/deep/args.txt") == text("args-flat.txt"), + "copy_file did not copy args-flat.txt into a directory it made"); + expect(text("copy/ro.txt") == text("args-flat.txt") && mode("copy/ro.txt") == mode("args-flat.txt"), + "copy_file did not replace a read-only file, or did not give it its source's permissions"); + expect(file("tree/c.log") && file("tree/sub/d.txt") && file("tree/platform/ios/App/e.txt") && dir("tree/empty"), + "copy_tree did not copy the contents of src/"); + expect(time("tree/c.log") == time("src/c.log"), "copy_tree did not keep a file's time"); + expect(file("tree/ro/f.txt") && mode("tree/ro/f.txt") == mode("src/ro/f.txt") && mode("tree/ro") == mode("src/ro"), + "copy_tree, twice, did not keep the permissions of src/ro/ and of its read-only file"); + expect(link("tree/linked.txt"), "copy_tree did not keep src/linked.txt as a link, or remove_glob of tree/*.txt " + "removed that link, to a directory, which a flat pattern passes over"); + expect(absent("tree/a.txt") && absent("tree/b.txt") && file("tree/sub/d.txt"), + "remove_glob did not remove tree/*.txt alone"); + expect(absent("tree2"), "copy_tree with if_exists copied a source that is not there"); + expect(file("tree3/d.txt"), "copy_tree with if_exists skipped a source that is there"); + expect(file("globbed/renamed.txt") && file("globbed/b.txt"), "copy_glob and rename did not give globbed/"); + expect(absent("globbed/a.txt") && absent("globbed/c.log") && absent("globbed/d.txt") && absent("globbed/linked.txt"), + "copy_glob copied what its pattern does not match, or rename left its source"); + expect(file("link/a.txt"), "symlink did not make a link to src/"); + + if (!failed.empty()) { + for (auto const& f : failed) say("steps-probe: " + f + "\n"); + return 1; + } + const auto written = os::fs::write(path_of(report), std::format("verified {} checks\n", checks)); + const auto counted_run = os::fs::append(path_of(runs), "run\n"); + if (!written || !counted_run) { + say("steps-probe: cannot write the report\n"); + return 1; + } + return 0; +} + +} // namespace + +int main() { + const auto args = os::env::arguments(); + if (args.size() >= 3 && args[1] == "args") { + const std::vector passed(args.begin() + 3, args.end()); + return os::fs::write(path_of(args[2]), counted(passed)) ? 0 : 1; + } + if (args.size() == 3 && args[1] == "cwd") + return os::fs::write(path_of(args[2]), os::fs::generic_utf8(fs::current_path())) ? 0 : 1; + if (args.size() == 3 && args[1] == "exit") return std::atoi(args[2].c_str()); + if (args.size() >= 4 && args[1] == "mode") { + const auto bits = static_cast(std::stoi(args[2], nullptr, 8)); + for (std::size_t i = 3; i < args.size(); ++i) { + std::error_code ec; + fs::permissions(path_of(args[i]), bits, ec); + if (ec) { + say("steps-probe: cannot set the permissions of " + args[i] + ": " + ec.message() + "\n"); + return 1; + } + } + return 0; + } + if (args.size() == 5 && args[1] == "verify") return verify(args[2], args[3], args[4]); + say("usage: steps-probe args ... | cwd | exit | mode ... " + "| verify \n"); + return 2; +} diff --git a/tests/steps-consumer/src/main.cpp b/tests/steps-consumer/src/main.cpp new file mode 100644 index 0000000..603cfb4 --- /dev/null +++ b/tests/steps-consumer/src/main.cpp @@ -0,0 +1,8 @@ +import std; + +// The program exists so the fixture has something to link. What is tested ran +// before it: the step programs build.mcpp declared, and the check of their tree. +int main() { + std::cout << "steps-consumer ok\n"; + return 0; +} diff --git a/tools/steps.cppm b/tools/steps.cppm index 74f469d..f0d8714 100644 --- a/tools/steps.cppm +++ b/tools/steps.cppm @@ -10,22 +10,28 @@ // `/bin/sh` scripts, which a Windows host cannot start; a Java program on the // JDK a member already needed; `cmake -P` over a script. // -// HERE A MEMBER DESCRIBES THE STEP AND A BACKEND RUNS IT. `program` is a list +// HERE A MEMBER DESCRIBES THE STEP AND A RUNNER RUNS IT. `program` is a list // of portable operations -- run a command, touch, make, remove and copy // files, list files into a named list, fail when a list is empty -- with // every value taken verbatim, so a path keeps its spaces, semicolons and -// backslashes on every host. A member never writes the backend's language. +// backslashes on every host. A member never writes the runner's language. // -// THE BACKEND IS `cmake -P` UNTIL THE ENGINE RUNS A STEP PROGRAM ITSELF -// (mcpp-community/mcpp#955). `command` renders the program as a CMake script, -// written only when its text changes, and returns the action's argument -// vector and the inputs it declares -- the runner and the script, so a changed -// program or runner runs the action again and an unchanged one does not. -// `runner_spec` is the runner the member resolves through `mcpp.plugins.tool`; -// a member that runs steps declares it on its own table, -// `"xim:cmake" = { version = ">=3.31", provision = "on-request" }`, so a plan -// that runs none installs nothing. When the engine runs step programs, these -// two functions change and no member does. +// THE RUNNER IS THIS PACKAGE'S OWN PROGRAM, `steps` (0.27.0). `command` writes +// the program as a step file (`mcpp::plugins::steps`, in the lib root, which +// the runner reads), only when its text changes, and returns the action's +// argument vector, `{, }`, with both as the inputs it declares, +// so a changed program or runner runs the action again and an unchanged one +// does not. The feature that adds this module declares the runner as its tool +// (`[features.tools-steps] tools = ["steps"]`): it is built once for the +// machine that builds, and every build program that links this library with +// the feature active receives its path (mcpp 2026.11.19.1, SPEC-007 R6.3), +// a framework's user as well as the package that names this collection. +// +// The runner was `cmake -P` over a rendered script in 0.25.0 and 0.26.0, and +// each member that ran steps declared `xim:cmake` for it. mcpp-community/mcpp#955 +// asked the engine to interpret these operations; the engine instead lets a +// plugin carry its own program, so the operations stay this package's +// vocabulary, versioned with it. // // Loops here index rather than iterate: an inline function of an imported // module that iterates a string fails to compile in the importer under @@ -35,11 +41,14 @@ export module mcpp.tools.steps; import std; import mcpp; +import mcpp.plugins; import mcpp.plugins.fs; -import mcpp.plugins.tool; export namespace mcpp::tools::steps { +using op_kind = mcpp::plugins::steps::op_kind; +using op = mcpp::plugins::steps::op; + struct run_options { // The directory the command runs in; empty is the build's. std::string working_directory; @@ -60,22 +69,6 @@ struct glob_options { std::vector exclude; }; -enum class op_kind { - run, touch, mkdir, remove, remove_glob, copy_file, copy_tree, copy_glob, - rename, symlink, glob, append, require, -}; - -// One operation. `values` is the argument vector of `run`, the values of -// `append` and the exclusions of `glob`; `a` and `b` are an operation's -// operands; `list` names the list an operation reads or extends. -struct op { - op_kind kind; - std::vector values; - std::string a, b, list; - bool recursive = false; - bool if_exists = false; -}; - // The operations of one step, run in order; the first that fails fails the // step. A list is named by letters, digits and `_`, and starts empty. class program { @@ -145,182 +138,42 @@ private: std::vector ops_; }; -// ─── The backend: `cmake -P` (until mcpp-community/mcpp#955) ─────────────── - -namespace cmake_backend { - -// A value as a bracket argument, with a bracket no value contains. -inline std::string bracket(std::string_view value) { - std::string eq = "=="; - while (value.find("]" + eq + "]") != std::string_view::npos) eq += '='; - return "[" + eq + "[" + std::string(value) + "]" + eq + "]"; -} - -inline std::string brackets(const std::vector& values) { - std::string out; - for (std::size_t i = 0; i < values.size(); ++i) { - if (i) out += ' '; - out += bracket(values[i]); - } - return out; -} - -inline bool valid_list_name(const std::string& name) { - if (name.empty()) return false; - for (std::size_t i = 0; i < name.size(); ++i) { - const unsigned char c = static_cast(name[i]); - if (!std::isalnum(c) && c != '_') return false; - } - return true; -} - -inline std::string var(const std::string& list) { return "mcpp_steps_" + list; } - -// An exclusion pattern as an anchored regular expression over the whole path: -// `*` is any run of characters, `?` one, a bracket expression stays one, and -// every other character stands for itself. -inline std::string exclusion_regex(const std::string& pattern) { - std::string out = "^"; - for (std::size_t i = 0; i < pattern.size(); ++i) { - const char c = pattern[i]; - if (c == '*') { - out += ".*"; - } else if (c == '?') { - out += '.'; - } else if (c == '[') { - const std::size_t close = pattern.find(']', i + 1); - if (close == std::string::npos) { out += "\\["; continue; } - std::string set = pattern.substr(i + 1, close - i - 1); - if (!set.empty() && set[0] == '!') set[0] = '^'; - out += "[" + set + "]"; - i = close; - } else { - if (std::string_view(".+()^$|\\{}").find(c) != std::string_view::npos) out += '\\'; - out += c; - } - } - return out + "$"; -} - -inline std::string parent_of(const std::string& path) { - return std::filesystem::path(path).parent_path().generic_string(); -} - -// The script. A list name outside letters, digits and `_` is a member's -// mistake and is refused here rather than rendered into the script. -inline std::string render(const program& p) { - std::string out; - std::vector lists; - const auto& ops = p.ops(); - for (std::size_t i = 0; i < ops.size(); ++i) { - const std::string& l = ops[i].list; - if (l.empty()) continue; - if (!valid_list_name(l)) - throw std::invalid_argument("mcpp.tools.steps: list name '" + l + "' is not letters, digits and _"); - if (std::find(lists.begin(), lists.end(), l) == lists.end()) { - lists.push_back(l); - out += "set(" + var(l) + ")\n"; - } - } - for (std::size_t i = 0; i < ops.size(); ++i) { - const op& o = ops[i]; - switch (o.kind) { - case op_kind::run: - out += "execute_process(COMMAND " + brackets(o.values); - if (!o.list.empty()) out += " ${" + var(o.list) + "}"; - if (!o.a.empty()) out += "\n WORKING_DIRECTORY " + bracket(o.a); - out += "\n COMMAND_ERROR_IS_FATAL ANY)\n"; - break; - case op_kind::touch: - if (!parent_of(o.a).empty()) out += "file(MAKE_DIRECTORY " + bracket(parent_of(o.a)) + ")\n"; - out += "file(TOUCH " + bracket(o.a) + ")\n"; - break; - case op_kind::mkdir: - out += "file(MAKE_DIRECTORY " + bracket(o.a) + ")\n"; - break; - case op_kind::remove: - out += "file(REMOVE_RECURSE " + bracket(o.a) + ")\n"; - break; - case op_kind::remove_glob: - out += "file(GLOB mcpp_steps_matched LIST_DIRECTORIES false " + bracket(o.a) + ")\n" - "if(mcpp_steps_matched)\n" - " file(REMOVE ${mcpp_steps_matched})\n" - "endif()\n"; - break; - case op_kind::copy_file: - if (!parent_of(o.b).empty()) out += "file(MAKE_DIRECTORY " + bracket(parent_of(o.b)) + ")\n"; - out += "file(COPY_FILE " + bracket(o.a) + " " + bracket(o.b) + ")\n"; - break; - case op_kind::copy_tree: { - // A trailing `/` copies the directory's contents rather than the directory. - std::string body = "file(MAKE_DIRECTORY " + bracket(o.b) + ")\n" - "file(COPY " + bracket(o.a + "/") + " DESTINATION " + bracket(o.b) + ")\n"; - out += o.if_exists ? "if(IS_DIRECTORY " + bracket(o.a) + ")\n" + body + "endif()\n" : body; - break; - } - case op_kind::copy_glob: - out += "file(GLOB mcpp_steps_matched LIST_DIRECTORIES false " + bracket(o.a) + ")\n" - "file(MAKE_DIRECTORY " + bracket(o.b) + ")\n" - "if(mcpp_steps_matched)\n" - " file(COPY ${mcpp_steps_matched} DESTINATION " + bracket(o.b) + ")\n" - "endif()\n"; - break; - case op_kind::rename: - out += "file(RENAME " + bracket(o.a) + " " + bracket(o.b) + ")\n"; - break; - case op_kind::symlink: - out += "file(CREATE_LINK " + bracket(o.a) + " " + bracket(o.b) + " SYMBOLIC)\n"; - break; - case op_kind::glob: - out += std::string(o.recursive ? "file(GLOB_RECURSE" : "file(GLOB") + " mcpp_steps_matched LIST_DIRECTORIES false"; - if (!o.b.empty()) out += " RELATIVE " + bracket(o.b); - out += " " + bracket(o.a) + ")\n"; - for (std::size_t k = 0; k < o.values.size(); ++k) - out += "list(FILTER mcpp_steps_matched EXCLUDE REGEX " + bracket(exclusion_regex(o.values[k])) + ")\n"; - out += "list(APPEND " + var(o.list) + " ${mcpp_steps_matched})\n"; - break; - case op_kind::append: - if (!o.values.empty()) out += "list(APPEND " + var(o.list) + " " + brackets(o.values) + ")\n"; - break; - case op_kind::require: - out += "if(NOT " + var(o.list) + ")\n" - " message(FATAL_ERROR " + bracket(o.a) + ")\n" - "endif()\n"; - break; - } - } - return out; -} - -} // namespace cmake_backend - -// The program a member resolves to run steps: `xim:cmake` in its two layouts -// (`bin/` and, on macOS, `CMake.app/Contents/bin`). `who` is the member's -// module, for the decision record and the refusal text. -inline mcpp::plugins::tool::spec runner_spec(std::string who) { - return { .who = std::move(who), .package = "cmake", .programs = {"cmake"}, - .bin_dirs = {"bin", "CMake.app/Contents/bin"}, .option = "options::cmake" }; +// ─── The runner: `steps`, a program of this package (0.27.0) ────────────── + +// The runner's path in this build program, from the feature's tool. Empty only +// where the engine gives this program no such tool, and the engine then +// reports the undeclared tool itself (`build-program/undeclared-tool`); a +// member refuses with `missing_runner` rather than plan an action without a +// program. +inline std::string runner() { return mcpp::dep_bin("mcpp.plugins", "steps"); } + +// The refusal of a member that has no runner; `who` is the member's module. +inline std::string missing_runner(std::string_view who) { + return std::format( + "{}: the runner of its step programs, `steps` of mcpp.plugins, is not available to this " + "build program. The feature `tools-steps` declares it, and mcpp 2026.11.19.1 or newer " + "gives it to every build program that links mcpp.plugins with that feature active.", + who); } // What an action declares to run a step program. struct invocation { - std::vector argv; // the runner, then its arguments - std::vector inputs; // the runner and the written program + std::vector argv; // the runner, then the step file + std::vector inputs; // the runner and the step file }; -// Writes `p` beside `base` (the backend adds its extension) unless the file -// already holds it, and returns how an action runs it with `runner`, the -// program `runner_spec` resolved. The first line names `who`, so a file found -// in an output directory says what wrote it. +// Writes `p` as `.steps` unless the file already holds it, and returns +// how an action runs it with `runner`, the path `runner()` answered. The +// comment line names `who`, so a file found in an output directory says what +// wrote it. inline invocation command(const std::string& runner, const std::filesystem::path& base, std::string_view who, const program& p) { std::filesystem::path file = base; - file += ".cmake"; - mcpp::plugins::fs::write_if_changed(file, - "# Written by " + std::string(who) + " through mcpp.tools.steps. Do not edit.\n" - + cmake_backend::render(p)); + file += ".steps"; + mcpp::plugins::fs::write_if_changed(file, mcpp::plugins::steps::write(p.ops(), + "Written by " + std::string(who) + " through mcpp.tools.steps. Do not edit.")); const std::string path = mcpp::plugins::fs::generic(file); - return { .argv = { runner, "-P", path }, .inputs = { runner, path } }; + return { .argv = { runner, path }, .inputs = { runner, path } }; } } // namespace mcpp::tools::steps diff --git a/tools/steps_main.cpp b/tools/steps_main.cpp new file mode 100644 index 0000000..4b82ef7 --- /dev/null +++ b/tools/steps_main.cpp @@ -0,0 +1,608 @@ +// steps -- the runner of a step program (mcpp.tools.steps, 0.27.0). +// +// steps +// +// Runs the operations the file holds (`mcpp::plugins::steps`, which +// `mcpp.tools.steps` writes while a build program plans) in order, and stops at +// the first that fails, naming it on standard error; the status is then 1. +// +// A PROGRAM OF THIS PACKAGE, NOT A VOCABULARY OF THE ENGINE. The feature +// `tools-steps` declares it as its tool, so the engine builds it once for the +// machine that builds and gives its path to every build program that links +// mcpp.plugins with that feature active (mcpp 2026.11.19.1). The operations +// change with this package and never wait for an engine release +// (mcpp-community/mcpp#955). +// +// NO SHELL, ON EVERY HOST. A program is started with its argument vector as it +// is (mcpplibs.os over openkal, which on Windows quotes each argument by the +// rule the started program splits its command line with), and every name is +// converted from UTF-8 by mcpplibs.os rather than through the process's code +// page. So a value keeps its spaces, semicolons, quotes, backslashes and +// non-ASCII text on Linux, macOS and Windows alike. +// +// THE SEMANTICS ARE THE ONES 0.25.0 STATED AND ITS BACKEND IMPLEMENTED, so that +// no member changes a step description. The backend was `cmake -P` of the +// `xim:cmake` it asked for, which the index offers only as CMake 4; where CMake +// decided a detail the statement left open, this program decides it the same +// way, as measured with CMake 4.5: a pattern's matches are sorted and spelled +// as the pattern's directory was written, then `/` and the rest; a pattern that +// names no absolute directory is the working directory's; a name is matched +// without case where the host compares names without it (Windows, macOS), and +// an exclusion is compared exactly; a recursive pattern enters no linked +// directory and matches the link by its name; a copied tree keeps a link as a +// link, a file's time and every permission, a directory's included; a +// read-only file or directory is removed and replaced as any other; a program +// named by a relative place is found from the directory it runs in. Three +// details differ, where CMake altered a value or read a byte as a character: a +// value that holds `;` stays one value of its list; a list is empty only when +// it holds no value; and `?` or a bracket expression stands for one character +// of UTF-8 text, compared without case as the rest of the name is. + +import std; +import mcpp.plugins; +import mcpplibs.os; + +namespace { + +namespace os = mcpplibs::os; +namespace fs = std::filesystem; +namespace st = mcpp::plugins::steps; + +using done = std::expected; +using lists = std::map>; + +fs::path path_of(std::string_view utf8) { return os::fs::from_utf8(utf8); } + +std::string shown(std::string_view value) { return std::format("'{}'", value); } + +void say(std::string_view text) { (void)os::stdio::write_error(text); } + +// ─── Names and patterns ──────────────────────────────────────────────────── + +// The characters of UTF-8 text, as code points. A byte that begins no valid +// sequence stands for itself above the code points, so a name that is not +// UTF-8 is still matched by its own bytes. +std::vector characters(std::string_view text) { + std::vector out; + out.reserve(text.size()); + std::size_t i = 0; + while (i < text.size()) { + const auto lead = static_cast(text[i]); + const std::size_t n = lead < 0x80 ? 1 : (lead >> 5) == 0x6 ? 2 : (lead >> 4) == 0xE ? 3 + : (lead >> 3) == 0x1E ? 4 : 0; + char32_t c = n == 1 ? lead : n == 2 ? (lead & 0x1Fu) : n == 3 ? (lead & 0x0Fu) : (lead & 0x07u); + bool whole = n != 0 && i + n <= text.size(); + for (std::size_t k = 1; whole && k < n; ++k) { + const auto next = static_cast(text[i + k]); + whole = (next >> 6) == 0x2; + c = (c << 6) | (next & 0x3Fu); + } + if (!whole) { + out.push_back(0x110000u + lead); + ++i; + continue; + } + out.push_back(c); + i += n; + } + return out; +} + +// One element of a pattern: a character, `?`, `*`, or a bracket expression. +struct token { + enum class kind { character, any, star, set } what = kind::character; + char32_t c = 0; + bool negated = false; + std::vector> ranges; +}; + +// The `]` that closes the bracket expression opened at `open`, or `cs.size()`. +// A `]` first in the expression, after a `!` or `^` that negates it, stands +// for itself. +std::size_t closing_bracket(const std::vector& cs, std::size_t open) { + std::size_t j = open + 1; + if (j < cs.size() && (cs[j] == U'!' || cs[j] == U'^')) ++j; + if (j < cs.size() && cs[j] == U']') ++j; + while (j < cs.size() && cs[j] != U']') ++j; + return j; +} + +token bracket(const std::vector& cs, std::size_t open, std::size_t close) { + token t{ token::kind::set }; + std::size_t j = open + 1; + if (cs[j] == U'!' || cs[j] == U'^') { + t.negated = true; + ++j; + } + while (j < close) { + if (j + 2 < close && cs[j + 1] == U'-') { + t.ranges.emplace_back(cs[j], cs[j + 2]); + j += 3; + } else { + t.ranges.emplace_back(cs[j], cs[j]); + ++j; + } + } + return t; +} + +// A pattern's elements: `*`, `?`, `[...]` (negated by `!` or `^`, `a-z` a +// range), and every other character for itself -- a `[` no `]` closes, and a +// backslash, included. This is the grammar 0.25.0's backend read for a name +// and, with `*` crossing `/`, for an exclusion. +std::vector compile(std::string_view pattern) { + const auto cs = characters(pattern); + std::vector out; + for (std::size_t i = 0; i < cs.size(); ++i) { + if (cs[i] == U'*') { + if (out.empty() || out.back().what != token::kind::star) out.push_back({ token::kind::star }); + continue; + } + if (cs[i] == U'?') { + out.push_back({ token::kind::any }); + continue; + } + const std::size_t close = cs[i] == U'[' ? closing_bracket(cs, i) : cs.size(); + if (close == cs.size()) { + out.push_back({ token::kind::character, cs[i] }); + continue; + } + out.push_back(bracket(cs, i, close)); + i = close; + } + return out; +} + +// The other case of an ASCII letter: names are compared without case only as +// far as the hosts that do so compare them for every name. +char32_t other_case(char32_t c) { + if (c >= U'a' && c <= U'z') return c - (U'a' - U'A'); + if (c >= U'A' && c <= U'Z') return c + (U'a' - U'A'); + return c; +} + +bool one(const token& t, char32_t c, bool fold) { + if (t.what == token::kind::any) return true; + if (t.what == token::kind::character) return t.c == c || (fold && t.c == other_case(c)); + const auto in = [&](char32_t x) { + return std::ranges::any_of(t.ranges, [&](const auto& r) { return r.first <= x && x <= r.second; }); + }; + return (in(c) || (fold && in(other_case(c)))) != t.negated; +} + +// Whether the pattern matches the whole text. A `*` matches any run of +// characters, and the match resumes after the last one when a later element +// fails. +bool matches(const std::vector& pattern, const std::vector& text, bool fold) { + std::size_t p = 0, t = 0, star = pattern.size(), resume = 0; + while (t < text.size()) { + if (p < pattern.size() && pattern[p].what == token::kind::star) { + star = p++; + resume = t; + } else if (p < pattern.size() && one(pattern[p], text[t], fold)) { + ++p; + ++t; + } else if (star != pattern.size()) { + p = star + 1; + t = ++resume; + } else { + return false; + } + } + while (p < pattern.size() && pattern[p].what == token::kind::star) ++p; + return p == pattern.size(); +} + +// A separator of the host's names: `/`, and on Windows `\` as well. +bool separator(char c) { + if constexpr (os::is_windows) return c == '/' || c == '\\'; + else return c == '/'; +} + +// Whether a pattern's directory, as written before its last separator, is a +// root: nothing (`/x`), or on Windows a drive (`C:/x`). +bool names_root(std::string_view dir) { + if constexpr (os::is_windows) return dir.empty() || (dir.size() == 2 && dir[1] == ':'); + else return dir.empty(); +} + +// The files a pattern matches, sorted. The wildcards of its last component are +// matched against each name of its directory, and with `recursive` against +// each name of every directory below it; a directory is never a match. A link +// to a directory is passed over by a flat pattern, and a recursive one does not +// enter it but matches it by its name, as CMake 4's recursive glob (the +// backend's `xim:cmake`) followed no link. +std::vector glob(std::string_view pattern, bool recursive) { + std::size_t cut = std::string_view::npos; + for (std::size_t i = 0; i < pattern.size(); ++i) + if (separator(pattern[i])) cut = i; + const bool has_dir = cut != std::string_view::npos; + const std::string_view name = has_dir ? pattern.substr(cut + 1) : pattern; + std::string spelled = has_dir ? std::string(pattern.substr(0, cut)) : std::string(); + // A pattern with no directory, or a relative one, is the working + // directory's, so a match is always absolute. + const bool root = has_dir && names_root(spelled); + if (!root && (!has_dir || !os::fs::is_absolute(path_of(spelled)))) { + const std::string here = os::fs::generic_utf8(fs::current_path()); + spelled = has_dir ? here + "/" + spelled : here; + } + std::vector found; + if (name.empty()) return found; + const auto tokens = compile(name); + const bool fold = os::conventions().case_insensitive_names; + // Each directory still to list, with the spelling of a match under it. + std::vector> pending{ { path_of(root ? spelled + "/" : spelled), spelled } }; + while (!pending.empty()) { + const auto [dir, prefix] = std::move(pending.back()); + pending.pop_back(); + std::error_code ec; + for (fs::directory_iterator it(dir, fs::directory_options::skip_permission_denied, ec), end; + !ec && it != end; it.increment(ec)) { + const std::string leaf = os::fs::utf8(it->path().filename()); + std::error_code kind; + const bool linked = it->is_symlink(kind); + if (it->is_directory(kind) && !(recursive && linked)) { + if (recursive) pending.emplace_back(it->path(), prefix + "/" + leaf); + continue; + } + if (matches(tokens, characters(leaf), fold)) found.push_back(prefix + "/" + leaf); + } + } + std::ranges::sort(found); + found.erase(std::unique(found.begin(), found.end()), found.end()); + return found; +} + +// The names of a path made absolute, its root's included, with `.` and `..` +// resolved as text. +std::vector names(const std::string& path) { + fs::path whole = path_of(path); + if (!os::fs::is_absolute(whole)) whole = fs::current_path() / whole; + std::vector out; + for (auto const& part : whole.lexically_normal()) + if (std::string name = os::fs::generic_utf8(part); !name.empty()) out.push_back(std::move(name)); + return out; +} + +bool same_name(std::string_view a, std::string_view b, bool fold) { + if (a.size() != b.size()) return false; + for (std::size_t i = 0; i < a.size(); ++i) { + const char32_t x = static_cast(a[i]), y = static_cast(b[i]); + if (x != y && !(fold && other_case(x) == y)) return false; + } + return true; +} + +// `file` relative to `base` as the backend's `GLOB RELATIVE` gave it: the +// names both begin with are dropped, compared without case where the host +// compares names so; each other name of `base` becomes `..`; and a file that +// shares not even the root with `base` (another drive) keeps its own path. +std::string relative(const std::string& file, const std::string& base) { + const auto f = names(file), b = names(base); + const bool fold = os::conventions().case_insensitive_names; + std::size_t same = 0; + while (same < f.size() && same < b.size() && same_name(f[same], b[same], fold)) ++same; + if (same == 0) return file; + std::string out; + for (std::size_t k = same; k < b.size(); ++k) out += out.empty() ? ".." : "/.."; + for (std::size_t k = same; k < f.size(); ++k) out += (out.empty() ? "" : "/") + f[k]; + return out; +} + +// ─── The operations ──────────────────────────────────────────────────────── + +done run_program(const st::op& o, const lists& named) { + std::vector argv = o.values; + if (const auto it = named.find(o.list); !o.list.empty() && it != named.end()) + argv.insert(argv.end(), it->second.begin(), it->second.end()); + if (argv.empty() || argv.front().empty()) return std::unexpected(std::string("there is no program to run")); + os::process::spawn_options start; + start.program = path_of(argv.front()); + // A program named by a relative place is found from the directory it runs + // in, as `exec` after a change of directory finds it. + if (!o.a.empty() && os::fs::names_a_place(argv.front()) && !os::fs::is_absolute(start.program)) + start.program = path_of(o.a) / start.program; + start.argv0 = argv.front(); + start.args.assign(argv.begin() + 1, argv.end()); + if (!o.a.empty()) start.cwd = path_of(o.a); + start.in = start.out = start.err = os::process::stdio::inherit; + // The failure's description names the program, so these messages do not. + auto child = os::process::process::spawn(start); + if (!child) return std::unexpected(std::format("it cannot be started: {}", child.error().message())); + const auto status = child->wait(); + if (!status) return std::unexpected(std::format("its end cannot be awaited: {}", status.error().message())); + if (status->success()) return {}; + if (status->by_environment) + return std::unexpected(std::format("it was ended by its environment (condition {})", status->code)); + return std::unexpected(std::format("it exited with status {}", status->code)); +} + +done touch_file(const st::op& o) { + const fs::path file = path_of(o.a); + std::error_code ec; + if (file.has_parent_path()) fs::create_directories(file.parent_path(), ec); + if (ec) return std::unexpected(std::format("cannot make the directory of {}: {}", shown(o.a), ec.message())); + if (!fs::exists(file, ec)) { + std::ofstream made(file, std::ios::binary | std::ios::app); + if (!made) return std::unexpected(std::format("cannot create {}", shown(o.a))); + return {}; + } + fs::last_write_time(file, fs::file_time_type::clock::now(), ec); + if (ec) return std::unexpected(std::format("cannot update the time of {}: {}", shown(o.a), ec.message())); + return {}; +} + +done make_directory(const st::op& o) { + const fs::path dir = path_of(o.a); + std::error_code ec; + fs::create_directories(dir, ec); + if (!ec && fs::is_directory(dir, ec)) return {}; + return std::unexpected(std::format("cannot make the directory {}: {}", shown(o.a), + ec ? ec.message() : std::string("something else is there"))); +} + +// The entry, and every entry under it, made writable by its owner, as the +// backend made them before it removed them: a read-only file fails a removal on +// Windows, and a read-only directory one everywhere. A link is left as it is, +// since its permissions are its target's. +void make_writable(const fs::path& path) { + std::error_code ignored, ec; + const auto writable = [&](const fs::path& p) { + if (!fs::is_symlink(fs::symlink_status(p, ignored))) + fs::permissions(p, fs::perms::owner_write, fs::perm_options::add, ignored); + }; + writable(path); + if (!fs::is_directory(fs::symlink_status(path, ignored))) return; + for (fs::recursive_directory_iterator it(path, ec), end; !ec && it != end; it.increment(ec)) + writable(it->path()); +} + +done remove_entry(std::string_view name, const fs::path& path) { + std::error_code ec; + fs::remove_all(path, ec); + if (!ec) return {}; + make_writable(path); + ec.clear(); + fs::remove_all(path, ec); + if (ec) return std::unexpected(std::format("cannot remove {}: {}", shown(name), ec.message())); + return {}; +} + +done remove_matches(const st::op& o) { + for (auto const& f : glob(o.a, false)) + if (auto removed = remove_entry(f, path_of(f)); !removed) return removed; + return {}; +} + +// Whatever is at `to`, unless it is a directory, removed before a copy or a +// link takes its place: the backend replaced a read-only file as any other. +std::error_code clear_way(const fs::path& to) { + std::error_code absent, ec; + // A missing `to` is an error of `symlink_status` under libstdc++, and not + // one of this copy. + if (const auto there = fs::symlink_status(to, absent); !fs::exists(there) || fs::is_directory(there)) return {}; + if (fs::remove(to, ec); !ec) return {}; + make_writable(to); + ec.clear(); + fs::remove(to, ec); + return ec; +} + +// A file or a link copied as the backend's `file(COPY)` copied it: a link as a +// link, a file with its permissions and its time. +done copy_entry(const fs::path& from, const fs::path& to) { + std::error_code ec; + const bool link = fs::is_symlink(fs::symlink_status(from, ec)); + if (!ec) ec = clear_way(to); + if (!ec && link) { + fs::copy_symlink(from, to, ec); + } else if (!ec) { + fs::copy_file(from, to, fs::copy_options::overwrite_existing, ec); + const auto when = ec ? fs::file_time_type{} : fs::last_write_time(from, ec); + if (!ec) fs::last_write_time(to, when, ec); + } + if (!ec) return {}; + return std::unexpected(std::format("cannot copy {} to {}: {}", shown(os::fs::generic_utf8(from)), + shown(os::fs::generic_utf8(to)), ec.message())); +} + +done copy_one_file(const st::op& o) { + const fs::path from = path_of(o.a), to = path_of(o.b); + std::error_code ec; + // What is at `to` stays when there is nothing to copy over it. + if (!fs::is_regular_file(from, ec)) return std::unexpected(std::format("{} is not a file", shown(o.a))); + if (to.has_parent_path()) fs::create_directories(to.parent_path(), ec); + if (ec) return std::unexpected(std::format("cannot make the directory of {}: {}", shown(o.b), ec.message())); + if (fs::exists(to, ec) && fs::equivalent(from, to, ec)) return {}; + ec = clear_way(to); + if (!ec) fs::copy_file(from, to, fs::copy_options::overwrite_existing, ec); + if (ec) return std::unexpected(std::format("cannot copy {} to {}: {}", shown(o.a), shown(o.b), ec.message())); + return {}; +} + +// A directory's contents copied into `o.b` as the backend's `file(COPY /)` +// copied them. Each directory is open to its owner while the copy fills it and +// takes its source's permissions after, `o.b` the source's own, so a read-only +// tree copies, and copies again over its copy. +done copy_tree_contents(const st::op& o) { + const fs::path from = path_of(o.a), to = path_of(o.b); + std::error_code ec; + if (!fs::is_directory(from, ec)) { + if (o.if_exists) return {}; + return std::unexpected(std::format("{} is not a directory", shown(o.a))); + } + std::vector> modes; + const auto open_directory = [&](const fs::path& source, const fs::path& dir) { + std::error_code e; + fs::create_directories(dir, e); + if (!e) modes.emplace_back(dir, fs::status(source, e).permissions()); + if (!e) fs::permissions(dir, fs::perms::owner_all, fs::perm_options::add, e); + if (e) return done(std::unexpected(std::format("cannot make the directory {}: {}", + shown(os::fs::generic_utf8(dir)), e.message()))); + return done{}; + }; + if (auto opened = open_directory(from, to); !opened) return opened; + for (fs::recursive_directory_iterator it(from, ec), end; !ec && it != end; it.increment(ec)) { + const fs::path dest = to / it->path().lexically_relative(from); + std::error_code kind; + auto copied = fs::is_directory(it->symlink_status(kind)) ? open_directory(it->path(), dest) + : copy_entry(it->path(), dest); + if (!copied) return copied; + } + if (ec) return std::unexpected(std::format("cannot list {}: {}", shown(o.a), ec.message())); + for (auto it = modes.rbegin(); it != modes.rend(); ++it) { + fs::permissions(it->first, it->second, ec); + if (ec) return std::unexpected(std::format("cannot set the permissions of {}: {}", + shown(os::fs::generic_utf8(it->first)), ec.message())); + } + return {}; +} + +done copy_matches(const st::op& o) { + const fs::path to = path_of(o.b); + std::error_code ec; + fs::create_directories(to, ec); + if (ec) return std::unexpected(std::format("cannot make the directory {}: {}", shown(o.b), ec.message())); + for (auto const& f : glob(o.a, false)) { + const fs::path from = path_of(f); + if (auto copied = copy_entry(from, to / from.filename()); !copied) return copied; + } + return {}; +} + +done rename_entry(const st::op& o) { + const fs::path from = path_of(o.a), to = path_of(o.b); + auto moved = os::fs::rename(from, to, true); + // Windows does not replace a read-only file; the backend made it writable + // and tried again. + if (std::error_code ignored; !moved && fs::is_regular_file(fs::symlink_status(to, ignored))) { + fs::permissions(to, fs::perms::owner_write, fs::perm_options::add, ignored); + moved = os::fs::rename(from, to, true); + } + if (!moved) + return std::unexpected(std::format("cannot rename {} to {}: {}", shown(o.a), shown(o.b), moved.error().message())); + return {}; +} + +// A symbolic link at `b` naming `a`, as written. An entry already at `b` that +// is not a directory is replaced, as the backend replaced it. +done make_link(const st::op& o) { + const fs::path target = path_of(o.a), link = path_of(o.b); + std::error_code absent, ec; + if (fs::is_directory(fs::symlink_status(link, absent))) + return std::unexpected(std::format("cannot link {}: a directory is there", shown(o.b))); + if (const auto in_the_way = clear_way(link)) + return std::unexpected(std::format("cannot replace {}: {}", shown(o.b), in_the_way.message())); + // Whether the target is a directory decides the kind of link on Windows; a + // relative target is read from the link's directory, as the system reads it. + const fs::path resolved = os::fs::is_absolute(target) ? target : link.parent_path() / target; + const bool directory = fs::is_directory(resolved, ec); + if (auto made = os::fs::create_link(target, link, directory); !made) + return std::unexpected(std::format("cannot link {} to {}: {}", shown(o.b), shown(o.a), made.error().message())); + return {}; +} + +done glob_into(const st::op& o, lists& named) { + std::vector found = glob(o.a, o.recursive); + if (!o.b.empty()) { + for (auto& f : found) f = relative(f, o.b); + std::ranges::sort(found); + found.erase(std::unique(found.begin(), found.end()), found.end()); + } + std::vector> excluded; + for (auto const& e : o.values) excluded.push_back(compile(e)); + auto& list = named[o.list]; + for (auto const& f : found) { + const auto text = characters(f); + if (std::ranges::none_of(excluded, [&](const auto& e) { return matches(e, text, false); })) + list.push_back(f); + } + return {}; +} + +done append_values(const st::op& o, lists& named) { + auto& list = named[o.list]; + list.insert(list.end(), o.values.begin(), o.values.end()); + return {}; +} + +done require_values(const st::op& o, const lists& named) { + if (const auto it = named.find(o.list); it != named.end() && !it->second.empty()) return {}; + return std::unexpected(o.a); +} + +done perform(const st::op& o, lists& named) { + switch (o.kind) { + case st::op_kind::run: return run_program(o, named); + case st::op_kind::touch: return touch_file(o); + case st::op_kind::mkdir: return make_directory(o); + case st::op_kind::remove: return remove_entry(o.a, path_of(o.a)); + case st::op_kind::remove_glob: return remove_matches(o); + case st::op_kind::copy_file: return copy_one_file(o); + case st::op_kind::copy_tree: return copy_tree_contents(o); + case st::op_kind::copy_glob: return copy_matches(o); + case st::op_kind::rename: return rename_entry(o); + case st::op_kind::symlink: return make_link(o); + case st::op_kind::glob: return glob_into(o, named); + case st::op_kind::append: return append_values(o, named); + case st::op_kind::require: return require_values(o, named); + } + return std::unexpected(std::string("an operation this runner does not know")); +} + +// The operation as a failure names it. +std::string describe(const st::op& o) { + switch (o.kind) { + case st::op_kind::run: + return std::format("run {}", o.values.empty() ? std::string("''") : shown(o.values.front())); + case st::op_kind::copy_file: case st::op_kind::copy_tree: case st::op_kind::copy_glob: + case st::op_kind::rename: case st::op_kind::symlink: + return std::format("{} {} {}", st::name_of(o.kind), shown(o.a), shown(o.b)); + case st::op_kind::glob: + return std::format("glob {} into '{}'", shown(o.a), o.list); + case st::op_kind::append: case st::op_kind::require: + return std::format("{} '{}'", st::name_of(o.kind), o.list); + default: + return std::format("{} {}", st::name_of(o.kind), shown(o.a)); + } +} + +int run_file(const std::string& file) { + const auto text = os::fs::read(path_of(file)); + if (!text) { + say(std::format("steps: {} cannot be read: {}\n", file, text.error().message())); + return 1; + } + const auto ops = st::read(*text); + if (!ops) { + say(std::format("steps: {}: {}\n", file, ops.error())); + return 1; + } + lists named; + for (std::size_t i = 0; i < ops->size(); ++i) { + const st::op& o = (*ops)[i]; + if (const auto outcome = perform(o, named); !outcome) { + say(std::format("steps: {}: operation {} of {}, {}: {}\n", file, i + 1, ops->size(), + describe(o), outcome.error())); + return 1; + } + } + return 0; +} + +} // namespace + +int main() { + const auto args = os::env::arguments(); + if (args.size() != 2) { + say("usage: steps \n" + " runs, in order, the operations of a step program that mcpp.tools.steps wrote\n"); + return 2; + } + try { + return run_file(args[1]); + } catch (const std::exception& e) { + say(std::format("steps: {}: {}\n", args[1], e.what())); + return 1; + } +} From 2629f110606102051156c9798a8beb9ecdf57dec Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Thu, 19 Nov 2026 19:15:28 +0900 Subject: [PATCH 2/4] 0.27.0: dist-apple refreshes the bundle with a step, not /usr/bin/touch The bundle step, the plan's sole terminal artifact, refreshes the bundle directory's time with the step operation `touch`, run by the runner `steps`, instead of naming the host program /usr/bin/touch. Every dist-apple plan therefore resolves the runner, which the feature tools-steps carries wherever the member is active; the framework copy and the disk-image staging were step programs already. The macOS and iOS plan checks hand the build program the runner's path and assert that the bundle step is a step program whose only operation touches the bundle. --- dist/apple.cppm | 38 +++++++++---------- .../check-apple-plan.sh | 5 ++- tests/ios-app-consumer/check-ios-plan.sh | 7 ++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/dist/apple.cppm b/dist/apple.cppm index 08e7224..f683919 100644 --- a/dist/apple.cppm +++ b/dist/apple.cppm @@ -425,11 +425,11 @@ inline plan& refuse(plan& p, std::string reason, const std::string& message) { return p; } -// A step of more than one command (0.25.0): a step program -// (`mcpp.tools.steps`) written into `/dist-apple/steps/`, so no step -// is a shell script. The runner and the written program join the step's inputs. -// `name` is used as a file name; anything but letters, digits, `-` and `.` -// becomes `_`. +// A step whose work is file operations, alone or around commands (0.25.0; the +// bundle's refresh from 0.27.0): a step program (`mcpp.tools.steps`) written +// into `/dist-apple/steps/`, so no step is a shell script. The runner +// and the written program join the step's inputs. `name` is used as a file +// name; anything but letters, digits, `-` and `.` becomes `_`. inline void attach(step& s, const std::string& runner, const std::string& out_dir, const std::string& name, const mcpp::tools::steps::program& program) { std::string file = name; @@ -1300,16 +1300,14 @@ inline plan plan_for(options opt = {}) { } } - // The runner `steps`, this package's program (0.27.0), runs the steps of - // more than one command: a framework's copy and signature, and a disk - // image's staging. Asked for only when the plan has one. + // The runner `steps`, this package's program (0.27.0), runs the step + // programs: a framework's copy and signature, a disk image's staging, and + // the bundle's refresh, which every plan has. The feature that carries the + // runner is active wherever this member is, so asking costs nothing. namespace steps = mcpp::tools::steps; - std::string runner; - if (!frameworks.empty() || dmg) { - runner = steps::runner(); - if (runner.empty()) - return refuse(p, "no step runner", steps::missing_runner("mcpp.dist.apple") + "\n So this plan bundles nothing."); - } + const std::string runner = steps::runner(); + if (runner.empty()) + return refuse(p, "no step runner", steps::missing_runner("mcpp.dist.apple") + "\n So this plan bundles nothing."); // THE FRAMEWORKS: each copied from the staged tree and, when the bundle is // signed, signed before the bundle is -- a bundle signature seals nested @@ -1441,16 +1439,18 @@ inline plan plan_for(options opt = {}) { // stamp included, when it ran, so the bundle is not the terminal until // signing (the last thing that can still fail) has happened. A directory // is an acceptable action output (the engine verifies `is_regular_file - // || is_directory`); `touch` has nothing to write, only a mtime to + // || is_directory`); the step has nothing to write, only a mtime to // refresh, and refreshing it is what makes ninja record the edge as run - // rather than replay a stale one. + // rather than replay a stale one. The refresh is the step operation + // `touch` (0.27.0) rather than `/usr/bin/touch`: an operation the + // collection performs itself needs no program at a fixed place on the host. step bundle; bundle.id = "mcpp.dist.apple.bundle"; bundle.role = "artifact"; bundle.description = "APP BUNDLE"; - bundle.argv = { "/usr/bin/touch", bundlePath }; - bundle.inputs = assembled; - bundle.outputs = { bundlePath }; + bundle.inputs = assembled; + attach(bundle, runner, opt.out_dir, "bundle", steps::program{}.touch(bundlePath)); + bundle.outputs = { bundlePath }; p.steps.push_back(bundle); // `--format dmg`: the bundle beside an `Applications` link, then the image. diff --git a/tests/app-framework-consumer/check-apple-plan.sh b/tests/app-framework-consumer/check-apple-plan.sh index f033296..1e5b0f1 100755 --- a/tests/app-framework-consumer/check-apple-plan.sh +++ b/tests/app-framework-consumer/check-apple-plan.sh @@ -168,6 +168,9 @@ if fw["outputs"][0] not in sign["inputs"]: bundle = actions.get("mcpp.dist.apple.bundle") if not bundle or sign["outputs"][0] not in bundle["inputs"]: fail("the bundle step does not follow the signature") +bp = program(bundle) +if [(o["kind"], o["a"]) for o in bp] != [("touch", bundle["outputs"][0])]: + fail("the bundle step does not refresh the bundle with the step operation touch: " + repr(bp)) if any(k.startswith("mcpp.dist.apple.dmg") for k in actions): fail("--format app planned a disk image") if "mcpp:link-flag=-Wl,-rpath,@executable_path/../Frameworks" not in lines: @@ -175,7 +178,7 @@ if "mcpp:link-flag=-Wl,-rpath,@executable_path/../Frameworks" not in lines: if "mcpp:runner-named=app:macapp-run" not in lines: fail("the app runner was not supplied") ' -echo "ok: the program, not the tree's entry script, is the bundle executable; the dylib is a framework signed ad hoc, not a resource; the bundle is signed after it; the rpath and the runner are declared" +echo "ok: the program, not the tree's entry script, is the bundle executable; the dylib is a framework signed ad hoc, not a resource; the bundle is signed after it and refreshed by a step; the rpath and the runner are declared" echo "== --format dmg on macOS ==" run_program dmg macos "" "$stage" /tmp/apple-plan-dmg.log diff --git a/tests/ios-app-consumer/check-ios-plan.sh b/tests/ios-app-consumer/check-ios-plan.sh index d5992cc..4c618b3 100755 --- a/tests/ios-app-consumer/check-ios-plan.sh +++ b/tests/ios-app-consumer/check-ios-plan.sh @@ -49,6 +49,9 @@ check_terminal_bundle() { || fail "the bundle step does not declare exactly one output" "$log" echo "$bundle_out" | grep -q '\.app"$' \ || fail "the bundle step's own output is not the .app directory" "$log" + # The bundle is refreshed by a step program (0.27.0), not `/usr/bin/touch`. + grep -qE '"command":\["/plan-check/tool-store/bin/steps","[^"]*/bundle\.steps"\]' <<<"$bundle_line" \ + || fail "the bundle step is not a step program run by the runner" "$log" local bundle_inputs bundle_inputs=$(quoted_inputs "$bundle_line") for other_id in mcpp.dist.apple.info-plist mcpp.dist.apple.layout \ @@ -109,7 +112,11 @@ run_row() { > "$stage/ios-app-consumer" fi out=$(mktemp -d) + # The runner of the step programs (0.27.0, `steps`), which the engine hands + # a build program through `tools-steps`' tool: the bundle step is one, and + # a plan names the runner without running it, so the path is enough. env -i PATH="$PATH" \ + MCPP_DEP_MCPP_PLUGINS_BIN_STEPS=/plan-check/tool-store/bin/steps \ MCPP_PACK_FORMAT=app \ MCPP_TARGET_OS="$os" \ MCPP_TARGET_ENV="$envv" \ From cf262abd629f776a78205f4b6ff68d05cc4083f8 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Thu, 19 Nov 2026 19:18:36 +0900 Subject: [PATCH 3/4] 0.27.0: xim:cmake stays only on the members that run CMake dist-apk and dist-apple no longer declare xim:cmake: their step programs run with the collection's runner, which tools-steps carries, so a pack downloads no CMake. deps-cmake and deps-archive keep it, since each runs cmake itself: to configure and build a subproject, and as `cmake -E tar` to extract an archive. The cross-host dist-apk step says that its javac, d8 and libs steps run without a shell or xim:cmake. --- .github/workflows/ci.yml | 7 ++++--- mcpp.toml | 8 -------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a81678..e1acfc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2626,12 +2626,13 @@ jobs: # dist-apk ON A HOST THAT IS NOT LINUX (0.24.0). Every tool the member # runs is a native program (`aapt2`, `zipalign`) or a jar on the JDK's # `java`, and each step of more than one command is a step program - # (0.25.0, `tools-steps`), so no step needs a shell and a Windows host + # (0.25.0, `tools-steps`), run from 0.27.0 by the collection's own + # runner, so no step needs a shell or `xim:cmake` and a Windows host # packs what a Linux host does. On Windows the NDK's # libc++ module sources come from `xim:android-ndk-libcxx-modules`, # which `xim:android-ndk`'s windows entry depends on. The criteria are the # level-0 step's on the Linux job, plus a level-1 package whose dex holds - # the activity: that is the javac, d8 and libs scripts all having run. + # the activity: that is the javac, d8 and libs steps all having run. - name: dist-apk packs a signed APK on this host, level 0 and level 1 if: ${{ !cancelled() }} working-directory: tests/apk-consumer @@ -2674,7 +2675,7 @@ jobs: grep -q "org.mcpp.apkconsumer.$c;" dexdump.log \ || { echo "FAIL: the dex does not hold org.mcpp.apkconsumer.$c"; exit 1; } done - echo "ok: level 1 -- the javac, d8 and libs scripts ran on this host, and the dex holds the activity and the generated class" + echo "ok: level 1 -- the javac, d8 and libs steps ran on this host, and the dex holds the activity and the generated class" - name: the rule declared its own compiler working-directory: tests/spirv-consumer diff --git a/mcpp.toml b/mcpp.toml index a5b9464..64ffae7 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -666,10 +666,6 @@ mcpplibs.os = "0.4.5" # "run"` keeps a build or a pack from installing it. [target.'cfg(os = "macos")'.feature-xlings.dist-apple] "xim:macapp-run" = { version = "0.1.0", when = "run" } -# `xim:cmake` runs the bundle's steps of more than one command (0.25.0, -# `tools-steps`, until mcpp#955), asked for only when a plan copies a -# framework or stages a disk image. -"xim:cmake" = { version = ">=3.31", provision = "on-request" } # THE iOS DEVICE ROW'S RUNNER (0.11.0), `devicectl-run`, which installs a signed # bundle on a connected device and launches it. The simulator row keeps the @@ -727,10 +723,6 @@ mcpplibs.os = "0.4.5" # mcpp#755): the member requests it while planning a bundle, so an ordinary # `--format apk` build installs nothing for it. "xim:bundletool" = { version = "1.18.3", provision = "on-request" } -# `xim:cmake` RUNS THE STEPS OF MORE THAN ONE COMMAND (0.25.0, `tools-steps`), -# the backend until the engine runs step programs itself (mcpp#955), so no step -# needs a shell on any host. Asked for when a package is planned. -"xim:cmake" = { version = ">=3.31", provision = "on-request" } # The compiler `options::kotlin_sources` needs, and the resolver `options::maven` # needs, each behind its own feature (see `[features.dist-apk-kotlin]`). The From 2d2d1d88de57118cf111ab398f365efbe183a82b Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Thu, 19 Nov 2026 19:20:55 +0900 Subject: [PATCH 4/4] 0.27.0: the package needs mcpp 2026.11.19.1, and the documents describe the runner The package floor is mcpp 2026.11.19.1, the release that gives a feature's `tools` to every build program that links the package with the feature active (SPEC-007 R6.3), which is how tools-steps brings its runner; CI's MCPP_VERSION names it. tools-steps, dist-apk and dist-apple state that floor in the member table. docs/tools-steps.md describes the runner, the step file format, the semantics it keeps from the CMake backend of 0.25.0 and 0.26.0 and the three details in which it differs, and states that mcpp-community/mcpp#955 was answered by a feature carrying the package's own program rather than by the engine running step programs. dist-apk and dist-apple no longer name xim:cmake or options::cmake; rule 5 of the plugin conventions admits a program of the plugin's own package that its feature declares as a tool; the tool-sources table lists the runner. --- .github/workflows/ci.yml | 10 ++++++++- README.md | 31 ++++++++++++++++----------- docs/dist-apk.md | 7 +++--- docs/dist-apple.md | 2 +- docs/plugin-development.md | 17 +++++++++------ docs/tool-sources.md | 1 + docs/tools-steps.md | 32 +++++++++++++++++++++++----- mcpp.toml | 14 +++++++----- src/plugins.cppm | 2 +- tests/steps-consumer/probe/mcpp.toml | 7 +++--- tools/README.md | 9 ++++++-- tools/steps_main.cpp | 3 ++- 12 files changed, 93 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1acfc7..d8da09e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,15 @@ env: # older engine, and docs/deps.md states the requirement where cross builds # are described. So here, as for 0.20.0's SYCL lane, `MCPP_VERSION` is the # newest engine a lane needs and the floor the oldest the collection loads on. - MCPP_VERSION: 2026.11.7.1 + # + # 2026.11.19.1 IS WHAT 0.27.0 NEEDS, and the package floor states it + # (mcpp#955, SPEC-007 R6.3): a feature's `tools` reaches every build program + # that links this package with the feature active, which is how + # `tools-steps` brings its runner `steps` to `dist-apk`, `dist-apple` and + # tests/steps-consumer. Until that release exists the jobs fetch + # `MCPP_BOOTSTRAP`, which the floor refuses, unless `mcpp_source_ref` names + # the engine to build. + MCPP_VERSION: 2026.11.19.1 # THE RELEASE EVERY JOB FETCHES, WHICH IS NOT ALWAYS THE ONE UNDER TEST. # # `MCPP_VERSION` states the engine this collection's lanes need -- the package diff --git a/README.md b/README.md index 41df098..de5b5c6 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ module name the member declares, and configures it there. ```toml [build-dependencies.mcpp] -plugins = { version = "0.26.0", features = ["rules-spirv"], host-module = true } +plugins = { version = "0.27.0", features = ["rules-spirv"], host-module = true } ``` ```cpp @@ -51,13 +51,15 @@ naming it to avoid a download, and the scenarios on both sides -- is in ## Members -From 0.21.0 the package as a whole needs mcpp 2026.10.30.1 (`[package] mcpp`), -which writes the configuration's contract that `deps-cmake` compiles a cross -build from (0.20.0 needed 2026.10.27.1, whose protocol 17 states a platform's -fields and whose `mcpp pack` writes `mcpp-package.json` beside every staged -tree; 0.19.0 needed 2026.10.1.3, whose -protocol 15 states where each tool and payload comes from); the column states -the release each member's behaviour first needed. +From 0.27.0 the package as a whole needs mcpp 2026.11.19.1 (`[package] mcpp`), +which gives a feature's tool to every build program that links the package with +the feature active, the way `tools-steps` brings its runner (0.21.0 needed +2026.10.30.1, which writes the configuration's contract that `deps-cmake` +compiles a cross build from; 0.20.0 needed 2026.10.27.1, whose protocol 17 +states a platform's fields and whose `mcpp pack` writes `mcpp-package.json` +beside every staged tree; 0.19.0 needed 2026.10.1.3, whose protocol 15 states +where each tool and payload comes from); the column states the release each +member's behaviour first needed. Cross CMake subprojects that link executables or shared libraries require mcpp 2026.11.7.1 or later; cross configuration requires CMake 3.19 or later. @@ -75,14 +77,14 @@ mcpp 2026.11.7.1 or later; cross configuration requires CMake 3.19 or later. | `rules-sycl` | `mcpp.rules.sycl` | 2026.10.1.3 | Compiles SYCL (`*.sycl`) with DPC++. | [rules](docs/rules.md#rules-sycl) | | `tools-embed` | `mcpp.tools.embed` | 2026.9.5.4 | Writes a data file into a header the program compiles in. | [tools-embed](docs/tools-embed.md) | | `tools-island` | `mcpp.tools.island` | 2026.9.7.1 | Generates the `extern "C"` boundary and the C++ module of a code island. | [tools-island](docs/tools-island.md) | -| `tools-steps` | `mcpp.tools.steps` | 2026.10.1.3 | Describes an action whose work is more than one command as portable operations a backend runs; implied by `dist-apk` and `dist-apple`. | [tools-steps](docs/tools-steps.md) | +| `tools-steps` | `mcpp.tools.steps` | 2026.11.19.1 | Describes an action whose work is more than one command as portable operations, which `steps`, the collection's own runner, performs; implied by `dist-apk` and `dist-apple`. | [tools-steps](docs/tools-steps.md) | | `dist-appimage` | `mcpp.dist.appimage` | 2026.10.1.3 | Turns the tree `mcpp pack` stages into an AppImage (Linux). | [dist](docs/dist.md#dist-appimage) | | `dist-deb` | `mcpp.dist.deb` | 2026.10.30.1 | Installs the staged tree under `/opt/` with a launcher, a desktop entry and an icon, as a Debian package (Linux targets). | [dist](docs/dist.md#dist-deb-and-dist-rpm) | | `dist-rpm` | `mcpp.dist.rpm` | 2026.10.30.1 | The same installation as an RPM package (Linux targets). | [dist](docs/dist.md#dist-deb-and-dist-rpm) | | `dist-wix` | `mcpp.dist.wix` | 2026.10.1.3 | Builds an MSI of the staged tree, and a Burn bundle chaining it (Windows). | [dist](docs/dist.md#dist-wix) | -| `dist-apple` | `mcpp.dist.apple` | 2026.9.14.2 | Lays out a macOS or iOS application bundle, signs it and writes a disk image. | [dist-apple](docs/dist-apple.md) | +| `dist-apple` | `mcpp.dist.apple` | 2026.11.19.1 | Lays out a macOS or iOS application bundle, signs it and writes a disk image. | [dist-apple](docs/dist-apple.md) | | `dist-web` | `mcpp.dist.web` | 2026.9.13.1 | Copies a `wasm32-emscripten` program and its files into a web directory with an `index.html`. | [dist](docs/dist.md#dist-web) | -| `dist-apk` | `mcpp.dist.apk` | 2026.10.1.3 | Packs the native closure into a signed APK or App Bundle, with Java, Kotlin and Maven libraries. | [dist-apk](docs/dist-apk.md) | +| `dist-apk` | `mcpp.dist.apk` | 2026.11.19.1 | Packs the native closure into a signed APK or App Bundle, with Java, Kotlin and Maven libraries. | [dist-apk](docs/dist-apk.md) | | `deps-vcpkg` | `mcpp.deps.vcpkg` | 2026.10.1.3 | Installs a `vcpkg.json` manifest as an action with the toolset mcpp resolved, and maps the prefix into the build. | [deps](docs/deps.md#deps-vcpkg) | | `deps-cmake` | `mcpp.deps.cmake` | 2026.10.1.3; a cross build 2026.10.30.1 | Builds and installs a CMake subproject as an action with Ninja and the toolset mcpp resolved -- for another target, the compilers and words of the engine's contract -- keeps the installation for any build with the same key, and maps the prefix into the build. | [deps](docs/deps.md#deps-cmake) | | `deps-archive` | `mcpp.deps.archive` | 2026.10.1.3 | Extracts a zip archive the project keeps and places its tree beside the program. | [deps](docs/deps.md#deps-archive) | @@ -118,8 +120,9 @@ declaration (0.15.0 removed `rules-qt-xim*`; see [rules-qt](docs/rules-qt.md)). ``` mcpp.toml the package: one feature per member src/plugins.cppm export module mcpp.plugins; the version, mcpp::plugins::surface - (the declarations a consumer names), mcpp::plugins::xml and - mcpp::plugins::package (a staged package's metadata) + (the declarations a consumer names), mcpp::plugins::xml, + mcpp::plugins::package (a staged package's metadata) and + mcpp::plugins::steps (the step file the runner reads) src/declare.cppm, the general library for build programs (`plugins-core`): src/toolset.cppm, mcpp.plugins.declare, mcpp.plugins.toolset, mcpp.plugins.fs src/fs.cppm @@ -129,6 +132,8 @@ src/compat/, deps/compat/ compatibility units, each retired on the date its header states rules/.cppm export module mcpp.rules.; tools/.cppm export module mcpp.tools.; +tools/_main.cpp the package's programs: `steps`, the runner `tools-steps` + carries, and `mcpp-embed` dist/.cppm export module mcpp.dist.; deps/.cppm export module mcpp.deps.; deps/deps.cppm is shared tests// one project per member, built by CI with the pinned mcpp diff --git a/docs/dist-apk.md b/docs/dist-apk.md index 7097b0c..5163db2 100644 --- a/docs/dist-apk.md +++ b/docs/dist-apk.md @@ -6,7 +6,7 @@ Module `mcpp.dist.apk`; engine floor: 2026.10.1.3 from 0.19.0 (mcpp#755), whose protocol 15 states where a tool comes from and installs `xim:bundletool` only when a bundle asks for it; 2026.9.14.2 from 0.10.0, which stages the closure this member reads; before it 2026.9.13.1, raised alongside `dist-web` in the same 0.9.0 release: this member's own manifest-template and Java-array changes ask nothing new of the engine, but this collection publishes one package at one version, and this is the release CI verifies it under from here on. -**Needs and behaviour.** `xim:android-build-tools`, `xim:android-platform` (versioned by API level, read back for `targetSdkVersion`), `xim:jdk-temurin` (`java`/`javac`/`jar`/`jarsigner`; `android-build-tools`' own runtime dependency provisions a JDK for its OWN wrappers only), `xim:android-debug-keystore`, `xim:bundletool` (0.10.0, for `--format aab`), `xim:cmake` (0.25.0, asked for when a package is planned: the runner of the steps of more than one command until mcpp-community/mcpp#955), all on the `cfg(env = "android")` axis. Generates `AndroidManifest.xml` and signs with the published Android debug key by default. Level 0 needs no Java (`hasCode="false"`, `android.app.NativeActivity`); `options::java_sources` adds `javac` + `d8` and a real ``. `options::manifest_template` renders a project manifest with six tokens substituted verbatim; `{{application_id}}` and `{{activity}}` are required always and `{{lib_name}}` at level 0, each refused by name at plan time when missing (naming `assets/mcpp-run.json`, which `adb-run` reads them from too) or when the template names an unknown token; empty renders 0.8.0's manifest byte-identically. From 0.9.3 the manifest template gains `{{version_name}}` / `{{version_code}}` (the package version, and `major * 1000000 + minor * 1000 + patch`). `options::resources` is a project's own `res/`, linked as the application's base resources from 0.9.1 (0.9.0 linked it as an aapt2 overlay, which refuses every resource the base does not already define -- a launcher icon could not be supplied). `options::java_sources` is an array: one `javac` over every root's `.java` files and one `d8` over the result, so a project's own sources and a path dependency's join without being merged into one directory first, and `rerun_if_changed_glob` is declared only for a root under `mcpp::manifest_dir()` -- a dependency root's files are already inputs of the `javac` action and its version is already in the build's fingerprint. Android only -- an `app` target is a shared object on this row (#622 A3). From 0.10.0, with mcpp 2026.9.14.2, the member reads the native closure the engine stages -- the application object, the graph's shared libraries and `libc++_shared.so` under `lib/` for one `--target`, `lib//` for several -- and packs every ABI the tree carries into one APK; its own `NEEDED` walk and the stamp that lost a dependency's library on a second pack are gone. A stage manifest without `needs` lines comes from an engine below 2026.9.14.2 and is refused naming that floor, as is an incomplete closure, naming the unresolved libraries; every refusal is also a `mcpp::warning`, because the engine discards a build program's output when it exits 0. `--format aab` shares every step but the last three: `aapt2 link --proto-format` (with `--version-code` / `--version-name`, which bundletool requires), a base module in the layout bundletool reads, `bundletool build-bundle` from `xim:bundletool` (declared on the same axis), and `jarsigner` with the same keystore. CI packages both level 0 and level 1 and checks the archive (`mcpp::deploy`'d files under `assets/`), and on `tests/apk-consumer-shared` two packs in a row, a two-ABI APK (`aapt2` reports both, `apksigner` verifies it), an App Bundle (`bundletool validate`, `jarsigner -verify`, a universal APK from `bundletool build-apks`), a refusal's reason in `mcpp pack`'s output, and the floor refusal; the runner has no emulator or device, so the two rows that actually run were measured locally on 2026-09-12, through `adb-run`, against a KVM-accelerated x86_64 emulator and a physical arm64-v8a phone, both printing `1-2-3` and exiting 0. From 0.11.0: Kotlin sources (`dist-apk-kotlin`, which declares `xim:kotlin`), R classes, Android libraries from source, local AARs and JARs, a Maven graph through a lock file (`dist-apk-maven`, which declares `xim:coursier`), a manifest merge, and an unsigned package -- see [`dist-apk`: Kotlin, libraries and a Maven graph](#dist-apk-kotlin-libraries-and-a-maven-graph). From 0.11.1 the native libraries are packed as the Android Gradle plugin packs them: each is stripped with the build's own `llvm-strip --strip-unneeded` (the NDK's, beside the compiler `mcpp::toolchain_dir()` reports; `options::keep_debug_symbols` packs them as staged), and a manifest stating `android:extractNativeLibs="false"` gets them stored uncompressed on a 16 KB page, which loading them from the APK in place requires; CI checks both, and the symbol table `keep_debug_symbols` keeps. From 0.12.0 the engine's strip decision governs these libraries as well: under mcpp 2026.9.16.1, which publishes it to build programs as `MCPP_PACK_STRIP` and `MCPP_PACK_DEBUG_SYMBOLS_DIR`, that engine strips and separates the libraries it stages itself and the member packs them as staged, while the libraries the engine did not stage -- an archive's `jni/` libraries -- follow the same decision inside the member: `--no-strip` packs them as they are, and `--debug-symbols ` separates each one's debug information into `//.debug` with `llvm-objcopy` before stripping it and linking the packed copy to that file (`.gnu_debuglink`). A library is stripped unless either `keep_debug_symbols` or the engine says to keep it, and under an older engine, which publishes neither variable, the member strips every library as before. Because that engine strips before the member reads the tree, `keep_debug_symbols` keeps only the member's own strip off and `--no-strip` is what ships the symbols of the libraries the graph built; the member warns when the option is set and the engine stripped. From 0.12.0 a library in the resolved graph contributes libraries and archives through `[package.metadata.dist-apk]`, ranked below the application's own -- see [A library states its contribution](#a-library-states-its-contribution-packagemetadatadist-apk). From 0.23.1 a Java or Kotlin root inside the build's output (`mcpp::out_dir()`, `target/`), which a build program generated, is an input of the `javac` action and declares no re-run glob, which could never match there. From 0.24.0 the member runs on Windows and macOS hosts as on Linux: `d8`, `apksigner`, bundletool, the Kotlin compiler and coursier run from their jars on the JDK's `java`, and the four `/bin/sh` helpers are one Java source file, `DistApk.java`, run by that `java`. From 0.25.0 those four steps are step programs (`tools-steps`): the member describes each and a runner runs it, `cmake -P` until mcpp runs them itself (mcpp-community/mcpp#955); `DistApk.java` is gone, and `options::cmake` names another `cmake`. From 0.26.0 the `javac` and `kotlinc` steps empty their class directories first, so a source that left the package, such as a library no longer in the graph, leaves no class in the next package. +**Needs and behaviour.** `xim:android-build-tools`, `xim:android-platform` (versioned by API level, read back for `targetSdkVersion`), `xim:jdk-temurin` (`java`/`javac`/`jar`/`jarsigner`; `android-build-tools`' own runtime dependency provisions a JDK for its OWN wrappers only), `xim:android-debug-keystore`, `xim:bundletool` (0.10.0, for `--format aab`), all on the `cfg(env = "android")` axis, and the runner of its step programs, `steps`, which [`tools-steps`](tools-steps.md) carries (0.27.0). Generates `AndroidManifest.xml` and signs with the published Android debug key by default. Level 0 needs no Java (`hasCode="false"`, `android.app.NativeActivity`); `options::java_sources` adds `javac` + `d8` and a real ``. `options::manifest_template` renders a project manifest with six tokens substituted verbatim; `{{application_id}}` and `{{activity}}` are required always and `{{lib_name}}` at level 0, each refused by name at plan time when missing (naming `assets/mcpp-run.json`, which `adb-run` reads them from too) or when the template names an unknown token; empty renders 0.8.0's manifest byte-identically. From 0.9.3 the manifest template gains `{{version_name}}` / `{{version_code}}` (the package version, and `major * 1000000 + minor * 1000 + patch`). `options::resources` is a project's own `res/`, linked as the application's base resources from 0.9.1 (0.9.0 linked it as an aapt2 overlay, which refuses every resource the base does not already define -- a launcher icon could not be supplied). `options::java_sources` is an array: one `javac` over every root's `.java` files and one `d8` over the result, so a project's own sources and a path dependency's join without being merged into one directory first, and `rerun_if_changed_glob` is declared only for a root under `mcpp::manifest_dir()` -- a dependency root's files are already inputs of the `javac` action and its version is already in the build's fingerprint. Android only -- an `app` target is a shared object on this row (#622 A3). From 0.10.0, with mcpp 2026.9.14.2, the member reads the native closure the engine stages -- the application object, the graph's shared libraries and `libc++_shared.so` under `lib/` for one `--target`, `lib//` for several -- and packs every ABI the tree carries into one APK; its own `NEEDED` walk and the stamp that lost a dependency's library on a second pack are gone. A stage manifest without `needs` lines comes from an engine below 2026.9.14.2 and is refused naming that floor, as is an incomplete closure, naming the unresolved libraries; every refusal is also a `mcpp::warning`, because the engine discards a build program's output when it exits 0. `--format aab` shares every step but the last three: `aapt2 link --proto-format` (with `--version-code` / `--version-name`, which bundletool requires), a base module in the layout bundletool reads, `bundletool build-bundle` from `xim:bundletool` (declared on the same axis), and `jarsigner` with the same keystore. CI packages both level 0 and level 1 and checks the archive (`mcpp::deploy`'d files under `assets/`), and on `tests/apk-consumer-shared` two packs in a row, a two-ABI APK (`aapt2` reports both, `apksigner` verifies it), an App Bundle (`bundletool validate`, `jarsigner -verify`, a universal APK from `bundletool build-apks`), a refusal's reason in `mcpp pack`'s output, and the floor refusal; the runner has no emulator or device, so the two rows that actually run were measured locally on 2026-09-12, through `adb-run`, against a KVM-accelerated x86_64 emulator and a physical arm64-v8a phone, both printing `1-2-3` and exiting 0. From 0.11.0: Kotlin sources (`dist-apk-kotlin`, which declares `xim:kotlin`), R classes, Android libraries from source, local AARs and JARs, a Maven graph through a lock file (`dist-apk-maven`, which declares `xim:coursier`), a manifest merge, and an unsigned package -- see [`dist-apk`: Kotlin, libraries and a Maven graph](#dist-apk-kotlin-libraries-and-a-maven-graph). From 0.11.1 the native libraries are packed as the Android Gradle plugin packs them: each is stripped with the build's own `llvm-strip --strip-unneeded` (the NDK's, beside the compiler `mcpp::toolchain_dir()` reports; `options::keep_debug_symbols` packs them as staged), and a manifest stating `android:extractNativeLibs="false"` gets them stored uncompressed on a 16 KB page, which loading them from the APK in place requires; CI checks both, and the symbol table `keep_debug_symbols` keeps. From 0.12.0 the engine's strip decision governs these libraries as well: under mcpp 2026.9.16.1, which publishes it to build programs as `MCPP_PACK_STRIP` and `MCPP_PACK_DEBUG_SYMBOLS_DIR`, that engine strips and separates the libraries it stages itself and the member packs them as staged, while the libraries the engine did not stage -- an archive's `jni/` libraries -- follow the same decision inside the member: `--no-strip` packs them as they are, and `--debug-symbols ` separates each one's debug information into `//.debug` with `llvm-objcopy` before stripping it and linking the packed copy to that file (`.gnu_debuglink`). A library is stripped unless either `keep_debug_symbols` or the engine says to keep it, and under an older engine, which publishes neither variable, the member strips every library as before. Because that engine strips before the member reads the tree, `keep_debug_symbols` keeps only the member's own strip off and `--no-strip` is what ships the symbols of the libraries the graph built; the member warns when the option is set and the engine stripped. From 0.12.0 a library in the resolved graph contributes libraries and archives through `[package.metadata.dist-apk]`, ranked below the application's own -- see [A library states its contribution](#a-library-states-its-contribution-packagemetadatadist-apk). From 0.23.1 a Java or Kotlin root inside the build's output (`mcpp::out_dir()`, `target/`), which a build program generated, is an input of the `javac` action and declares no re-run glob, which could never match there. From 0.24.0 the member runs on Windows and macOS hosts as on Linux: `d8`, `apksigner`, bundletool, the Kotlin compiler and coursier run from their jars on the JDK's `java`, and the four `/bin/sh` helpers are one Java source file, `DistApk.java`, run by that `java`. From 0.25.0 those four steps are step programs (`tools-steps`): the member describes each and a runner runs it, `cmake -P` of `xim:cmake` in 0.25.0 and 0.26.0, where `options::cmake` named another `cmake`; `DistApk.java` is gone. From 0.26.0 the `javac` and `kotlinc` steps empty their class directories first, so a source that left the package, such as a library no longer in the graph, leaves no class in the next package. From 0.27.0 the runner is the collection's own program `steps`, which `tools-steps` carries to the build program (mcpp 2026.11.19.1), and the member declares no `xim:cmake` and has no `options::cmake`: mcpp-community/mcpp#955 asked the engine to run step programs, and the engine instead lets a feature carry its package's own program. ## `dist-apk`: Kotlin, libraries and a Maven graph @@ -87,8 +87,9 @@ Anything beyond that belongs in the project's `manifest_template`. Kotlin compiler, coursier), and from 0.25.0 each step of more than one command (javac or kotlinc with its stamp, d8 over the classes it finds, the archive gaining its libraries, assets and dex, an App Bundle's base module) is a step -program ([`tools-steps`](tools-steps.md)), so no step needs a shell and a Windows -host packs what a Linux host does. CI packs level 0 and level 1 on Linux, macOS and Windows hosts; +program ([`tools-steps`](tools-steps.md)), run from 0.27.0 by the collection's +own runner, so no step needs a shell and a Windows host packs what a Linux host +does. CI packs level 0 and level 1 on Linux, macOS and Windows hosts; the Kotlin, library, bundle and Maven criteria run on Linux. On Windows the NDK's libc++ module sources come from `xim:android-ndk-libcxx-modules`, which `xim:android-ndk`'s windows entry depends on. diff --git a/docs/dist-apple.md b/docs/dist-apple.md index 68d8848..798b2cf 100644 --- a/docs/dist-apple.md +++ b/docs/dist-apple.md @@ -6,7 +6,7 @@ Module `mcpp.dist.apple`; engine floor: 2026.9.14.2 (0.10.0); 2026.9.11.2 (macOS) and 2026.9.12.3 (iOS) before it. -**Needs and behaviour.** the base macOS install (`ditto`, `codesign`, `hdiutil`), `xim:macapp-run` for `mcpp run` on macOS, which this feature declares with `when = "run"`, and `xim:cmake` (0.25.0), asked for only when a plan copies a framework or stages a disk image: those steps are step programs ([`tools-steps`](tools-steps.md)), whose runner is `cmake` until mcpp runs them itself (mcpp-community/mcpp#955), and `options::cmake` names another `cmake`. macOS: `Contents/`-shaped, as always. iOS (`aarch64-ios-sim`, `aarch64-ios`): a flat bundle at the same call site -- no separate feature, no separate module -- with `MinimumOSVersion` from `mcpp::min_platform_version()` (#622 A11), `CFBundleSupportedPlatforms` read from `env == "sim"`, `UIDeviceFamily`, `LSRequiresIPhoneOS`, and a directory of flat PNGs listed under `CFBundleIcons` in place of macOS's single `.icns` file. Signing is skipped on the simulator row (`options::identity` is ignored, with a `mcpp::warning` naming why), and the device row signs only with an identity. The iOS row is measured end to end on `macos-15`: a real `mcpp build`, `mcpp pack --format app` and `mcpp run` against `aarch64-ios-sim`, through `xim:apple-simulator-tools`' `simctl-run`. **The macOS floor is one release higher than its siblings** and the reason is not this member: under 2026.9.11.1 `mcpp pack` staged before dispatching and let a staging failure fail the command, so on a Mach-O program -- which the built-in closure walk refuses, because it uses `LD_TRACE_LOADED_OBJECTS` and dyld answers that by running the program -- every dispatched format was unreachable, including one that reads no staged tree. 2026.9.11.2 makes staging a service to the provider. From 0.9.2 the staged tree's deployed files (`bin//...`, which the engine stages for a Mach-O program before the closure walk since the release for mcpp#630) land at the bundle's resource destination -- `Contents/Resources//...` on macOS, the bundle root on iOS -- and the launcher alone goes to the executable directory, so `CFBundleExecutable` names a file that is where it says. The iOS fixture declares `llvm.libcxx` and `llvm.compiler-rt-builtins` under `cfg(os = "ios")`, which is what an application that imports `std` on those rows declares. From 0.10.0, with mcpp 2026.9.14.2: the dylibs the engine stages beside a Mach-O program, which the stage manifest's `needs` lines name, go to `Contents/Frameworks/` (`Frameworks/` on iOS) and not to the resources; the program is linked with the rpath that finds them there (`@executable_path/../Frameworks`, `@executable_path/Frameworks` on iOS) through `mcpp::link_flag`, so no file is edited after the link; a macOS bundle without `options::identity` is signed ad hoc, frameworks first and the bundle second, which `codesign --verify --deep --strict` requires of a bundle that carries a framework; an incomplete closure is a `mcpp::warning` naming the unresolved libraries; every refusal is a `mcpp::warning` as well, because the engine discards a build program's output when it exits 0. On macOS the member supplies the runner named `app` (`macapp-run`), so `mcpp run --format app` runs the bundle's executable in the foreground and returns its status with no runner in the manifest; a manifest runner of that name wins. `--format dmg` stages the bundle beside an `Applications` link and writes a UDZO image with `hdiutil create` (`options::volume_name`, `options::dmg`); it is refused on iOS. An engine below 2026.9.14.2 stages no `needs` lines, so the bundle carries no framework, anchors the rpath to the package directory, and hands the bundle directory to the kernel under `mcpp run --format app` unless `--runner app` is typed. CI measures the bundle on `macos-15`: the load command, the signature, the program with and without its framework (exit 7, then "Library not loaded"), `mcpp run --format app` with and without `--runner app`, and `hdiutil verify` and an attached image. From 0.11.0: a project's own Info.plist entries (`options::info_plist`), an iOS device bundle's provisioning profile (`options::provisioning_profile`), and `devicectl-run` (`xim:apple-device-tools`) as the device row's runner named `app` -- see [`dist-apple`: a project's Info.plist, and an iOS device](#dist-apple-a-projects-infoplist-and-an-ios-device). From 0.12.0 `options::omit_keys` leaves out a key the member only defaults -- see [`dist-apple`: a project's Info.plist, and an iOS device](#dist-apple-a-projects-infoplist-and-an-ios-device). From 0.12.0 a package in the resolved graph contributes Info.plist entries through `[package.metadata.dist-apple]`, applied before the application's own +**Needs and behaviour.** the base macOS install (`ditto`, `codesign`, `hdiutil`), `xim:macapp-run` for `mcpp run` on macOS, which this feature declares with `when = "run"`, and the runner of its step programs, `steps`, which [`tools-steps`](tools-steps.md) carries (0.27.0): a framework's copy and signature, a disk image's staging and the bundle's refresh are step programs, so no step is a shell script. In 0.25.0 and 0.26.0 the runner was `cmake -P` of `xim:cmake`, asked for only when a plan copied a framework or staged a disk image, with `options::cmake` for another `cmake`, and the bundle was refreshed with `/usr/bin/touch`; mcpp-community/mcpp#955 asked the engine to run step programs, and mcpp 2026.11.19.1 instead lets the feature carry the collection's own runner. macOS: `Contents/`-shaped, as always. iOS (`aarch64-ios-sim`, `aarch64-ios`): a flat bundle at the same call site -- no separate feature, no separate module -- with `MinimumOSVersion` from `mcpp::min_platform_version()` (#622 A11), `CFBundleSupportedPlatforms` read from `env == "sim"`, `UIDeviceFamily`, `LSRequiresIPhoneOS`, and a directory of flat PNGs listed under `CFBundleIcons` in place of macOS's single `.icns` file. Signing is skipped on the simulator row (`options::identity` is ignored, with a `mcpp::warning` naming why), and the device row signs only with an identity. The iOS row is measured end to end on `macos-15`: a real `mcpp build`, `mcpp pack --format app` and `mcpp run` against `aarch64-ios-sim`, through `xim:apple-simulator-tools`' `simctl-run`. **The macOS floor is one release higher than its siblings** and the reason is not this member: under 2026.9.11.1 `mcpp pack` staged before dispatching and let a staging failure fail the command, so on a Mach-O program -- which the built-in closure walk refuses, because it uses `LD_TRACE_LOADED_OBJECTS` and dyld answers that by running the program -- every dispatched format was unreachable, including one that reads no staged tree. 2026.9.11.2 makes staging a service to the provider. From 0.9.2 the staged tree's deployed files (`bin//...`, which the engine stages for a Mach-O program before the closure walk since the release for mcpp#630) land at the bundle's resource destination -- `Contents/Resources//...` on macOS, the bundle root on iOS -- and the launcher alone goes to the executable directory, so `CFBundleExecutable` names a file that is where it says. The iOS fixture declares `llvm.libcxx` and `llvm.compiler-rt-builtins` under `cfg(os = "ios")`, which is what an application that imports `std` on those rows declares. From 0.10.0, with mcpp 2026.9.14.2: the dylibs the engine stages beside a Mach-O program, which the stage manifest's `needs` lines name, go to `Contents/Frameworks/` (`Frameworks/` on iOS) and not to the resources; the program is linked with the rpath that finds them there (`@executable_path/../Frameworks`, `@executable_path/Frameworks` on iOS) through `mcpp::link_flag`, so no file is edited after the link; a macOS bundle without `options::identity` is signed ad hoc, frameworks first and the bundle second, which `codesign --verify --deep --strict` requires of a bundle that carries a framework; an incomplete closure is a `mcpp::warning` naming the unresolved libraries; every refusal is a `mcpp::warning` as well, because the engine discards a build program's output when it exits 0. On macOS the member supplies the runner named `app` (`macapp-run`), so `mcpp run --format app` runs the bundle's executable in the foreground and returns its status with no runner in the manifest; a manifest runner of that name wins. `--format dmg` stages the bundle beside an `Applications` link and writes a UDZO image with `hdiutil create` (`options::volume_name`, `options::dmg`); it is refused on iOS. An engine below 2026.9.14.2 stages no `needs` lines, so the bundle carries no framework, anchors the rpath to the package directory, and hands the bundle directory to the kernel under `mcpp run --format app` unless `--runner app` is typed. CI measures the bundle on `macos-15`: the load command, the signature, the program with and without its framework (exit 7, then "Library not loaded"), `mcpp run --format app` with and without `--runner app`, and `hdiutil verify` and an attached image. From 0.11.0: a project's own Info.plist entries (`options::info_plist`), an iOS device bundle's provisioning profile (`options::provisioning_profile`), and `devicectl-run` (`xim:apple-device-tools`) as the device row's runner named `app` -- see [`dist-apple`: a project's Info.plist, and an iOS device](#dist-apple-a-projects-infoplist-and-an-ios-device). From 0.12.0 `options::omit_keys` leaves out a key the member only defaults -- see [`dist-apple`: a project's Info.plist, and an iOS device](#dist-apple-a-projects-infoplist-and-an-ios-device). From 0.12.0 a package in the resolved graph contributes Info.plist entries through `[package.metadata.dist-apple]`, applied before the application's own ## `dist-apple`: a project's Info.plist, and an iOS device diff --git a/docs/plugin-development.md b/docs/plugin-development.md index 7acb1bf..78b928f 100644 --- a/docs/plugin-development.md +++ b/docs/plugin-development.md @@ -22,7 +22,7 @@ mcpp is a general build engine with a framework for build plugins. Plugins come The level that decided is recorded with `mcpp::fact`. What a plugin returns (a prefix, an SDK root, the deployed files) is its extension point: `build.mcpp` may declare its own actions over it. 4. **The runtime closure belongs to the package that ships the binaries.** A payload whose libraries load others carries or declares them on every platform, so a packed program starts on a machine with only its operating system. A plugin names the payload's library directories as runtime search directories and nothing beyond them. -5. **Internals are not part of the contract.** The contract is the set of feature names, `options` fields, returned types and documented environment variables. A consumer's manifest names no program the plugin uses internally. An action's command is the tool itself (`vcpkg`, or `cmake -P` over a script the plugin writes), or a step program for work of more than one command (`mcpp.tools.steps`), never a helper program built from the plugin's package and never a shell script, which a Windows host cannot start. +5. **Internals are not part of the contract.** The contract is the set of feature names, `options` fields, returned types and documented environment variables. A consumer's manifest names no program the plugin uses internally. An action's command is the tool itself (`vcpkg`, or `cmake -P` over a script the plugin writes); a program of the plugin's own package that the feature using it declares as its tool (`[features.] tools = [""]`), which the engine builds for the machine that builds and gives to every build program that links the package with the feature active, so no consumer names it (mcpp 2026.11.19.1, SPEC-007 R6.3); or a step program for work of more than one command (`mcpp.tools.steps`), which this package's runner `steps` performs that way (0.27.0). It is never a shell script, which a Windows host cannot start. 6. **Work is an action.** Installation, extraction and generation are actions with declared inputs and outputs (SPEC-007 R1.1, R3). A build program plans, and `mcpp emit build-database` never installs. 7. **Absence is a warning.** A missing tool or SDK is a `mcpp::warning`, and the plan states every path it can (R1.2). A plan never depends on what an action produced (R1.3). 8. **Engine gaps are reported, not patched.** A capability the engine lacks is filed as an mcpp issue. A workaround that already exists is recorded in the plugin's documentation with the issue number and is removed when the engine provides the capability. @@ -52,7 +52,7 @@ mcpp-index refuses such a package. ```toml [build-dependencies.mcpp] -plugins = { version = "0.26.0", features = ["plugins-core"], host-module = true, reexport = true } +plugins = { version = "0.27.0", features = ["plugins-core"], host-module = true, reexport = true } ``` `reexport = true` is needed when the plugin's consumers import L2 modules in @@ -60,10 +60,13 @@ their own build programs. **The engine floor.** A plugin states the first mcpp release it needs in `[package] mcpp = ">="`; an older engine stops before any other work -and names the upgrade. This package's floor is 2026.10.27.1, the release that -speaks protocol 17 (the platform's directives and the `platform` phase, mcpp -SPEC-013) and writes `mcpp-package.json` beside every staged tree (SPEC-014); -it carries protocol 15, which states where each tool and payload comes from. +and names the upgrade. This package's floor is 2026.11.19.1 (0.27.0), the +release that gives a feature's tool to every build program that links the +package with the feature active (SPEC-007 R6.3), which is how `tools-steps` +brings its runner, and that speaks protocol 20. It carries protocol 17 (the +platform's directives and the `platform` phase, mcpp SPEC-013, and +`mcpp-package.json` beside every staged tree, SPEC-014) and protocol 15, which +states where each tool and payload comes from. **Where a member's tool comes from.** A member that runs a program resolves it through `mcpp.plugins.tool`, which answers in one order for every member: @@ -220,7 +223,7 @@ A project's own plugin is a module in the project (a path dependency with `host- ## Optional action progress -`mcpp.plugins.progress` is part of `plugins-core`. `enable(action, requested)` sets the optional action flag when the engine API provides it. With older APIs it reports that telemetry is unavailable and leaves the action usable. Engine support starts at mcpp 2026.11.5.1 (protocol 18); this optional path does not raise the package's 2026.10.30.1 floor. +`mcpp.plugins.progress` is part of `plugins-core`. `enable(action, requested)` sets the optional action flag when the engine API provides it. With older APIs it reports that telemetry is unavailable and leaves the action usable. Engine support starts at mcpp 2026.11.5.1 (protocol 18), which the package's floor includes from 0.27.0 (2026.11.19.1); until then this optional path did not raise the floor. Worker programs select `plugins-progress` and import `mcpp.plugins.progress.writer`. `writer` reads `MCPP_ACTION_PROGRESS_FILE`; an absent channel is a no-op. `report({.phase="compile", .done=3, .total=9})` atomically replaces the latest schema-1 snapshot, assigns increasing sequence numbers and publishes at most five times per second. Omit counts when the total is unknown. `report()` returns whether it published; this result does not determine whether the worker's actual task succeeded. The optional writer feature uses `mcpplibs.os.fs` for portable atomic replacement; `plugins-core` depends on `mcpplibs.os` as well (§4). diff --git a/docs/tool-sources.md b/docs/tool-sources.md index 48d2382..6af3903 100644 --- a/docs/tool-sources.md +++ b/docs/tool-sources.md @@ -581,6 +581,7 @@ part in the build is what this mechanism exists to prevent. | `rules-sycl` | `xim:dpcpp`, `xim:gcc`, `xim:glibc`, `xim:linux-headers` | eager | the compile line is built from the C and C++ libraries | | `rules-spirv`, `rules-slang`, `rules-ascendc` | `xim:shaderc` / `glslang`, `xim:slang`, `xim:cann-toolkit` | eager | the plan classifies the compiler it found | | `dist-apple` | `xim:macapp-run`, `xim:apple-device-tools` | eager, under `when = "run"` | only `mcpp run` needs them, and a tier states that without a request | +| `tools-steps`, so `dist-apk` and `dist-apple` | `steps`, this package's own program | the feature's `tools = ["steps"]` (0.27.0) | the engine builds it for the machine that builds and nothing is downloaded | | `rules-qt` | none | the project declares `xim:qt-base` in its own `[xlings]` table | the SDK a program links is the project's choice | | `rules-metal`, `rules-swift` | none | the host's Xcode | the platform publishes no payload for them | diff --git a/docs/tools-steps.md b/docs/tools-steps.md index 40bdf13..dc6a0bb 100644 --- a/docs/tools-steps.md +++ b/docs/tools-steps.md @@ -1,12 +1,12 @@ # `tools-steps` -`mcpp.tools.steps` is how a member runs an action whose work is more than one command: the member describes the step as portable operations, and a backend runs it on every host, with no shell. +`mcpp.tools.steps` is how a member runs an action whose work is more than one command: the member describes the step as portable operations, and `steps`, a program of this package, runs them on every host, with no shell. ## `tools-steps` -Module `mcpp.tools.steps`; engine floor: 2026.10.1.3; implied by `dist-apk` and `dist-apple`. +Module `mcpp.tools.steps`; engine floor: 2026.11.19.1; implied by `dist-apk` and `dist-apple`. -**Needs and behaviour.** A runner, resolved by the member with `runner_spec()` through `mcpp.plugins.tool`. Until mcpp runs step programs itself (mcpp-community/mcpp#955) the runner is `cmake` 3.31 or newer, which each member that runs steps declares on its own table as `"xim:cmake" = { version = ">=3.31", provision = "on-request" }`, so a plan that runs no step installs nothing. The operations run in order and the first that fails fails the step. `command` writes the program beside the path it is given only when its text changes, and returns the action's argument vector and the inputs it declares, the runner and the program, so a changed program or runner runs the action again and an unchanged one does not. +**Needs and behaviour.** The runner `steps` (`tools/steps_main.cpp`), which the feature declares as its tool, `tools = ["steps"]` (0.27.0). An edge that activates the feature acts as if it had written `tools = ["steps"]`: the engine builds the runner once for the machine that builds, keeps it in the tool store, and gives its path to every build program that links this package with the feature active, a framework's user included (mcpp SPEC-007 R6.3, 2026.11.19.1). `runner()` answers that path, and `missing_runner()` is the refusal of a member that has none. The operations run in order and the first that fails fails the step: the runner names the step file, the operation and its position, and the cause on standard error, and exits 1. `command` writes the program beside the path it is given, as `.steps`, only when its text changes, and returns the action's argument vector, `{, }`, and the inputs it declares, the same two, so a changed program or runner runs the action again and an unchanged one does not. | operation of `program` | what it does when the step runs | |---|---| @@ -17,6 +17,28 @@ Module `mcpp.tools.steps`; engine floor: 2026.10.1.3; implied by `dist-apk` and | `glob(list, pattern, {recursive, relative_to, exclude})` | appends the matching files, sorted, to a named list; from 0.26.0 `exclude` drops a match whose whole path matches one of its patterns, where `*` crosses a `/` | | `append(list, values)`, `require(list, message)` | appends values known at plan time; fails the step with `message` when the list is empty | -Every value is taken verbatim, so a path keeps its spaces, semicolons and backslashes. A list is named by letters, digits and `_`, and starts empty. A pattern's wildcards (`*`, `?`, `[...]`) apply to its last component, and `recursive` matches it in every subdirectory. +Every value is taken verbatim, so a path keeps its spaces, semicolons, quotes, backslashes and non-ASCII text on Linux, macOS and Windows: the runner starts a program with its argument vector and no shell, through mcpplibs.os, which on Windows quotes each argument by the rule the started program splits its command line with, and it converts every name from UTF-8. A list is named by letters, digits and `_`, and starts empty. A pattern's wildcards (`*`, `?`, `[...]`, negated by `!` or `^`) apply to its last component, and `recursive` matches it in every subdirectory. -The backend is internal. Today it renders the program as a CMake script and the action runs `cmake -P` over it; when the engine runs step programs, `runner_spec` and `command` change and no member does. `cmake_backend::render` is exported so a test can read what a program becomes. +**The semantics of 0.25.0 and 0.26.0.** Those releases rendered a program as a CMake script and ran `cmake -P` over it, with the `xim:cmake` each member that ran steps declared, which the index offers only as CMake 4. Where the table leaves a detail open, the runner decides it as that backend did: + +- the matches of a pattern are sorted by their bytes, and each is spelled as the pattern's directory was written, then `/` and the rest; a pattern whose directory is relative, or that has none, is the working directory's; +- a name is matched without regard to the case of ASCII letters on Windows and macOS and exactly elsewhere; an exclusion is compared exactly on every host; `relative_to` drops the names a match shares with it from the root, compared as names are matched; +- a directory is never a match; a flat pattern passes over a link to a directory, and a recursive one does not enter the link but matches it by its name; +- `copy_tree` and `copy_glob` copy a link as a link and a file with its permissions and its time; `copy_tree` gives each directory its source's permissions, `to` included; a file in the way of a copy is replaced, read-only or not; `copy_file` copies a file's contents and permissions; +- `remove` and `remove_glob` remove read-only files and directories as well; +- `run` starts a program named by a relative path with a directory from its `working_directory`, and looks a bare name up on `PATH`. + +Three details differ from that backend, each where CMake altered a value or read a byte as a character: a value that holds `;` stays one value of its list, where CMake split it; a list is empty only when it holds no value, where CMake also took for empty a list whose one value it reads as false (`""`, `0`, `OFF`, `NO`, `FALSE`, `N`, `IGNORE`, `NOTFOUND`, or a value ending in `-NOTFOUND`); and `?` or a bracket expression stands for one character of UTF-8 text, compared without case wherever the rest of the name is, where CMake read one byte and compared a bracket expression as written against a name it had put in lower case. + +**The step file.** `command` writes the program in a format of counted values, and the runner reads it with the same code, `mcpp::plugins::steps` in the lib root, so the writer and the reader do not drift. The first line names the format, `mcpp-steps 1`; a line that begins with `#` where a record could begin is a comment, and `command` writes one naming the member. Each operation is one record: its name; its flags, `-` for none or `r` (`recursive`) and `e` (`if_exists`) in that order; the operands `a` and `b`; the list it reads or extends; and the count of its values, then each value. The fields are separated by single spaces and the record ends with a line break. An operand, a list name and a value are each written as `:`, the value's length in bytes, a colon and the bytes, so nothing is quoted or escaped and a value may hold any byte, a line break included: + +``` +mcpp-steps 1 +# Written by mcpp.dist.apk through mcpp.tools.steps. Do not edit. +remove - 16:/out/classes dir 0: 0: 0 +run - 0: 0: 0: 4 10:/jdk/javac 2:-d 16:/out/classes dir 6:A.java +``` + +The file is internal: a member builds a `program` and never writes the format, and the runner refuses a file whose first line names another format or whose counts do not hold. + +**Before 0.27.0.** The runner was `cmake -P` over the rendered script: each member resolved `cmake` with `runner_spec()` through `mcpp.plugins.tool`, declared `"xim:cmake" = { version = ">=3.31", provision = "on-request" }` on its own table, and took another `cmake` through `options::cmake`. mcpp-community/mcpp#955 asked the engine to run step programs itself; the engine instead lets a feature carry its package's own program to every build program that links the package (mcpp 2026.11.19.1), so the operations remain this package's and change with its version. 0.27.0 removes the CMake backend, `runner_spec`, `cmake_backend::render` and the members' `options::cmake` and `xim:cmake`. diff --git a/mcpp.toml b/mcpp.toml index 64ffae7..ea1a438 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,15 +1,19 @@ [package] name = "plugins" namespace = "mcpp" -version = "0.26.0" -# The first mcpp release that speaks protocol 17 (SPEC-013, mcpp#847): the -# platform's directives `mcpp.plugins.platform` states (`link_driver`, +version = "0.27.0" +# The first mcpp release that gives a feature's `tools` to every build program +# that links this package with the feature active, a framework's user +# included (SPEC-007 R6.3, mcpp#955): `[features.tools-steps] tools = +# ["steps"]` is how the step programs of `dist-apk` and `dist-apple` get their +# runner. It speaks protocol 20 and carries protocol 17 (SPEC-013, mcpp#847): +# the platform's directives `mcpp.plugins.platform` states (`link_driver`, # `link_input`, `artifact_name`, `seal`, `run_host`), the `platform` phase, and # `mcpp-package.json` beside every staged tree, which `mcpp::plugins::package` -# reads. It carries protocol 15 (mcpp#755): `xpkg_source`, `xpkg_program`, +# reads; and protocol 15 (mcpp#755): `xpkg_source`, `xpkg_program`, # `xpkg_request`, `mcpp::decision`, `mcpp::toolchain`, `mcpp::phase`, and the # `provision = "on-request"` entries below. -mcpp = ">=2026.10.30.1" +mcpp = ">=2026.11.19.1" description = "Official mcpp build plugins: rule packages under mcpp.rules.*, build-time utilities under mcpp.tools.*, each member selected by a feature" license = "Apache-2.0" authors = ["mcpp-community"] diff --git a/src/plugins.cppm b/src/plugins.cppm index 83877de..45f689a 100644 --- a/src/plugins.cppm +++ b/src/plugins.cppm @@ -46,7 +46,7 @@ export namespace mcpp::plugins { // // One package, one version: the number lives in mcpp.toml, and the CI step // `the collection states its own version` compares the two. -inline constexpr std::string_view version = "0.26.0"; +inline constexpr std::string_view version = "0.27.0"; } // namespace mcpp::plugins diff --git a/tests/steps-consumer/probe/mcpp.toml b/tests/steps-consumer/probe/mcpp.toml index a5a06f6..6d0ac48 100644 --- a/tests/steps-consumer/probe/mcpp.toml +++ b/tests/steps-consumer/probe/mcpp.toml @@ -1,7 +1,8 @@ # The program the step programs of tests/steps-consumer run: it records the -# arguments a step passes, the directory it runs in, exits with a status it is -# given, and checks what the operations left (src/main.cpp). The fixture builds -# it as a tool, so a step names it by its path. +# arguments a step passes and the directory it runs in, exits with a status it +# is given, sets the permissions a case needs, and checks what the operations +# left (src/main.cpp). The fixture builds it as a tool, so a step names it by +# its path. [package] name = "steps-probe" version = "0.1.0" diff --git a/tools/README.md b/tools/README.md index 728d63b..59e33e0 100644 --- a/tools/README.md +++ b/tools/README.md @@ -9,11 +9,16 @@ program needs that no compiler performs, and does it while `build.mcpp` runs. |---|---|---| | `mcpp.tools.embed` | `tools-embed` | writes a data file into a header the program compiles in, as a byte array or a 32-bit word array | | `mcpp.tools.island` | `tools-island` | writes the `extern "C"` boundary and the C++ module of a code island | -| `mcpp.tools.steps` | `tools-steps` | describes an action whose work is more than one command as portable operations, run by a backend (`cmake -P` until mcpp-community/mcpp#955); the members that need it imply it | +| `mcpp.tools.steps` | `tools-steps` | describes an action whose work is more than one command as portable operations, which `steps` (`tools/steps_main.cpp`), the package's runner, performs; the feature carries the runner to the build program, and the members that need it imply it | Each member is one file, `tools/.cppm`, declaring `export module mcpp.tools.;`, added to the source set by the feature `tools-` in `mcpp.toml`, and importing nothing but `std`, `mcpp`, `mcpp.plugins` and the -general library of `plugins-core`. A +general library of `plugins-core`. A program a member's actions run is +`tools/_main.cpp`, a `kind = "bin"` target: `steps`, which the feature +`tools-steps` declares as its tool (`tools = ["steps"]`), so the engine builds +it for the machine that builds and no consumer names it; and `mcpp-embed`, +which a consumer names on its own edge (`tools = ["mcpp-embed"]`) for +`storage::object`. A utility written for a single consumer belongs in that consumer's `build.mcpp`; a member here is one that more than one consumer needs. diff --git a/tools/steps_main.cpp b/tools/steps_main.cpp index 4b82ef7..f0ff12a 100644 --- a/tools/steps_main.cpp +++ b/tools/steps_main.cpp @@ -24,7 +24,8 @@ // no member changes a step description. The backend was `cmake -P` of the // `xim:cmake` it asked for, which the index offers only as CMake 4; where CMake // decided a detail the statement left open, this program decides it the same -// way, as measured with CMake 4.5: a pattern's matches are sorted and spelled +// way, as measured with CMake 4.5 on Linux (the case rule is the one CMake +// compiles in for Windows and macOS): a pattern's matches are sorted and spelled // as the pattern's directory was written, then `/` and the rest; a pattern that // names no absolute directory is the working directory's; a name is matched // without case where the host compares names without it (Windows, macOS), and