Skip to content

Commit 506eebc

Browse files
authored
feat: expose @nodejs_host//:bin/node without using alias (#3434)
This makes it possible for repository rules to reliably find a path to a node interpreter using rctx.path, without having to hard-code any repository name. Needed to workaround rctx.path not understanding alias, and repository rules not having any toolchain resolution.
1 parent 5afaab8 commit 506eebc

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

nodejs/private/nodejs_repo_host_os_alias.bzl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"Provide convenience repository for the host platform"
22

3-
load("//nodejs/private:os_name.bzl", "os_name")
3+
load("//nodejs/private:os_name.bzl", "is_windows_os", "os_name")
44

55
def _nodejs_host_os_alias_impl(repository_ctx):
6+
ext = ".exe" if is_windows_os(repository_ctx) else ""
7+
68
# Base BUILD file for this repository
79
repository_ctx.file("BUILD.bazel", """# Generated by nodejs_repo_host_os_alias.bzl
810
package(default_visibility = ["//visibility:public"])
@@ -18,12 +20,22 @@ alias(name = "node", actual = "@{node_repository}_{os_name}//
1820
alias(name = "npm", actual = "@{node_repository}_{os_name}//:npm")
1921
alias(name = "node_files", actual = "@{node_repository}_{os_name}//:node_files")
2022
alias(name = "npm_files", actual = "@{node_repository}_{os_name}//:npm_files")
21-
exports_files(["index.bzl"])
23+
exports_files([
24+
"index.bzl",
25+
"bin/node{ext}",
26+
])
2227
""".format(
2328
node_repository = repository_ctx.attr.user_node_repository_name,
2429
os_name = os_name(repository_ctx),
30+
ext = ext,
2531
))
2632

33+
repository_ctx.symlink("../{node_repository}_{os_name}/bin/node{ext}".format(
34+
node_repository = repository_ctx.attr.user_node_repository_name,
35+
os_name = os_name(repository_ctx),
36+
ext = ext,
37+
), "bin/node" + ext)
38+
2739
# index.bzl file for this repository
2840
repository_ctx.file("index.bzl", content = """# Generated by nodejs_repo_host_os_alias.bzl
2941
host_platform="{host_platform}"

0 commit comments

Comments
 (0)