aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-02-25 01:12:22 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-02-25 14:14:35 +0000
commit86c319e313529b52da0f0fc6062c27a7e75afe5b (patch)
tree8ae5b90ffc8fa2783c53b4af75bebe53769747b2 /src/main/java
parent63da2e7998720cf20d35a961e316c786f3f4ec87 (diff)
Update the glob documentation to reflect a semantic change made a very long time ago where glob(['**'], exclude_directories = 0) doesn't match the package's directory. Also add tests for this behavior.
Also update Skyframe globbing to have these semantics. Any discrepancy has always been problematic, but now that we have Skyframe-hybrid globbing it's a lot more dangerous and consequential. Alternatives considered: do this the other way around (keep the stale documentation as-is and instead update legacy globbing). This would potentially require changing existing usages from stuff like 'data = glob(["**"], exclude_directories = 0)' to 'data = [x for x in glob(["**"], exclude_directories = 0) where x != '']'. I think this is too messy, so long as there is a valid use-case for globs matching directories in the first place. -- MOS_MIGRATED_REVID=115511504
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm9
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java3
2 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm b/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm
index e6d89c0054..b1b94dc40b 100644
--- a/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm
+++ b/src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm
@@ -454,6 +454,15 @@ There are several important limitations and caveats:
If a rule and a source file with the same name both exist in the package, the glob will
return the outputs of the rule instead of the source file.
</li>
+
+ <li>
+ The "**" wildcard has one corner case: the pattern
+ <code>"**"</code> doesn't match the package's directory path. That is to
+ say, <code>glob(["**"], exclude_directories = 0)</code> matches all files
+ and directories transitively strictly under the current package's directory
+ (but of course not going into directories of subpackages - see the previous
+ note about that).
+ </li>
</ol>
<p>
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java
index e1c877f455..e233cdfdd5 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/GlobFunction.java
@@ -90,7 +90,8 @@ public final class GlobFunction implements SkyFunction {
// "**" also matches an empty segment, so try the case where it is not present.
if ("**".equals(patternHead)) {
if (patternTail == null) {
- if (!glob.excludeDirs()) {
+ // Recursive globs aren't supposed to match the package's directory.
+ if (!glob.excludeDirs() && !globSubdir.equals(PathFragment.EMPTY_FRAGMENT)) {
matches.add(globSubdir);
}
} else {