Typically for one package to get files from another package, you would define a file group in the other package with the files you're interested in:
foo/BUILD:
filegroup(
name = "files",
srcs = glob(["*.ext"]),
visibility = ["//visibility:public"],
)
bar/BUILD:
java_binary(
...,
resources = ["//foo:files"],
...,
)
However, a macro cannot inspect the values or providers of a target (i.e. //foo:files). So the next thing one might try is to glob the files and put that into a variable:
foo/BUILD:
FILES = glob(["*.ext"])
but t
he problem then is that you can't load that variable into another BUILD file:
load("//foo:BUILD", "FILES")
def macro(...):
if "foo" in FILES:
...
that would give:
ERROR: BUILD:1:6: in load statement: The label must reference a file with extension '.bzl'
Is there any way that you can move what you'd like to do into Starlark? Then you can have a "srcs" attribute or similar, put the filegroup in there, and it would work as usual in Starlark.