Skip to content

Commit 79bedc5

Browse files
committed
fix: also link "runfiles" mappings from *_test rules
Add test for the above to the integration tests
1 parent c95f5d8 commit 79bedc5

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

internal/linker/link_node_modules.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ def get_module_mappings(label, attrs, vars, rule_kind, srcs = [], workspace_name
107107
(label, k, mappings[k], v)), "deps")
108108
_debug(vars, "target %s propagating module mapping %s: %s" % (dep, k, v))
109109

110-
# A package which was reachable transitively via a *_binary
110+
# A package which was reachable transitively via a *_binary or *_test
111111
# rule is assumed to be in the runfiles of that binary,
112112
# so we switch the linker target root.
113113
# In theory we ought to be able to tell that the files really are
114114
# propagated through the runfiles output of the target we are visiting
115115
# but it seems that this info is only available in Bazel Java internals.
116116
# TODO: revisit whether this is the correct condition after downstream testing
117-
if rule_kind.endswith("_binary"):
117+
if rule_kind.endswith("_binary") or rule_kind.endswith("_test"):
118118
mappings[k] = ["runfiles", v[1]]
119119
else:
120120
mappings[k] = v

internal/linker/test/integration/BUILD.bazel

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ genrule(
1212
toolchains = ["@build_bazel_rules_nodejs//toolchains/node:toolchain"],
1313
)
1414

15-
# Make our program executable and include the linker
16-
# The runfiles here are only the ones included with the program itself
17-
sh_binary(
15+
# A program from a *_test rule with a module mapped package that will
16+
# by linked as "runfiles" mapping by downstream rules
17+
sh_test(
1818
name = "some_program",
1919
srcs = ["some_program.sh"],
2020
data = [
@@ -43,6 +43,7 @@ sh_binary(
4343
"@bazel_tools//tools/bash/runfiles",
4444
"@build_bazel_rules_nodejs//toolchains/node:node_bin",
4545
],
46+
testonly = True,
4647
)
4748

4849
# How a users rule might want to run a node program
@@ -54,10 +55,18 @@ linked(
5455
# NB: reference the copy of index.js in the output folder
5556
"//%s/absolute_import:copy_to_bin" % package_name(),
5657
":run_program",
58+
# NB: Verify that a direct dep on :some_program and a transitive dep on
59+
# the same via :run_program works with the linker. These should both
60+
# bring in the transitive_static_linked mapping to
61+
# ["runfiles", "build_bazel_rules_nodejs/internal/linker/test/integration/transitive_static_linked_pkg"].
62+
# This tests that the linker does "runfiles" mappings for both *_binary target
63+
# and *_test targets.
64+
":some_program",
5765
"//internal/linker/test/integration/dynamic_linked_pkg",
5866
"//internal/linker/test/integration/dynamic_linked_scoped_pkg",
5967
"@npm//semver",
6068
],
69+
testonly = True,
6170
)
6271

6372
golden_file_test(

0 commit comments

Comments
 (0)