Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 711
Joseph Garvin Avatar asked Jun 28 '16 02:06

Joseph Garvin


2 Answers

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.

like image 63
kristina Avatar answered Oct 08 '22 16:10

kristina


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.

like image 28
Damien Martin-Guillerez Avatar answered Oct 08 '22 14:10

Damien Martin-Guillerez