2

I have an integration test target which uses runfiles from two different targets:

java_test(
  name = "test",
  srcs = ["Test.java"],
  data = ["//package:resource1", "//package:resource2"],
  ...
)

The first one is a filegroup:

filegroup(
    name = "resource1",
    srcs = glob(
        ["test-resources/sample-repo/**"],
        exclude_directories = 0,
    ),
    visibility = ["//visibility:public"],
)

and the second one is a genrule:

genrule(
    name = "resource2",
    srcs = [],
    outs = [
        "test-resources/sample-repo/file1",
        "test-resources/sample-repo/file2",
    ],
    cmd = "$(location //package:tool) -d $(RULEDIR)/test-resources/sample-repo",
    tools = ["//package:tool"],
    visibility = ["//visibility:public"],
)

The test requires the files obtained from both the filegroup and the genrule to be placed in a single directory (let's say: test-resources/sample-repo).

However, apparently it is not possible to achieve that using the method described above:

WARNING: [path to my repo]/BUILD:8:17: runfiles symlink test/test-resources/sample-repo/file1 -> bazel-out/k8-fastbuild/bin/test/test-resources/sample-repo/file1 obscured by test/test-resources/sample-repo -> test/test-resources/sample-repo
WARNING: [path to my repo]/BUILD:8:17: runfiles symlink test/test-resources/sample-repo/file2 -> bazel-out/k8-fastbuild/bin/test/test-resources/sample-repo/file2 obscured by test/test-resources/sample-repo -> test/test-resources/sample-repo

My last resort would be copying the files at runtime, but I'd rather avoid it. Is there any way to gather runfiles from multiple targets in a single directory?

agluszak
  • 90
  • 1
  • 6

1 Answers1

0

Try omitting exclude_directories = 0 (was that needed for something else?).

With exclude_directories = 0 Bazel will symlink directories in the runfiles tree. In the case of the filegroup, Bazel creates a symlink to the directory in the source tree (test-resources/sample-repo). But then it also needs to symlink the generated files from the output directory into the same spot in the runfiles tree -- but that spot is a symlink. So there's no where to put those symlinks (besides the source tree itself... but Bazel by design doesn't modify the source tree).

ahumesky
  • 4,203
  • 8
  • 12
  • `test-resources/sample-repo` contains subdirectories which are needed as well – agluszak Apr 05 '22 at 20:54
  • with `**` the glob should pick up every source file under `test-resources/sample-repo` -- does something go missing? – ahumesky Apr 06 '22 at 20:13
  • Yup - the files from subdirectories are missing – agluszak Apr 06 '22 at 22:51
  • Are there BUILD files in those subdirectories (i.e. making those directories packages)? glob() will not traverse into subpackages – ahumesky Apr 07 '22 at 15:37
  • Yup, there are BUILD files in those directories. `test-resources/sample-repo` is a different workspace (it contains a WORKSPACE file). Our case is that we write a tool integrating with Bazel and in that folder we have a sample repository for an e2e test into which our tool would normally be installed. – agluszak Apr 08 '22 at 12:19