Skip to content

Commit

Permalink
Be explicit about alowing empty globs
Browse files Browse the repository at this point in the history
  • Loading branch information
limdor committed Apr 24, 2022
1 parent 5cb8456 commit cbba6ed
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ filegroup(
srcs = glob(
[".git/**"],
exclude = [".git/**/*[*"], # gitk creates temp files with []
allow_empty = True,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void testInvalidVisibilityWithSelect() throws Exception {
" hdrs = select({",
" ':fastbuild': glob([",
" '*.h',",
" ]),",
" ], allow_empty = True),",
" }),",
")");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public void selectsWithGlobsWrongType() throws Exception {
" cmd = 'echo' + select({",
" '//conditions:a': 'a',",
" '//conditions:b': 'b',",
" }) + glob(['globbed.java']))");
" }) + glob(['globbed.java'], allow_empty = True))");

reporter.removeHandler(failFastHandler);
assertThrows(NoSuchTargetException.class, () -> getTarget("//foo:binary"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
"java_host_runtime_alias(name = 'current_host_java_runtime')",
"filegroup(name='langtools', srcs=['jdk/lib/tools.jar'])",
"filegroup(name='bootclasspath', srcs=['jdk/jre/lib/rt.jar'])",
"filegroup(name='extdir', srcs=glob(['jdk/jre/lib/ext/*']))",
"filegroup(name='extdir', srcs=glob(['jdk/jre/lib/ext/*'], allow_empty = True))",
"filegroup(name='java', srcs = ['jdk/jre/bin/java'])",
"filegroup(name='JacocoCoverage', srcs = ['JacocoCoverage_deploy.jar'])",
"exports_files([",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ private Package evaluateGlob(
scratch.file(
"globs/BUILD",
Starlark.format(
"result = glob(%r, exclude=%r, exclude_directories=%r)",
"result = glob(%r, exclude=%r, exclude_directories=%r, allow_empty = True)",
includes, excludes, excludeDirs ? 1 : 0),
resultAssertion);
return loadPackage("globs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testNonMultidexBuildStructure() throws Exception {
" name = 'nomultidex',",
" srcs = ['a.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = glob(['res/**']),",
" resource_files = glob(['res/**'], allow_empty = True),",
" multidex = 'off')");
internalTestNonMultidexBuildStructure("//java/foo:nomultidex");
}
Expand All @@ -70,7 +70,7 @@ public void testDefaultBuildStructure() throws Exception {
" name = 'default',",
" srcs = ['a.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = glob(['res/**']))");
" resource_files = glob(['res/**'], allow_empty = True))");
internalTestNonMultidexBuildStructure("//java/foo:default");
}

Expand All @@ -83,7 +83,7 @@ public void testManualMainDexMode() throws Exception {
" name = 'manual_main_dex',",
" srcs = ['a.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = glob(['res/**']),",
" resource_files = glob(['res/**'], allow_empty = True),",
" multidex = 'manual_main_dex',",
" main_dex_list = 'main_dex_list.txt')");
internalTestMultidexBuildStructure("//java/foo:manual_main_dex", MultidexMode.MANUAL_MAIN_DEX);
Expand All @@ -103,7 +103,7 @@ public void testLegacyMultidexBuildStructure() throws Exception {
" name = 'legacy',",
" srcs = ['a.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = glob(['res/**']),",
" resource_files = glob(['res/**'], allow_empty = True),",
" multidex = 'legacy')");
internalTestMultidexBuildStructure("//java/foo:legacy", MultidexMode.LEGACY);
}
Expand All @@ -122,7 +122,7 @@ public void testNativeMultidexBuildStructure() throws Exception {
" name = 'native',",
" srcs = ['a.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = glob(['res/**']),",
" resource_files = glob(['res/**'], allow_empty = True),",
" multidex = 'native')");
internalTestMultidexBuildStructure("//java/foo:native", MultidexMode.NATIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void writeDataBindingFilesWithNoResourcesDep() throws Exception {
" enable_data_binding = 1,",
" manifest = 'AndroidManifest.xml',",
" srcs = ['LibWithResourceFiles.java'],",
" resource_files = glob(['res/**']),",
" resource_files = glob(['res/**'], allow_empty = True),",
")");
scratch.file(
"java/android/lib_with_resource_files/LibWithResourceFiles.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ private static Iterable<Label> getSrcs(Package pkg, String targetName)
public void testOneNewElementInMultipleGlob() throws Exception {
scratch.file(
"foo/BUILD",
"sh_library(name = 'foo', srcs = glob(['*.sh']))",
"sh_library(name = 'bar', srcs = glob(['*.sh', '*.txt']))");
"sh_library(name = 'foo', srcs = glob(['*.sh'], allow_empty = True))",
"sh_library(name = 'bar', srcs = glob(['*.sh', '*.txt'], allow_empty = True))");
preparePackageLoading(rootDirectory);
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
Package pkg = validPackageWithoutErrors(skyKey);
Expand All @@ -590,8 +590,8 @@ public void testOneNewElementInMultipleGlob() throws Exception {
public void testNoNewElementInMultipleGlob() throws Exception {
scratch.file(
"foo/BUILD",
"sh_library(name = 'foo', srcs = glob(['*.sh', '*.txt']))",
"sh_library(name = 'bar', srcs = glob(['*.sh', '*.txt']))");
"sh_library(name = 'foo', srcs = glob(['*.sh', '*.txt'], allow_empty = True))",
"sh_library(name = 'bar', srcs = glob(['*.sh', '*.txt'], allow_empty = True))");
preparePackageLoading(rootDirectory);
SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo"));
Package pkg = validPackageWithoutErrors(skyKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void testChangeDirectory() throws Exception {

// A dummy directory that is not changed.
scratch.file("misc/BUILD",
"py_binary(name = 'misc', srcs = ['other.py'], data = glob(['*.txt']))");
"py_binary(name = 'misc', srcs = ['other.py'], data = glob(['*.txt'], allow_empty = True))");

sync("//python/hello:hello", "//misc:misc");

Expand Down Expand Up @@ -639,7 +639,7 @@ private void sync(String... labelStrings) throws Exception {
public void testInterruptLoadedTarget() throws Exception {
analysisMock.pySupport().setup(mockToolsConfig);
scratch.file("python/hello/BUILD",
"py_binary(name = 'hello', srcs = ['hello.py'], data = glob(['*.txt']))");
"py_binary(name = 'hello', srcs = ['hello.py'], data = glob(['*.txt'], allow_empty = True))");
Thread.currentThread().interrupt();
LoadedPackageProvider packageProvider =
new LoadedPackageProvider(skyframeExecutor.getPackageManager(), reporter);
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/integration/loading_phase_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ function test_glob_with_subpackage() {
assert_equals "3" $(wc -l "$TEST_log")

# glob returns an empty list, because t3.txt is outside the package
echo "exports_files(glob(['subpkg/t3.txt']))" >$pkg/p/BUILD
echo "exports_files(glob(['subpkg/t3.txt'], allow_empty = True))" >$pkg/p/BUILD
bazel query "$pkg/p:*" -k >$TEST_log || fail "Expected success"
expect_log "//$pkg/p:BUILD"
assert_equals "1" $(wc -l "$TEST_log")

# same test, with a nonexisting file
echo "exports_files(glob(['subpkg/no_glob.txt']))" >$pkg/p/BUILD
echo "exports_files(glob(['subpkg/no_glob.txt'], allow_empty = True))" >$pkg/p/BUILD
bazel query "$pkg/p:*" -k >$TEST_log || fail "Expected success"
expect_log "//$pkg/p:BUILD"
assert_equals "1" $(wc -l "$TEST_log")
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/integration/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ EOF
cat > cc/BUILD <<EOF
cc_binary(name='kitty',
srcs=['kitty.cc'],
data=glob(['*.txt']))
data=glob(['*.txt'], allow_empty = True))
EOF
}

Expand Down
2 changes: 1 addition & 1 deletion tools/android/android_sdk_repository_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def create_android_sdk_rules(
"build-tools/%s/lib/**" % build_tools_directory,
# Build tools version 24.0.0 added a lib64 folder.
"build-tools/%s/lib64/**" % build_tools_directory,
]),
], allow_empty = True),
)

for tool in ["aapt", "aapt2", "aidl", "zipalign"]:
Expand Down

0 comments on commit cbba6ed

Please sign in to comment.