Skip to content

Commit

Permalink
feat(): macros nodejs_binary_toolchains nodejs_test_toolchains input …
Browse files Browse the repository at this point in the history
…multiple toolchains nodejs_binary or nodejs_test
  • Loading branch information
dymart committed Dec 13, 2021
1 parent 12a521d commit f9738df
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 9 deletions.
16 changes: 14 additions & 2 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Defaults to `"1.22.11"`

<pre>
nodejs_binary(<a href="#nodejs_binary-name">name</a>, <a href="#nodejs_binary-chdir">chdir</a>, <a href="#nodejs_binary-configuration_env_vars">configuration_env_vars</a>, <a href="#nodejs_binary-data">data</a>, <a href="#nodejs_binary-default_env_vars">default_env_vars</a>, <a href="#nodejs_binary-entry_point">entry_point</a>, <a href="#nodejs_binary-env">env</a>,
<a href="#nodejs_binary-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_binary-node">node</a>, <a href="#nodejs_binary-templated_args">templated_args</a>)
<a href="#nodejs_binary-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_binary-node">node</a>, <a href="#nodejs_binary-templated_args">templated_args</a>, <a href="#nodejs_binary-toolchain">toolchain</a>)
</pre>

Runs some JavaScript code in NodeJS.
Expand Down Expand Up @@ -484,14 +484,20 @@ Predefined genrule variables are not supported in this context.

Defaults to `[]`

<h4 id="nodejs_binary-toolchain">toolchain</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*)

Defaults to `None`


## nodejs_test

**USAGE**

<pre>
nodejs_test(<a href="#nodejs_test-name">name</a>, <a href="#nodejs_test-chdir">chdir</a>, <a href="#nodejs_test-configuration_env_vars">configuration_env_vars</a>, <a href="#nodejs_test-data">data</a>, <a href="#nodejs_test-default_env_vars">default_env_vars</a>, <a href="#nodejs_test-entry_point">entry_point</a>, <a href="#nodejs_test-env">env</a>,
<a href="#nodejs_test-expected_exit_code">expected_exit_code</a>, <a href="#nodejs_test-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_test-node">node</a>, <a href="#nodejs_test-templated_args">templated_args</a>)
<a href="#nodejs_test-expected_exit_code">expected_exit_code</a>, <a href="#nodejs_test-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_test-node">node</a>, <a href="#nodejs_test-templated_args">templated_args</a>, <a href="#nodejs_test-toolchain">toolchain</a>)
</pre>


Expand Down Expand Up @@ -744,6 +750,12 @@ Predefined genrule variables are not supported in this context.

Defaults to `[]`

<h4 id="nodejs_test-toolchain">toolchain</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*)

Defaults to `None`


## npm_install

Expand Down
8 changes: 7 additions & 1 deletion docs/Cypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Defaults to `None`
<pre>
cypress_web_test(<a href="#cypress_web_test-name">name</a>, <a href="#cypress_web_test-chdir">chdir</a>, <a href="#cypress_web_test-config_file">config_file</a>, <a href="#cypress_web_test-configuration_env_vars">configuration_env_vars</a>, <a href="#cypress_web_test-cypress_npm_package">cypress_npm_package</a>, <a href="#cypress_web_test-data">data</a>,
<a href="#cypress_web_test-default_env_vars">default_env_vars</a>, <a href="#cypress_web_test-entry_point">entry_point</a>, <a href="#cypress_web_test-env">env</a>, <a href="#cypress_web_test-expected_exit_code">expected_exit_code</a>, <a href="#cypress_web_test-link_workspace_root">link_workspace_root</a>, <a href="#cypress_web_test-node">node</a>,
<a href="#cypress_web_test-plugin_file">plugin_file</a>, <a href="#cypress_web_test-srcs">srcs</a>, <a href="#cypress_web_test-templated_args">templated_args</a>)
<a href="#cypress_web_test-plugin_file">plugin_file</a>, <a href="#cypress_web_test-srcs">srcs</a>, <a href="#cypress_web_test-templated_args">templated_args</a>, <a href="#cypress_web_test-toolchain">toolchain</a>)
</pre>


Expand Down Expand Up @@ -349,6 +349,12 @@ Predefined genrule variables are not supported in this context.

Defaults to `[]`

<h4 id="cypress_web_test-toolchain">toolchain</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*)

Defaults to `None`


## cypress_repositories

Expand Down
16 changes: 10 additions & 6 deletions internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,12 @@ fi
# when building the image as that will reflect the selected --platform.
node_tool_files = ctx.files.node[:]

# this should be resolved the same as above
node_tool_files.extend(ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo.tool_files)
if ctx.attr.toolchain:
node_toolchain = ctx.attr.toolchain[platform_common.ToolchainInfo]
else:
node_toolchain = ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"]

node_tool_files.extend(node_toolchain.nodeinfo.tool_files)
node_tool_files.append(ctx.file._link_modules_script)
node_tool_files.append(ctx.file._runfile_helpers_bundle)
node_tool_files.append(ctx.file._runfile_helpers_main)
Expand Down Expand Up @@ -597,14 +600,15 @@ Predefined genrule variables are not supported in this context.
default = Label("@nodejs//:node_bin"),
allow_single_file = True,
),
"_node_patches_script": attr.label(
default = Label("//internal/node:node_patches.js"),
allow_single_file = True,
),
"toolchain": attr.label(),
"_repository_args": attr.label(
default = Label("@nodejs//:bin/node_repo_args.sh"),
allow_single_file = True,
),
"_node_patches_script": attr.label(
default = Label("//internal/node:node_patches.js"),
allow_single_file = True,
),
"_require_patch_template": attr.label(
default = Label("//internal/node:require_patch.js"),
allow_single_file = True,
Expand Down
71 changes: 71 additions & 0 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,74 @@ nodejs_test(
"@bazel_tools//src/conditions:windows": "@node16_windows_amd64//:node_toolchain",
}),
)

# these rules create different targets for each toolchain that is supplied in the list for toolchains
# this makes it easy to build or test against multiple versions of a toolchain at the same time with less duplicate work
# this will create 2 nodejs_binary targets
# bazel build //internal/node/test:main_multiple_loop_node16
# bazel build //internal/node/test:main_multiple_loop_node15
# the numbers are based on the order that the toolchains are passed to the rule
[
nodejs_binary(
name = "main_multiple_loop_" + id,
entry_point = "binary_version.js",
node = tc,
toolchain = tc,
)
for id, tc in zip(
[
"node16",
"node15",
],
[
# using the select statement will download toolchains for all platforms
# you can also just provide an individual toolchain if you don't want to download them all
select({
"@bazel_tools//src/conditions:linux_x86_64": "@node16_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node16_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node16_windows_amd64//:node_toolchain",
}),
select({
"@bazel_tools//src/conditions:linux_x86_64": "@node15_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node15_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node15_windows_amd64//:node_toolchain",
}),
],
)
]

# this will create 2 test:
# bazel test //internal/node/test:main_test_multiple_loop_node16
# bazel test //internal/node/test:main_test_multiple_loop_node15
# the numbers are based on the order that the toolchains are passed to the rule
[
nodejs_test(
name = "main_test_multiple_loop_" + id,
data = [
"data/data.json",
],
entry_point = ":data_resolution.spec.js",
node = tc,
toolchain = tc,
)
for id, tc in zip(
[
"node16",
"node15",
],
[
# using the select statement will download toolchains for all platforms
# you can also just provide an individual toolchain if you don't want to download them all
select({
"@bazel_tools//src/conditions:linux_x86_64": "@node16_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node16_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node16_windows_amd64//:node_toolchain",
}),
select({
"@bazel_tools//src/conditions:linux_x86_64": "@node15_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node15_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node15_windows_amd64//:node_toolchain",
}),
],
)
]

0 comments on commit f9738df

Please sign in to comment.