-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For source directory action inputs, depend on all files in the subtree
This fixes a number of long-standing correctness issues where Bazel did not notice if files within the purview of an action changed. Consider this BUILD rule: genrule( name = "bad", outs = ["ls.txt"], srcs = ["dir"], cmd = "ls -l test/dir > $@", ) If "dir" is a directory, then Bazel does not notice changes to files underneath dir, and also does not give an error message. It only emits a warning like this: "WARNING: /path/to/BUILD:1:1: input 'test/dir' to //test:bad is a directory; dependency checking of directories is unsound" We use a startup flag for rollout since the new code requires additional Skyframe dependencies. Use like this: bazel --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1 build ... With this change, Bazel assumes that all the files underneath dir/ are action inputs (i.e., it implicitly globs all the files) and reruns the action whenever any of these files change. The main differences to glob(["dir/**"]) are: - the file names do not have to be valid labels; the label syntax currently restricts the allowed characters to a small subset of UTF-8 (mainly ASCII) - the files cannot be directly referenced from another package unless they are also explicitly mentioned in the package - globbing happens during execution, not loading; this can have a significant effect on performance for packages that have a lot of globs / directory references - globs are evaluated eagerly during loading, even if only a single rule from that package is needed This change does not affect remote execution, which continues to not allow such inputs, although this could be changed subsequently. We may in the future require that directory references in BUILD files end with a trailing forward slash ('/') to indicate this fact to a reader of the BUILD file. PiperOrigin-RevId: 218817101
- Loading branch information
Showing
4 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/google/devtools/build/lib/skyframe/TrackSourceDirectoriesFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.skyframe; | ||
|
||
/** | ||
* A flag to enable / disable tracking of source directories. Uses a system property which can be | ||
* set via a startup flag. The intention is for this code to be temporary, so I didn't want to add | ||
* a permanent flag to startup options (and there's already --host_jvm_args, which we can use to | ||
* roll this out). The flag affects Skyframe dependencies, so it needs to clear the Skyframe graph - | ||
* the easiest way to do that is to restart the server, which is done when --host_jvm_args changes. | ||
*/ | ||
public class TrackSourceDirectoriesFlag { | ||
private static final boolean TRACK_SOURCE_DIRECTORIES; | ||
|
||
static { | ||
TRACK_SOURCE_DIRECTORIES = "1".equals(System.getProperty("BAZEL_TRACK_SOURCE_DIRECTORIES")); | ||
} | ||
|
||
public static boolean trackSourceDirectories() { | ||
return TRACK_SOURCE_DIRECTORIES; | ||
} | ||
|
||
// Private constructor to prevent instantiation. | ||
private TrackSourceDirectoriesFlag() { | ||
} | ||
} |