Skip to content

Commit

Permalink
fix: also link "runfiles" mappings from *_test rules
Browse files Browse the repository at this point in the history
Add test for the above to the integration tests
  • Loading branch information
gregmagolan committed Jan 29, 2020
1 parent c95f5d8 commit 79bedc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/linker/link_node_modules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def get_module_mappings(label, attrs, vars, rule_kind, srcs = [], workspace_name
(label, k, mappings[k], v)), "deps")
_debug(vars, "target %s propagating module mapping %s: %s" % (dep, k, v))

# A package which was reachable transitively via a *_binary
# A package which was reachable transitively via a *_binary or *_test
# rule is assumed to be in the runfiles of that binary,
# so we switch the linker target root.
# In theory we ought to be able to tell that the files really are
# propagated through the runfiles output of the target we are visiting
# but it seems that this info is only available in Bazel Java internals.
# TODO: revisit whether this is the correct condition after downstream testing
if rule_kind.endswith("_binary"):
if rule_kind.endswith("_binary") or rule_kind.endswith("_test"):
mappings[k] = ["runfiles", v[1]]
else:
mappings[k] = v
Expand Down
15 changes: 12 additions & 3 deletions internal/linker/test/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ genrule(
toolchains = ["@build_bazel_rules_nodejs//toolchains/node:toolchain"],
)

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

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

golden_file_test(
Expand Down

0 comments on commit 79bedc5

Please sign in to comment.