From 61726da1da2173a41978265b68e8284431f7f8a5 Mon Sep 17 00:00:00 2001 From: Isaac Parker <128327439+isaacparker0@users.noreply.github.com> Date: Thu, 20 Aug 2026 15:45:42 -0400 Subject: [PATCH] Make release archive packaging version-independent --- nodejs.BUILD.bazel | 3 ++- nodejs/private/release_archive.bzl | 1 + nodejs/private/release_mtree.c | 24 ++++++++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/nodejs.BUILD.bazel b/nodejs.BUILD.bazel index 1747e50..f4597f6 100644 --- a/nodejs.BUILD.bazel +++ b/nodejs.BUILD.bazel @@ -1,5 +1,6 @@ """Build targets for the Node.js source repository.""" +load(":bazel/release.bzl", "NODEJS_RELEASE") load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") load("@nodejs//nodejs:compiler_options.bzl", "cxx20_copts") load( @@ -3684,7 +3685,7 @@ nodejs_release_archives( name = "release_archives", config_gypi = ":config_gypi", node = ":node", - version = "26.3.1", + version = NODEJS_RELEASE.release, ) cc_library( diff --git a/nodejs/private/release_archive.bzl b/nodejs/private/release_archive.bzl index 08e2856..3f5cc78 100644 --- a/nodejs/private/release_archive.bzl +++ b/nodejs/private/release_archive.bzl @@ -473,6 +473,7 @@ def nodejs_release_archives(name, version, node, config_gypi): args = [ "$(execpath :_release_mtree)", "$(execpath {}.mtree)".format(normalized_mtree), + version, root, ] + _EXECUTABLE_RELEASE_FILES, target_compatible_with = release_constraints, diff --git a/nodejs/private/release_mtree.c b/nodejs/private/release_mtree.c index 01599d1..a098a2e 100644 --- a/nodejs/private/release_mtree.c +++ b/nodejs/private/release_mtree.c @@ -134,10 +134,17 @@ static int compare_entries(const void *left_value, const void *right_value) { return strcmp(left->destination, right->destination); } -static int valid_root(const char *root) { - static const char prefix[] = "node-v26.3.1-"; +static int valid_root(const char *root, const char *version) { + static const char prefix[] = "node-v"; + const size_t prefix_length = sizeof(prefix) - 1; + const size_t version_length = strlen(version); + const size_t root_prefix_length = prefix_length + version_length + 1; + const size_t root_length = strlen(root); const unsigned char *cursor = (const unsigned char *)root; - if (strncmp(root, prefix, sizeof(prefix) - 1) != 0) { + if (version_length == 0 || root_length <= root_prefix_length || + strncmp(root, prefix, prefix_length) != 0 || + strncmp(root + prefix_length, version, version_length) != 0 || + root[prefix_length + version_length] != '-') { return 0; } for (; *cursor != '\0'; ++cursor) { @@ -271,15 +278,16 @@ int main(int argc, char **argv) { char required_npm[192]; char required_npx[192]; - if (argc < 4 || !valid_root(argv[3])) { - fprintf(stderr, "usage: release_mtree INPUT OUTPUT node-v26.3.1-PLATFORM " - "[EXECUTABLE ...]\n"); + if (argc < 5 || !valid_root(argv[4], argv[3])) { + fprintf(stderr, + "usage: release_mtree INPUT OUTPUT VERSION node-vVERSION-PLATFORM " + "[EXECUTABLE ...]\n"); return 2; } input_path = argv[1]; output_path = argv[2]; - root = argv[3]; - for (index = 4; index < (size_t)argc; ++index) { + root = argv[4]; + for (index = 5; index < (size_t)argc; ++index) { if (!valid_relative_path(argv[index])) { fprintf(stderr, "release_mtree: invalid executable path %s\n", argv[index]);