admin管理员组

文章数量:1404927

Given a directory structure like:

WORKSPACE
java/
  BUILD
  test.bash
  dev/enola/io
    BUILD
    Resource.java

in I want to run a Lint-like test.bash sort of script over all of my **/*.java with this java/BUILD:

sh_test(
    name = "test",
    srcs = ["test.bash"],
    data = glob(["**/*.java"]),
)

Running bazelisk //java:test should test.bash, with dev/enola/io/Resource.java in the runfiles.

Instead, it fails with "Error in glob: glob pattern '**/*.java' didn't match anything".

I understand that this happens because there are (of course) [many other] BUILD files within java/... - which makes Bazel "hide" (?) their **/*.java.

But how does one typically still somehow do this with Bazel?

Given a directory structure like:

WORKSPACE
java/
  BUILD
  test.bash
  dev/enola/io
    BUILD
    Resource.java

in https://github/enola-dev/enola/pull/1202 I want to run a Lint-like test.bash sort of script over all of my **/*.java with this java/BUILD:

sh_test(
    name = "test",
    srcs = ["test.bash"],
    data = glob(["**/*.java"]),
)

Running bazelisk //java:test should test.bash, with dev/enola/io/Resource.java in the runfiles.

Instead, it fails with "Error in glob: glob pattern '**/*.java' didn't match anything".

I understand that this happens because there are (of course) [many other] BUILD files within java/... - which makes Bazel "hide" (?) their **/*.java.

But how does one typically still somehow do this with Bazel?

Share Improve this question asked Mar 9 at 9:09 vorburgervorburger 3,93836 silver badges43 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If you go up the dir structure, the first BUILD file is the one "owning" the file. Whether it can be accessed from outside is regulated by the visibility, which by default is not public, hence the error. From outside, the file is simply not visible.

Now, you can change the default visibility, but maybe it would be smartest to define a filegroup instead (in the owning BUILD file) and export that. You could also give it a speaking name.

Another question you should ask yourself is if you shouldn't merge the two BUILD files. If they are so deeply connected, splitting them up would be questionable.

本文标签: How to use dataglob in shtest over directory containing other BUILDbazel filesStack Overflow