Joseph Garvin
Joseph Garvin

Reputation: 21974

Does Bazel have the same problems as CMake with file globbing?

I'm starting a new project and need to pick a build system. I hate having to manually add every C++ source file to my build rules, because it's the kind of thing that should be automated by 2016 and it makes for extra busywork when refactoring (rename the class in the header, and the source file, and the build system file...).

I was starting to use CMake with recursive file globbing when I came across this post: Specify source files globally with GLOB?

Which suggests that globbing is evil, because of CMake using two phases for builds (cmake and make) and in normal use the user only rerunning the second phase (make).

At first glance Bazel also allows file globbing. Is it evil to use with Bazel? Is running find over a code base such a scaling problem that build systems really need to avoid it?

Upvotes: 5

Views: 3376

Answers (2)

kris
kris

Reputation: 23591

Bazel does not have the issues mentioned in that post, i.e.:

(We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.)

Bazel will always notice if anything was added, removed or changed from the glob's matches, and rebuild accordingly. Globbing will never give you stale results with Bazel.

There are a couple caveats and limitations listed in the build encyclopedia for globbing, so you should read that over before using globs.

Also, you can see what is being globbed using a bazel query:

bazel query '//path/to/your:target' --output=build
# /Users/kchodorow/gitroot/path/to/your/BUILD:7:1
java_library(
    name = "target",
    srcs = ["//path/to/your:A.java", "//path/to/your:B.java"],
)

This will print the "evaluated" glob, so you can play around and see how Bazel tracks the inputs.

Upvotes: 7

Damien Martin-Guillerez
Damien Martin-Guillerez

Reputation: 2370

It should be find to use glob in Bazel, it can cause a long analysis phase for big globs but if you use the --watchfs flag then the file system change will be tracked watching file system events instead of stating all the files so incremental build should be really fast.

Upvotes: 3

Related Questions