From fc53d3786e53522b866c5d86e78036ab255c502c Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Wed, 18 Nov 2026 17:53:39 +0900 Subject: [PATCH 1/2] 0.26.0: a step program's glob excludes paths, and dist-apk empties its class directories glob_options::exclude drops a match whose whole path matches a pattern, where `*` crosses a `/`: a step that archives every object of a build except the ones below one directory (an application core without the platform shell's entry) has no other way to say so. The cmake backend renders each pattern as an anchored regular expression filtering the matches. dist-apk's javac and kotlinc steps empty their class directories before they compile. A compiler adds classes and never removes one, so a source that left the package -- a library dropped from the graph, a file deleted -- kept its class in the directory d8 lists, and in the next package. --- README.md | 2 +- dist/apk.cppm | 9 ++++-- docs/dist-apk.md | 2 +- docs/plugin-development.md | 2 +- docs/tools-steps.md | 2 +- mcpp.toml | 2 +- tests/all-rules-compile/build.mcpp | 13 +++++++++ tools/steps.cppm | 46 ++++++++++++++++++++++++++---- 8 files changed, 65 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cf58eb2..41df098 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.25.0", features = ["rules-spirv"], host-module = true } +plugins = { version = "0.26.0", features = ["rules-spirv"], host-module = true } ``` ```cpp diff --git a/dist/apk.cppm b/dist/apk.cppm index fde7348..5d9f785 100644 --- a/dist/apk.cppm +++ b/dist/apk.cppm @@ -2490,7 +2490,8 @@ inline plan plan_for(options opt = {}) { kt.inputs = kotlinFiles; for (auto const& f : javaFiles) kt.inputs.push_back(f); for (auto const& c : classpath) kt.inputs.push_back(c); - attach(kt, id("apk-kotlinc", "aab-kotlinc"), steps::program{}.run(command).touch(kt.output)); + attach(kt, id("apk-kotlinc", "aab-kotlinc"), + steps::program{}.remove(kotlinClassesDir).run(command).touch(kt.output)); p.steps.push_back(kt); kotlinStamp = kt.output; } @@ -2508,8 +2509,12 @@ inline plan plan_for(options opt = {}) { javacStep.inputs = javaFiles; for (auto const& c : classpath) javacStep.inputs.push_back(c); if (!kotlinStamp.empty()) javacStep.inputs.push_back(kotlinStamp); + // THE DIRECTORY IS EMPTIED FIRST: a compiler adds classes and never + // removes one, so a source that left the package -- a library dropped + // from the graph, a file deleted -- would otherwise keep its class in + // the directory d8 lists, and in the package. attach(javacStep, id("apk-javac", "aab-javac"), - steps::program{}.run(javacCommand).touch(javacStep.output)); + steps::program{}.remove(classesDir).run(javacCommand).touch(javacStep.output)); p.steps.push_back(javacStep); const std::string dexDir = (outDir / "dex").string(); diff --git a/docs/dist-apk.md b/docs/dist-apk.md index fdb12a2..7097b0c 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` +**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. ## `dist-apk`: Kotlin, libraries and a Maven graph diff --git a/docs/plugin-development.md b/docs/plugin-development.md index aad0331..7acb1bf 100644 --- a/docs/plugin-development.md +++ b/docs/plugin-development.md @@ -52,7 +52,7 @@ mcpp-index refuses such a package. ```toml [build-dependencies.mcpp] -plugins = { version = "0.25.0", features = ["plugins-core"], host-module = true, reexport = true } +plugins = { version = "0.26.0", features = ["plugins-core"], host-module = true, reexport = true } ``` `reexport = true` is needed when the plugin's consumers import L2 modules in diff --git a/docs/tools-steps.md b/docs/tools-steps.md index c6a8092..40bdf13 100644 --- a/docs/tools-steps.md +++ b/docs/tools-steps.md @@ -14,7 +14,7 @@ Module `mcpp.tools.steps`; engine floor: 2026.10.1.3; implied by `dist-apk` and | `touch(file)`, `mkdir(dir)` | creates or updates a file, creating its directory; creates a directory | | `remove(path)`, `remove_glob(pattern)` | removes a file or a tree, or the files a pattern matches; absent is not an error | | `copy_file(from, to)`, `copy_tree(from, to, if_exists)`, `copy_glob(pattern, dir)`, `rename(from, to)`, `symlink(target, link)` | file operations; `copy_tree` copies a directory's contents, and with `if_exists` skips a source that is not a directory | -| `glob(list, pattern, {recursive, relative_to})` | appends the matching files, sorted, to a named list | +| `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. diff --git a/mcpp.toml b/mcpp.toml index 5195931..ebe6f53 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] name = "plugins" namespace = "mcpp" -version = "0.25.0" +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`, # `link_input`, `artifact_name`, `seal`, `run_host`), the `platform` phase, and diff --git a/tests/all-rules-compile/build.mcpp b/tests/all-rules-compile/build.mcpp index 480d296..bebcc60 100644 --- a/tests/all-rules-compile/build.mcpp +++ b/tests/all-rules-compile/build.mcpp @@ -73,6 +73,19 @@ int main() { "execute_process(COMMAND [==[a b]==] [==[c;d]==] ${mcpp_steps_found}\n" " WORKING_DIRECTORY [==[w]==]\n COMMAND_ERROR_IS_FATAL ANY)\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. + { + 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"; + } // `dist-wix`, `dist-apple` and `dist-web` are neither rules nor tools, but the same // property is worth asserting on every platform for the same reason: a diff --git a/tools/steps.cppm b/tools/steps.cppm index 5d171f3..74f469d 100644 --- a/tools/steps.cppm +++ b/tools/steps.cppm @@ -52,6 +52,12 @@ struct glob_options { bool recursive = false; // Give each match relative to this directory rather than absolute. std::string relative_to; + // Drop a match whose path, as it is given, matches one of these patterns + // (0.26.0). Unlike the pattern that finds the files, an exclusion applies + // to the whole path: `*` matches any run of characters, `/` included, and + // `?` one character; `*/platform/ios/App/*` drops everything below such a + // directory at any depth. + std::vector exclude; }; enum class op_kind { @@ -59,9 +65,9 @@ enum class op_kind { rename, symlink, glob, append, require, }; -// One operation. `values` is the argument vector of `run` and the values of -// `append`; `a` and `b` are an operation's operands; `list` names the list an -// operation reads or extends. +// 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; @@ -114,7 +120,7 @@ public: } // Appends the files a pattern matches, sorted, to a list. program& glob(std::string list, std::string pattern, glob_options o = {}) { - op x{ op_kind::glob, {}, std::move(pattern), std::move(o.relative_to), std::move(list) }; + op x{ op_kind::glob, std::move(o.exclude), std::move(pattern), std::move(o.relative_to), std::move(list) }; x.recursive = o.recursive; return add(std::move(x)); } @@ -170,6 +176,32 @@ inline bool valid_list_name(const std::string& name) { 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(); } @@ -242,8 +274,10 @@ inline std::string render(const program& p) { 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" - "list(APPEND " + var(o.list) + " ${mcpp_steps_matched})\n"; + 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"; From 418696b149dc5cb3c752cc6b20ac2aa30d6ae8f4 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Wed, 18 Nov 2026 19:28:41 +0900 Subject: [PATCH 2/2] 0.26.0: state the version in the module as in the manifest --- src/plugins.cppm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins.cppm b/src/plugins.cppm index 6566672..68f1b50 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.25.0"; +inline constexpr std::string_view version = "0.26.0"; } // namespace mcpp::plugins