|
| 1 | +diff --git a/nodejs/extensions.bzl b/nodejs/extensions.bzl |
| 2 | +index 1de6f363..1d9d21f0 100644 |
| 3 | +--- a/nodejs/extensions.bzl |
| 4 | ++++ b/nodejs/extensions.bzl |
| 5 | +@@ -1,6 +1,12 @@ |
| 6 | + "extensions for bzlmod" |
| 7 | + |
| 8 | +-load(":repositories.bzl", "DEFAULT_NODE_REPOSITORY", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") |
| 9 | ++load( |
| 10 | ++ ":repositories.bzl", |
| 11 | ++ "DEFAULT_NODE_REPOSITORY", |
| 12 | ++ "DEFAULT_NODE_URL", |
| 13 | ++ "DEFAULT_NODE_VERSION", |
| 14 | ++ "nodejs_register_toolchains", |
| 15 | ++) |
| 16 | + |
| 17 | + def _toolchain_extension(module_ctx): |
| 18 | + registrations = {} |
| 19 | +@@ -8,33 +14,37 @@ def _toolchain_extension(module_ctx): |
| 20 | + for toolchain in mod.tags.toolchain: |
| 21 | + if toolchain.name != DEFAULT_NODE_REPOSITORY and not mod.is_root: |
| 22 | + fail("Only the root module may provide a name for the node toolchain.") |
| 23 | +- |
| 24 | + if toolchain.name in registrations.keys(): |
| 25 | + if toolchain.name == DEFAULT_NODE_REPOSITORY: |
| 26 | + # Prioritize the root-most registration of the default node toolchain version and |
| 27 | + # ignore any further registrations (modules are processed breadth-first) |
| 28 | + continue |
| 29 | +- if toolchain.node_version == registrations[toolchain.name].node_version and toolchain.node_version_from_nvmrc == registrations[toolchain.name].node_version_from_nvmrc: |
| 30 | ++ if (toolchain.node_version != registrations[toolchain.name].node_version or |
| 31 | ++ toolchain.node_version_from_nvmrc != registrations[toolchain.name].node_version_from_nvmrc): |
| 32 | ++ fail("Multiple conflicting toolchains declared for name {} ({} and {})".format( |
| 33 | ++ toolchain.name, |
| 34 | ++ toolchain.node_version, |
| 35 | ++ registrations[toolchain.name].node_version, |
| 36 | ++ )) |
| 37 | ++ elif toolchain.node_urls != registrations[toolchain.name].node_urls: |
| 38 | ++ fail("Multiple toolchains with conflicting urls declared for name {} ({} and {})".format( |
| 39 | ++ toolchain.name, |
| 40 | ++ toolchain.node_urls, |
| 41 | ++ registrations[toolchain.name].node_urls, |
| 42 | ++ )) |
| 43 | ++ else: |
| 44 | + # No problem to register a matching toolchain twice |
| 45 | + continue |
| 46 | +- fail("Multiple conflicting toolchains declared for name {} ({} and {})".format( |
| 47 | +- toolchain.name, |
| 48 | +- toolchain.node_version, |
| 49 | +- registrations[toolchain.name], |
| 50 | +- )) |
| 51 | + else: |
| 52 | +- registrations[toolchain.name] = struct( |
| 53 | +- node_version = toolchain.node_version, |
| 54 | +- node_version_from_nvmrc = toolchain.node_version_from_nvmrc, |
| 55 | +- include_headers = toolchain.include_headers, |
| 56 | +- ) |
| 57 | ++ registrations[toolchain.name] = toolchain |
| 58 | + |
| 59 | +- for k, v in registrations.items(): |
| 60 | ++ for k, t in registrations.items(): |
| 61 | + nodejs_register_toolchains( |
| 62 | + name = k, |
| 63 | +- node_version = v.node_version, |
| 64 | +- node_version_from_nvmrc = v.node_version_from_nvmrc, |
| 65 | +- include_headers = v.include_headers, |
| 66 | ++ node_version = t.node_version, |
| 67 | ++ node_version_from_nvmrc = t.node_version_from_nvmrc, |
| 68 | ++ node_urls = t.node_urls, |
| 69 | ++ include_headers = t.include_headers, |
| 70 | + register = False, |
| 71 | + ) |
| 72 | + |
| 73 | +@@ -62,6 +72,10 @@ If set then the version found in the .nvmrc file is used instead of the one spec |
| 74 | + This setting creates a dependency on a c++ toolchain. |
| 75 | + """, |
| 76 | + ), |
| 77 | ++ "node_urls": attr.string_list( |
| 78 | ++ doc = "Custom list of URL formats to use to download NodeJS, containing {version} and {filename}", |
| 79 | ++ default = [DEFAULT_NODE_URL], |
| 80 | ++ ), |
| 81 | + }), |
| 82 | + }, |
| 83 | + ) |
0 commit comments