refactor: remove legacy node toolchain At this point everything should be using the new one
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 6d44033..c5489c6 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml
@@ -40,9 +40,6 @@ - "--test_tag_filters=-e2e,-examples,-manual,-browser:chromium-local,-browser:firefox-local,-browser:custom_chrome,-cypress" test_targets: - "//..." - # //internal/node/test:nodejs_toolchain_linux_amd64_test is a "manual" test that must be run - # explicitly; it should pass when running on Linux with no --platform set. - - "//internal/node/test:nodejs_toolchain_linux_amd64_test" ubuntu1804_debug: name: ubuntu1804_debug platform: ubuntu1804 @@ -129,40 +126,6 @@ # TODO(gregmagolan): make node_repositories acccept different archives for different platforms - "//examples:examples_vendored_node" - "//examples:examples_vendored_node_and_yarn" - ubuntu1804_cross_compile_darwin: - name: ubuntu1804_cross_compile_darwin - platform: ubuntu1804 - # Build on linux with the node --platform set to darwin - build_flags: - - "--platforms=@rules_nodejs//nodejs:darwin_amd64" - # TODO(gregmagolan): figure out how to install missing shared libs - # Without this filter the @cypress external repository will be built and that build will fail due to missing shared libs. - - "--build_tag_filters=-cypress" - build_targets: - - "//internal/..." - test_flags: - - "--platforms=@rules_nodejs//nodejs:darwin_amd64" - test_targets: - # //internal/node/test:nodejs_toolchain_darwin_amd64_test is a "manual" test that must be run - # explicitly with --platforms set to darwin_amd64 - - "//internal/node/test:nodejs_toolchain_darwin_amd64_test" - ubuntu1804_cross_compile_windows: - name: ubuntu1804_cross_compile_windows - platform: ubuntu1804 - # Build on linux with the node --platform set to Windows - build_flags: - - "--platforms=@rules_nodejs//nodejs:windows_amd64" - # TODO(gregmagolan): figure out how to install missing shared libs - # Without this filter the @cypress external repository will be built and that build will fail due to missing shared libs. - - "--build_tag_filters=-cypress" - build_targets: - - "//internal/..." - test_flags: - - "--platforms=@rules_nodejs//nodejs:windows_amd64" - test_targets: - # //internal/node/test:nodejs_toolchain_windows_amd64_test is a "manual" test that must be run - # explicitly with --platforms set to windows_amd64 - - "//internal/node/test:nodejs_toolchain_windows_amd64_test" macos: name: macos platform: macos @@ -186,9 +149,6 @@ - "--test_tag_filters=-e2e,-examples,-manual,-browser:firefox-local" test_targets: - "//..." - # //internal/node/test:nodejs_toolchain_darwin_amd64_test is a "manual" test that must be run - # explicitly; it should pass when running on OSX with no --platform set. - - "//internal/node/test:nodejs_toolchain_darwin_amd64_test" macos_e2e: name: macos_e2e platform: macos @@ -245,20 +205,6 @@ - "--test_arg=--test_tag_filters=-no-bazelci-mac,-manual,-browser:firefox-local" test_targets: - "//..." - macos_cross_compile_linux: - name: macos_cross_compile_linux - platform: macos - # Build on mac with the node --platform set to linux - build_flags: - - "--platforms=@rules_nodejs//nodejs:linux_amd64" - build_targets: - - "//internal/..." - test_flags: - - "--platforms=@rules_nodejs//nodejs:linux_amd64" - test_targets: - # //internal/node/test:nodejs_toolchain_linux_amd64_test is a "manual" test that must be run - # explicitly with --platforms set to linux_amd64 - - "//internal/node/test:nodejs_toolchain_linux_amd64_test" # TODO(gregmagolan): fix platform configuraiton for this test job for Bazel 2.0 # macos_fake_rbe: # name: macos_fake_rbe @@ -294,9 +240,6 @@ - "--test_tag_filters=-e2e,-examples,-fix-windows,-no-bazelci-windows,-requires-runfiles,-manual,-browser:firefox-local,-cypress" test_targets: - "//..." - # //internal/node/test:nodejs_toolchain_windows_amd64_test is a "manual" test that must be run - # explicitly; it should pass when running on Windows with no --platform set. - - "//internal/node/test:nodejs_toolchain_windows_amd64_test" windows_runfiles_enabled: name: windows_runfiles_enabled platform: windows @@ -347,15 +290,6 @@ - "--test_arg=--test_tag_filters=-fix-windows,-no-bazelci-windows,-requires-runfiles,-manual,-browser:chromium-local,-browser:firefox-local,-cypress" test_targets: - "//..." - windows_cross_compile_linux: - name: windows_cross_compile_linux - platform: windows - build_flags: - - "--build_tag_filters=-fix-windows,-no-bazelci-windows,-requires-runfiles" - # Build on windows with the node --platform set to linux - - "--platforms=@rules_nodejs//nodejs:linux_amd64" - build_targets: - - "//internal/..." rbe_ubuntu1604: name: rbe_ubuntu1604 platform: rbe_ubuntu1604
diff --git a/BUILD.bazel b/BUILD.bazel index 7ffb4f3..ca3ddae 100644 --- a/BUILD.bazel +++ b/BUILD.bazel
@@ -116,7 +116,6 @@ "//third_party/npm/node_modules/named-amd:package_contents", "//toolchains/cypress:package_contents", "//toolchains/esbuild:package_contents", - "//toolchains/node:package_contents", ], )
diff --git a/docs/Toolchains.md b/docs/Toolchains.md index a9e3bd2..49ac02f 100644 --- a/docs/Toolchains.md +++ b/docs/Toolchains.md
@@ -52,76 +52,6 @@ Defaults to `None` -## node_toolchain - -**USAGE** - -<pre> -node_toolchain(<a href="#node_toolchain-name">name</a>, <a href="#node_toolchain-target_tool">target_tool</a>, <a href="#node_toolchain-target_tool_path">target_tool_path</a>) -</pre> - -Defines a node toolchain. - -For usage see https://docs.bazel.build/versions/main/toolchains.html#defining-toolchains. - - -**ATTRIBUTES** - - -<h4 id="node_toolchain-name">name</h4> - -(*<a href="https://bazel.build/docs/build-ref.html#name">Name</a>, mandatory*): A unique name for this target. - - -<h4 id="node_toolchain-target_tool">target_tool</h4> - -(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*): A hermetically downloaded nodejs executable target for the target platform. - -Defaults to `None` - -<h4 id="node_toolchain-target_tool_path">target_tool_path</h4> - -(*String*): Path to an existing nodejs executable for the target platform. - -Defaults to `""` - - -## node_toolchain_configure - -**USAGE** - -<pre> -node_toolchain_configure(<a href="#node_toolchain_configure-name">name</a>, <a href="#node_toolchain_configure-repo_mapping">repo_mapping</a>, <a href="#node_toolchain_configure-target_tool">target_tool</a>, <a href="#node_toolchain_configure-target_tool_path">target_tool_path</a>) -</pre> - -Creates an external repository with a node_toolchain //:toolchain target properly configured. - -**ATTRIBUTES** - - -<h4 id="node_toolchain_configure-name">name</h4> - -(*<a href="https://bazel.build/docs/build-ref.html#name">Name</a>, mandatory*): A unique name for this repository. - - -<h4 id="node_toolchain_configure-repo_mapping">repo_mapping</h4> - -(*<a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a>, mandatory*): A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`). - - -<h4 id="node_toolchain_configure-target_tool">target_tool</h4> - -(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*): Target for a downloaded nodejs binary for the target os. - -Defaults to `None` - -<h4 id="node_toolchain_configure-target_tool_path">target_tool_path</h4> - -(*String*): Absolute path to a pre-installed nodejs binary for the target os. - -Defaults to `""` - - ## configure_esbuild_toolchains **USAGE**
diff --git a/e2e/nodejs_image/BUILD.bazel b/e2e/nodejs_image/BUILD.bazel index f15e5c4..714691a 100644 --- a/e2e/nodejs_image/BUILD.bazel +++ b/e2e/nodejs_image/BUILD.bazel
@@ -12,7 +12,7 @@ entry_point = "main.js", ) -# bazel run --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //:nodejs_image +# bazel run --platforms=@rules_nodejs//:linux_amd64 //:nodejs_image nodejs_image( name = "nodejs_image", binary = ":main",
diff --git a/internal/node/BUILD.bazel b/internal/node/BUILD.bazel index 30d499e..5add4d5 100644 --- a/internal/node/BUILD.bazel +++ b/internal/node/BUILD.bazel
@@ -31,7 +31,6 @@ "//internal/npm_install:bzl", "//nodejs:bzl", "//third_party/github.com/bazelbuild/bazel-skylib:bzl", - "//toolchains/node:bzl", "@rules_nodejs//nodejs:bzl", ], )
diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 0a6c72e..3ae7b0e 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl
@@ -22,7 +22,6 @@ load("//internal/common:check_bazel_version.bzl", "check_bazel_version") load("//nodejs/private:os_name.bzl", "OS_ARCH_NAMES", "node_exists_for_os", "os_name") load("//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", node_repositories_rule = "node_repositories") -load("//toolchains/node:node_toolchain_configure.bzl", "node_toolchain_configure") load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains") def node_repositories(**kwargs): @@ -57,12 +56,6 @@ name = node_repository_name, **kwargs ) - target_tool = "@%s//:node_bin" % node_repository_name - native.register_toolchains("@build_bazel_rules_nodejs//toolchains/node:node_%s_toolchain" % os_name) - node_toolchain_configure( - name = "%s_config" % node_repository_name, - target_tool = target_tool, - ) # Install new toolchain under "nodejs" repository name prefix nodejs_register_toolchains(name = "nodejs")
diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index f0f465b..e87d8ac 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel
@@ -1,11 +1,9 @@ load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "nodejs_test", "npm_package_bin") load("@npm//typescript:index.bzl", "tsc") load("//:index.bzl", "js_library") -load("//nodejs:repositories.bzl", "BUILT_IN_NODE_PLATFORMS") load("//packages/jasmine:index.bzl", "jasmine_node_test") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") -load(":nodejs_toolchain_test.bzl", "nodejs_toolchain_test") # You can have a nodejs_binary with no node_modules attribute # and no fine grained deps @@ -341,14 +339,6 @@ ], ) -[nodejs_toolchain_test( - name = "nodejs_toolchain_%s_test" % platform, - platform = platform, - # must be run with --platforms=@rules_nodejs//nodejs:PLATFORM - # where PLATFORM is one of BUILT_IN_NODE_PLATFORMS - tags = ["manual"], -) for platform in BUILT_IN_NODE_PLATFORMS] - nodejs_binary( name = "expand_variables", entry_point = "expand_variables.js",
diff --git a/internal/node/test/nodejs_toolchain_test.bzl b/internal/node/test/nodejs_toolchain_test.bzl deleted file mode 100644 index cfa55b3..0000000 --- a/internal/node/test/nodejs_toolchain_test.bzl +++ /dev/null
@@ -1,63 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Testing for node toolchains - -This test verifies that if --platforms=@rules_nodejs//nodejs:<platform> is set then -the correct node path is available to rules via -ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo.tool_files[0].path -""" - -load("//nodejs:repositories.bzl", "NODE_EXTRACT_DIR") - -_SCRIPT_TEMPLATE = """#!/bin/bash -EXPECTED_NODE_PATH="{expected_node_path}" -TOOLCHAIN_NODE_PATH="{toolchain_node_path}" -if [ "$EXPECTED_NODE_PATH" != "$TOOLCHAIN_NODE_PATH" ]; then - echo "Expected platform node path to be '$EXPECTED_NODE_PATH' but got '$TOOLCHAIN_NODE_PATH'" - exit 1 -fi -""" - -_ATTRS = { - "platform": attr.string( - values = ["linux_amd64", "linux_arm64", "linux_s390x", "linux_ppc64le", "darwin_amd64", "darwin_arm64", "windows_amd64"], - ), -} - -def _nodejs_toolchain_test(ctx): - script = ctx.actions.declare_file(ctx.label.name) - - is_windows = ctx.attr.platform == "windows_amd64" - expected_node_path = "external/nodejs_%s/%s/%s" % (ctx.attr.platform, NODE_EXTRACT_DIR, "node.exe" if is_windows else "bin/node") - - ctx.actions.write( - script, - _SCRIPT_TEMPLATE.format( - expected_node_path = expected_node_path, - toolchain_node_path = ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo.tool_files[0].path, - ), - is_executable = True, - ) - return [DefaultInfo(executable = script)] - -nodejs_toolchain_test = rule( - implementation = _nodejs_toolchain_test, - attrs = _ATTRS, - test = True, - toolchains = [ - "@build_bazel_rules_nodejs//toolchains/node:toolchain_type", - "@bazel_tools//tools/sh:toolchain_type", - ], -)
diff --git a/toolchains/BUILD.bazel b/toolchains/BUILD.bazel index 962a2a9..08747a2 100644 --- a/toolchains/BUILD.bazel +++ b/toolchains/BUILD.bazel
@@ -9,6 +9,5 @@ deps = [ "//toolchains/cypress:bzl", "//toolchains/esbuild:bzl", - "//toolchains/node:bzl", ], )
diff --git a/toolchains/index.for_docs.bzl b/toolchains/index.for_docs.bzl index b271eaf..9e55f67 100644 --- a/toolchains/index.for_docs.bzl +++ b/toolchains/index.for_docs.bzl
@@ -10,12 +10,8 @@ load("//toolchains/cypress:cypress_toolchain.bzl", _cypress_toolchain = "cypress_toolchain") load("//toolchains/esbuild:esbuild_repositories.bzl", _esbuild_repositories = "esbuild_repositories") load("//toolchains/esbuild:toolchain.bzl", _configure_esbuild_toolchains = "configure_esbuild_toolchains") -load("//toolchains/node:node_toolchain_configure.bzl", _node_toolchain_configure = "node_toolchain_configure") -load("//toolchains/node:node_toolchain.bzl", _node_toolchain = "node_toolchain") cypress_repositories = _cypress_repositories cypress_toolchain = _cypress_toolchain esbuild_repositories = _esbuild_repositories configure_esbuild_toolchains = _configure_esbuild_toolchains -node_toolchain_configure = _node_toolchain_configure -node_toolchain = _node_toolchain
diff --git a/toolchains/node/BUILD.bazel b/toolchains/node/BUILD.bazel deleted file mode 100644 index 300d40b..0000000 --- a/toolchains/node/BUILD.bazel +++ /dev/null
@@ -1,139 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -package(default_visibility = ["//visibility:private"]) - -licenses(["notice"]) # Apache 2.0 - -bzl_library( - name = "bzl", - srcs = glob(["*.bzl"]), - visibility = ["//visibility:public"], -) - -filegroup( - name = "package_contents", - srcs = glob(["*"]), - visibility = ["//:__pkg__"], -) - -# node toolchain type -toolchain_type( - name = "toolchain_type", - visibility = ["//visibility:public"], -) - -# Allow targets to use a toolchains attribute, such as sh_binary and genrule -# This way they can reference the NODE_PATH make variable. -alias( - name = "toolchain", - actual = select({ - "@bazel_tools//src/conditions:darwin_arm64": "@nodejs_darwin_arm64_config//:toolchain", - "@bazel_tools//src/conditions:darwin_x86_64": "@nodejs_darwin_amd64_config//:toolchain", - "@bazel_tools//src/conditions:linux_aarch64": "@nodejs_linux_arm64_config//:toolchain", - "@bazel_tools//src/conditions:linux_s390x": "@nodejs_linux_s390x_config//:toolchain", - "@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64_config//:toolchain", - "@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64_config//:toolchain", - "@bazel_tools//src/conditions:linux_ppc64le": "@nodejs_linux_ppc64le_config//:toolchain", - "//conditions:default": "@nodejs_linux_amd64_config//:toolchain", - }), - visibility = ["//visibility:public"], -) - -# Allow targets to declare a dependency on the node binary for the current host platform -alias( - name = "node_bin", - actual = select({ - "@bazel_tools//src/conditions:darwin_arm64": "@nodejs_darwin_arm64//:node_bin", - "@bazel_tools//src/conditions:darwin_x86_64": "@nodejs_darwin_amd64//:node_bin", - "@bazel_tools//src/conditions:linux_aarch64": "@nodejs_linux_arm64//:node_bin", - "@bazel_tools//src/conditions:linux_s390x": "@nodejs_linux_s390x//:node_bin", - "@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64//:node_bin", - "@bazel_tools//src/conditions:linux_ppc64le": "@nodejs_linux_ppc64le//:node_bin", - "@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64//:node_bin", - "//conditions:default": "@nodejs_linux_amd64//:node_bin", - }), - visibility = ["//visibility:public"], -) - -toolchain( - name = "node_linux_amd64_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ], - toolchain = "@nodejs_linux_amd64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_linux_arm64_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:aarch64", - ], - toolchain = "@nodejs_linux_arm64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_darwin_amd64_toolchain", - target_compatible_with = [ - "@platforms//os:osx", - "@platforms//cpu:x86_64", - ], - toolchain = "@nodejs_darwin_amd64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_darwin_arm64_toolchain", - target_compatible_with = [ - "@platforms//os:osx", - "@platforms//cpu:aarch64", - ], - toolchain = "@nodejs_darwin_arm64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_windows_amd64_toolchain", - target_compatible_with = [ - "@platforms//os:windows", - "@platforms//cpu:x86_64", - ], - toolchain = "@nodejs_windows_amd64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_linux_s390x_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:s390x", - ], - toolchain = "@nodejs_linux_s390x_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_linux_ppc64le_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:ppc", - ], - toolchain = "@nodejs_linux_ppc64le_config//:toolchain", - toolchain_type = ":toolchain_type", -)
diff --git a/toolchains/node/BUILD.tpl b/toolchains/node/BUILD.tpl deleted file mode 100644 index 909fd9e..0000000 --- a/toolchains/node/BUILD.tpl +++ /dev/null
@@ -1,25 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""This BUILD file is auto-generated from toolchains/node/BUILD.tpl -""" - -package(default_visibility = ["//visibility:public"]) - -load("@build_bazel_rules_nodejs//toolchains/node:node_toolchain.bzl", "node_toolchain") - -node_toolchain( - name = "toolchain", -%{TOOL_ATTRS} -)
diff --git a/toolchains/node/node_toolchain.bzl b/toolchains/node/node_toolchain.bzl deleted file mode 100644 index 09034ce..0000000 --- a/toolchains/node/node_toolchain.bzl +++ /dev/null
@@ -1,79 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""This module implements the node toolchain rule. -""" - -NodeInfo = provider( - doc = "Information about how to invoke the node executable.", - fields = { - "target_tool_path": "Path to the nodejs executable for the target platform.", - "tool_files": """Files required in runfiles to make the nodejs executable available. - -May be empty if the target_tool_path points to a locally installed node binary.""", - }, -) - -# Avoid using non-normalized paths (workspace/../other_workspace/path) -def _to_manifest_path(ctx, file): - if file.short_path.startswith("../"): - return file.short_path[3:] - else: - return ctx.workspace_name + "/" + file.short_path - -def _node_toolchain_impl(ctx): - if ctx.attr.target_tool and ctx.attr.target_tool_path: - fail("Can only set one of target_tool or target_tool_path but both were set.") - if not ctx.attr.target_tool and not ctx.attr.target_tool_path: - fail("Must set one of target_tool or target_tool_path.") - - tool_files = [] - target_tool_path = ctx.attr.target_tool_path - - if ctx.attr.target_tool: - tool_files = ctx.attr.target_tool.files.to_list() - target_tool_path = _to_manifest_path(ctx, tool_files[0]) - - return [ - platform_common.ToolchainInfo( - nodeinfo = NodeInfo( - target_tool_path = target_tool_path, - tool_files = tool_files, - ), - ), - # Make the $(NODE_PATH) variable available in places like genrules. - # See https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables - platform_common.TemplateVariableInfo({ - "NODE_PATH": target_tool_path, - }), - ] - -node_toolchain = rule( - implementation = _node_toolchain_impl, - attrs = { - "target_tool": attr.label( - doc = "A hermetically downloaded nodejs executable target for the target platform.", - mandatory = False, - allow_single_file = True, - ), - "target_tool_path": attr.string( - doc = "Path to an existing nodejs executable for the target platform.", - mandatory = False, - ), - }, - doc = """Defines a node toolchain. - -For usage see https://docs.bazel.build/versions/main/toolchains.html#defining-toolchains. -""", -)
diff --git a/toolchains/node/node_toolchain_configure.bzl b/toolchains/node/node_toolchain_configure.bzl deleted file mode 100644 index 870f17f..0000000 --- a/toolchains/node/node_toolchain_configure.bzl +++ /dev/null
@@ -1,54 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Defines a repository rule for configuring the node executable. -""" - -def _impl(repository_ctx): - if repository_ctx.attr.target_tool and repository_ctx.attr.target_tool_path: - fail("Can only set one of target_tool or target_tool_path but both where set.") - - if repository_ctx.attr.target_tool: - substitutions = {"%{TOOL_ATTRS}": " target_tool = \"%s\"\n" % repository_ctx.attr.target_tool} - else: - if repository_ctx.attr.target_tool_path: - default_tool_path = repository_ctx.attr.target_tool_path - else: - default_tool_path = repository_ctx.which("node") - if not default_tool_path: - fail("No node found on local path. node must available on the PATH or target_tool_path must be provided") - substitutions = {"%{TOOL_ATTRS}": " target_tool_path = \"%s\"\n" % default_tool_path} - - repository_ctx.template( - "BUILD", - Label("@build_bazel_rules_nodejs//toolchains/node:BUILD.tpl"), - substitutions, - False, - ) - -node_toolchain_configure = repository_rule( - implementation = _impl, - attrs = { - "target_tool": attr.label( - doc = "Target for a downloaded nodejs binary for the target os.", - mandatory = False, - allow_single_file = True, - ), - "target_tool_path": attr.string( - doc = "Absolute path to a pre-installed nodejs binary for the target os.", - mandatory = False, - ), - }, - doc = """Creates an external repository with a node_toolchain //:toolchain target properly configured.""", -)