Skip to content

Commit 9555565

Browse files
devversionAndrewKushnir
authored andcommitted
build: disable bazel nodejs linker to improve stability on windows (angular#45872)
The NodeJS Bazel linker does not work well on Windows because there is no sandboxing and linker processes from different tests will attempt to modify the same `node_modules`, causing concurrency race conditions and resulting in flakiness. PR Close angular#45872
1 parent ecae55d commit 9555565

File tree

18 files changed

+66
-61
lines changed

18 files changed

+66
-61
lines changed

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
1+
load("//tools:defaults.bzl", "nodejs_binary")
22

33
package(default_visibility = ["//visibility:public"])
44

aio/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@aio_npm//@angular-devkit/architect-cli:index.bzl", "architect", "architect_test")
2-
load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin")
2+
load("//tools:defaults.bzl", "npm_package_bin")
33

44
# The write_source_files macro is used to write bazel outputs to the source tree and test that they are up to date.
55
# See: https://docs.aspect.build/aspect-build/bazel-lib/v0.5.0/docs/docs/write_source_files-docgen.html

aio/scripts/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
1+
load("//tools:defaults.bzl", "nodejs_binary")
22

33
package(default_visibility = ["//visibility:public"])
44

integration/bazel_workspace_tests/bazel_ngtsc_plugin/tools/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ nodejs_binary(
1313
"@npm//@bazel/concatjs",
1414
],
1515
entry_point = "@npm//:node_modules/@bazel/concatjs/internal/tsc_wrapped/tsc_wrapped.js",
16+
# Disable the linker and rely on patched resolution which works better on Windows
17+
# and is less prone to race conditions when targets build concurrently.
18+
templated_args = ["--nobazel_run_linker"],
1619
visibility = ["//:__subpackages__"],
1720
)
1821

packages/bazel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"bazelBin": {
1818
"ngc-wrapped": {
1919
"additionalAttributes": {
20-
"templated_args": "[\"--bazel_patch_module_resolver\"]"
20+
"templated_args": "[\"--nobazel_run_linker\"]"
2121
}
2222
}
2323
},

packages/bazel/src/ng_package/BUILD.bazel

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ nodejs_binary(
3636
# END-DEV-ONLY
3737
"//:node_modules/rollup/dist/bin/rollup"
3838
),
39-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
40-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
41-
templated_args = ["--bazel_patch_module_resolver"],
39+
# Disable the linker and rely on patched resolution which works better on Windows
40+
# and is less prone to race conditions when targets build concurrently.
41+
templated_args = ["--nobazel_run_linker"],
4242
)
4343

4444
exports_files([
@@ -72,8 +72,8 @@ nodejs_binary(
7272
"@npm//shelljs",
7373
],
7474
entry_point = ":packager.ts",
75-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
76-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
77-
templated_args = ["--bazel_patch_module_resolver"],
75+
# Disable the linker and rely on patched resolution which works better on Windows
76+
# and is less prone to race conditions when targets build concurrently.
77+
templated_args = ["--nobazel_run_linker"],
7878
)
7979
# END-DEV-ONLY

packages/bazel/src/ngc-wrapped/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ nodejs_binary(
4949
"@npm//source-map-support",
5050
],
5151
entry_point = ":extract_i18n.ts",
52-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
53-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
54-
templated_args = ["--bazel_patch_module_resolver"],
52+
# Follows the same reasoning as for the actual `ngc-wrapped` target.
53+
templated_args = ["--nobazel_run_linker"],
5554
visibility = ["//visibility:public"],
5655
)
5756

packages/bazel/src/types_bundle/BUILD.bazel

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# BEGIN-DEV-ONLY
22

3-
load("//tools:defaults.bzl", "ts_library")
4-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
3+
load("//tools:defaults.bzl", "nodejs_binary", "ts_library")
54

65
package(default_visibility = ["//packages:__subpackages__"])
76

@@ -24,9 +23,9 @@ nodejs_binary(
2423
"@npm//@microsoft/api-extractor",
2524
],
2625
entry_point = ":index.ts",
27-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
28-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
29-
templated_args = ["--bazel_patch_module_resolver"],
26+
# Disable the linker and rely on patched resolution which works better on Windows
27+
# and is less prone to race conditions when targets build concurrently.
28+
templated_args = ["--nobazel_run_linker"],
3029
visibility = ["//visibility:public"],
3130
)
3231

packages/common/locales/generate-locales-tool/bin/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
2-
load("//tools:defaults.bzl", "ts_library")
1+
load("//tools:defaults.bzl", "nodejs_binary", "ts_library")
32

43
package(default_visibility = ["//visibility:public"])
54

@@ -30,5 +29,5 @@ ts_library(
3029
# We need to patch the NodeJS module resolution as this binary runs as
3130
# part of a genrule where the linker does not work as expected.
3231
# See: https://github.com/bazelbuild/rules_nodejs/issues/2600.
33-
templated_args = ["--bazel_patch_module_resolver"],
32+
templated_args = ["--nobazel_run_linker"],
3433
) for entrypoint in BIN_ENTRYPOINTS]

packages/compiler-cli/ngcc/test/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ jasmine_node_test(
9999
],
100100
shard_count = 4,
101101
tags = [],
102-
templated_args = [
103-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
104-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
105-
"--bazel_patch_module_resolver",
106-
],
107102
deps = [
108103
":integration_lib",
109104
"@npm//convert-source-map",

packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "npm_package_bin")
1+
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
2+
load("//tools:defaults.bzl", "nodejs_binary", "npm_package_bin")
23

34
def partial_compliance_golden(filePath):
45
"""Creates the generate and testing targets for partial compile results.
@@ -19,10 +20,7 @@ def partial_compliance_golden(filePath):
1920
data = data + [filePath],
2021
visibility = [":__pkg__"],
2122
entry_point = "//packages/compiler-cli/test/compliance/partial:cli.ts",
22-
templated_args = [
23-
"--bazel_patch_module_resolver",
24-
"$(execpath %s)" % filePath,
25-
],
23+
templated_args = ["$(execpath %s)" % filePath],
2624
)
2725

2826
nodejs_binary(
@@ -31,13 +29,7 @@ def partial_compliance_golden(filePath):
3129
data = data,
3230
visibility = [":__pkg__"],
3331
entry_point = "//packages/compiler-cli/test/compliance/partial:cli.ts",
34-
templated_args = [
35-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
36-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
37-
"--bazel_patch_module_resolver",
38-
"--node_options=--inspect-brk",
39-
filePath,
40-
],
32+
templated_args = ["--node_options=--inspect-brk", filePath],
4133
)
4234

4335
npm_package_bin(
@@ -46,6 +38,9 @@ def partial_compliance_golden(filePath):
4638
testonly = True,
4739
stdout = "%s/_generated.js" % path,
4840
link_workspace_root = True,
41+
# Disable the linker and rely on patched resolution which works better on Windows
42+
# and is less prone to race conditions when targets build concurrently.
43+
args = ["--nobazel_run_linker"],
4944
visibility = [":__pkg__"],
5045
data = [],
5146
)

packages/core/test/render3/perf/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
load("//tools:defaults.bzl", "app_bundle", "jasmine_node_test", "ng_benchmark", "ts_library")
1+
load("//tools:defaults.bzl", "app_bundle", "jasmine_node_test", "ts_library")
2+
load("//tools:ng_benchmark.bzl", "ng_benchmark")
23

34
package(default_visibility = ["//visibility:private"])
45

tools/circular_dependency_test/index.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
55

6-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
6+
load("//tools:defaults.bzl", "nodejs_test")
77

88
MADGE_CONFIG_LABEL = "//tools/circular_dependency_test:madge-resolve.config.js"
99

tools/defaults.bzl

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Re-export of some bazel rules with repository-wide defaults."""
22

33
load("@rules_pkg//:pkg.bzl", "pkg_tar")
4-
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm")
4+
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _nodejs_test = "nodejs_test", _npm_package_bin = "npm_package_bin", _pkg_npm = "pkg_npm")
55
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
66
load("@npm//@bazel/concatjs:index.bzl", _concatjs_devserver = "concatjs_devserver", _ts_config = "ts_config", _ts_library = "ts_library")
77
load("@npm//@bazel/rollup:index.bzl", _rollup_bundle = "rollup_bundle")
@@ -10,7 +10,6 @@ load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protract
1010
load("@npm//typescript:index.bzl", "tsc")
1111
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
1212
load("@npm//@angular/dev-infra-private/bazel/benchmark/app_bundling:index.bzl", _app_bundle = "app_bundle")
13-
load("//tools:ng_benchmark.bzl", _ng_benchmark = "ng_benchmark")
1413
load("@npm//@angular/dev-infra-private/bazel/http-server:index.bzl", _http_server = "http_server")
1514
load("@npm//@angular/dev-infra-private/bazel/karma:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
1615
load("@npm//@angular/dev-infra-private/bazel/api-golden:index.bzl", _api_golden_test = "api_golden_test", _api_golden_test_npm_package = "api_golden_test_npm_package")
@@ -391,14 +390,28 @@ def protractor_web_test_suite(**kwargs):
391390
**kwargs
392391
)
393392

394-
def ng_benchmark(**kwargs):
395-
"""Default values for ng_benchmark"""
396-
_ng_benchmark(**kwargs)
397-
398-
def nodejs_binary(data = [], **kwargs):
399-
"""Default values for nodejs_binary"""
393+
def nodejs_binary(data = [], templated_args = [], **kwargs):
400394
_nodejs_binary(
401395
data = data + ["@npm//source-map-support"],
396+
# Disable the linker and rely on patched resolution which works better on Windows
397+
# and is less prone to race conditions when targets build concurrently.
398+
templated_args = ["--nobazel_run_linker"] + templated_args,
399+
**kwargs
400+
)
401+
402+
def nodejs_test(templated_args = [], **kwargs):
403+
_nodejs_test(
404+
# Disable the linker and rely on patched resolution which works better on Windows
405+
# and is less prone to race conditions when targets build concurrently.
406+
templated_args = ["--nobazel_run_linker"] + templated_args,
407+
**kwargs
408+
)
409+
410+
def npm_package_bin(args = [], **kwargs):
411+
_npm_package_bin(
412+
# Disable the linker and rely on patched resolution which works better on Windows
413+
# and is less prone to race conditions when targets build concurrently.
414+
args = ["--nobazel_run_linker"] + args,
402415
**kwargs
403416
)
404417

@@ -440,9 +453,10 @@ def jasmine_node_test(bootstrap = [], **kwargs):
440453
]
441454
configuration_env_vars = kwargs.pop("configuration_env_vars", [])
442455

443-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
444-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
445-
templated_args = ["--bazel_patch_module_resolver"] + kwargs.pop("templated_args", [])
456+
# Disable the linker and rely on patched resolution which works better on Windows
457+
# and is less prone to race conditions when targets build concurrently.
458+
templated_args = ["--nobazel_run_linker"] + kwargs.pop("templated_args", [])
459+
446460
for label in bootstrap:
447461
deps += [label]
448462
templated_args += ["--node_options=--require=$$(rlocation $(rootpath %s))" % label]

tools/ng_benchmark.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# found in the LICENSE file at https://angular.io/license
55
"""Bazel macro for running Angular benchmarks"""
66

7-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
7+
load("//tools:defaults.bzl", "nodejs_binary")
88

99
def ng_benchmark(name, bundle):
1010
"""

tools/saucelabs/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
1+
load("//tools:defaults.bzl", "nodejs_binary")
22

33
package(default_visibility = ["//visibility:public"])
44

tools/size-tracking/index.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
55

6-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test")
6+
load("//tools:defaults.bzl", "nodejs_binary", "nodejs_test")
77

88
"""
99
Macro that can be used to track the size of a given input file by inspecting

tools/symbol-extractor/index.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
55

6-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test")
6+
load("//tools:defaults.bzl", "nodejs_binary", "nodejs_test")
77

88
"""
99
This test verifies that a set of top level symbols from a javascript file match a gold file.
@@ -25,9 +25,9 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
2525
data = all_data,
2626
entry_point = entry_point,
2727
tags = kwargs.pop("tags", []) + ["symbol_extractor"],
28-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
29-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
30-
templated_args = ["--bazel_patch_module_resolver", "$(rootpath %s)" % src, "$(rootpath %s)" % golden],
28+
# Disable the linker and rely on patched resolution which works better on Windows
29+
# and is less prone to race conditions when targets build concurrently.
30+
templated_args = ["--nobazel_run_linker", "$(rootpath %s)" % src, "$(rootpath %s)" % golden],
3131
**kwargs
3232
)
3333

@@ -36,8 +36,8 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
3636
testonly = True,
3737
data = all_data,
3838
entry_point = entry_point,
39-
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
40-
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
41-
templated_args = ["--bazel_patch_module_resolver", "$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
39+
# Disable the linker and rely on patched resolution which works better on Windows
40+
# and is less prone to race conditions when targets build concurrently.
41+
templated_args = ["--nobazel_run_linker", "$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
4242
**kwargs
4343
)

0 commit comments

Comments
 (0)