bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.13k stars 4.05k forks source link

Allow for glob of packages #1421

Closed abergmeier closed 8 years ago

abergmeier commented 8 years ago

Currently you cannot glob for packages. Now we could use this quite a bit so we can execute certain rules for all certain packages in a repo of a certain type (named specially).

hermione521 commented 8 years ago

Is this what you are looking for?

kchodorow commented 8 years ago

Or possibly http://www.bazel.io/docs/be/general.html#genquery.

abergmeier commented 8 years ago

@hermione521 Not really sure what you mean.

hermione521 commented 8 years ago

Oops... Sorry I misread your question. It's only for test.

abergmeier commented 8 years ago

@kchodorow Is it me or is there no way of querying packages by pattern? At least I tried genquery but all I get is none. That being said - using :all does not complain when being used - contrary to documentation.

kchodorow commented 8 years ago

You might be looking for buildfiles(expr) (and opts = ["--output=package"]). If not, can you give an example?

abergmeier commented 8 years ago

I would like to find all packages with suffix .foo.bar in the name (e.g. mygreatname.foo.bar) Tried stuff like:

result = genquery(
  expression = "*.intmat.dir",
  opts = ["--output=package"],
  scope = [],
)

and all I get is result as None.

kchodorow commented 8 years ago

That isn't the format of any of that... try starting with bazel query 'filter(.foo.bar, //...)', mess around with that until it's giving you what you want, then translate to genquery. Take a look at http://www.bazel.io/docs/query.html.

ahumesky commented 8 years ago

Do you mean that you have something like this:

project
├── BUILD
├── bar
│   ├── b
│   └── BUILD
└── foo
    ├── a
    └── BUILD

and you want to have a glob in project/BUILD that can find project/foo/a and project/bar/b, but it doesn't work because glob doesn't go past package boundaries? The usual solution to this is to put filegroup rules in project/foo/BUILD and project/bar/BUILD and then reference those filegroups in project/BUILD.

Or do you mean that there are rules in those build files that you want to run, and you don't want to manually figure out what those rules are? One way to to do this is to construct a query like Kristina says, and use that for the targets to build, e.g. bazel build $(bazel query '.....'). genquery would allow you to put the query into your build files, so you don't have to maintain the query externally to the build system, unfortunately it doesn't appear that genquery allows recursive patterns (i.e. "//...").

abergmeier commented 8 years ago

I have something like this:

project
├── BUILD
├── mynice.intmat.dir
│   ├── a
│   └── BUILD
└── myother.intmat.dir
    ├── a
    └── BUILD

And I want to execute a certain rule from project/BUILD for every *.intmat.dir. Reason is that people can keep adding these directories without any other housekeeping. As you said, the limitations in genquery are sadly preventing me from doing this :(

As a little background: We do it in project/BUILD because we need to combine various outputs by various packages.

ahumesky commented 8 years ago

And I want to execute a certain rule from project/BUILD for every *.intmat.dir

Do you mean that you want a rule in project/BUILD to automatically depend on rules in every subpackage? I'm not sure that there is a way to do that automatically.

One thing you could do is not have build files in the subdirectories, and do everything from project/BUILD. That way, that BUILD file can glob over those directories. I'm not sure if that is practical for you though.

dslomov commented 8 years ago

Sounds like no action is needed.

abergmeier commented 8 years ago

@dslomov Correct. Thanks for maintaining that :)

jxramos commented 4 years ago

I hit this blocker too needing to run a parametrized pytest that executed upon all the cpp binary hits matching a certain naming convention. I found out I cannot run bazel query commands from within a bazel py_test because that test doesn't run in a bazel workspace. I tried a workaround with a genquery but the scope attribute could not be properly tamed I soon found out because in general...

BUILD files do not support wildcard dependencies. https://docs.bazel.build/versions/master/be/general.html#genquery