Skip to content

Commit

Permalink
Recurse into //external if --experimental_sibling_repository_layout i…
Browse files Browse the repository at this point in the history
…s set when processing package directories.

PiperOrigin-RevId: 342025570
  • Loading branch information
Googler authored and copybara-github committed Nov 12, 2020
1 parent 37b6f9d commit 8fce67f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2028,16 +2028,19 @@ java_library(
":file_symlink_infinite_expansion_exception",
":file_symlink_infinite_expansion_uniqueness_function",
":package_lookup_value",
":precomputed_value",
":process_package_directory_result",
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata",
"//src/main/java/com/google/devtools/build/lib/analysis:blaze_directories",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/net/starlark/java/eval",
"//third_party:guava",
"//third_party:jsr305",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
Expand All @@ -40,6 +41,7 @@
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import net.starlark.java.eval.StarlarkSemantics;

/**
* Processes a directory that may contain a package and subdirectories for the benefit of processes
Expand Down Expand Up @@ -179,9 +181,18 @@ public ProcessPackageDirectoryResult getPackageExistenceAndSubdirDeps(
} catch (NoSuchPackageException e) {
throw new IllegalStateException(e);
}
StarlarkSemantics starlarkSemantics = PrecomputedValue.STARLARK_SEMANTICS.get(env);
if (env.valuesMissing()) {
return null;
}
return new ProcessPackageDirectoryResult(
pkgLookupValue.packageExists() && pkgLookupValue.getRoot().equals(rootedPath.getRoot()),
getSubdirDeps(dirListingValue, rootedPath, repositoryName, excludedPaths),
getSubdirDeps(
dirListingValue,
rootedPath,
repositoryName,
excludedPaths,
starlarkSemantics.getBool(BuildLanguageOptions.EXPERIMENTAL_SIBLING_REPOSITORY_LAYOUT)),
/** additionalValuesToAggregate= */
ImmutableMap.of());
}
Expand All @@ -190,7 +201,8 @@ private Iterable<SkyKey> getSubdirDeps(
DirectoryListingValue dirListingValue,
RootedPath rootedPath,
RepositoryName repositoryName,
ImmutableSet<PathFragment> excludedPaths) {
ImmutableSet<PathFragment> excludedPaths,
boolean siblingRepositoryLayout) {
Root root = rootedPath.getRoot();
PathFragment rootRelativePath = rootedPath.getRootRelativePath();
boolean followSymlinks = shouldFollowSymlinksWhenTraversing(dirListingValue.getDirents());
Expand All @@ -209,8 +221,9 @@ private Iterable<SkyKey> getSubdirDeps(
}
String basename = dirent.getName();
PathFragment subdirectory = rootRelativePath.getRelative(basename);
if (subdirectory.equals(LabelConstants.EXTERNAL_PACKAGE_NAME)) {
// Not a real package.
if (!siblingRepositoryLayout && subdirectory.equals(LabelConstants.EXTERNAL_PACKAGE_NAME)) {
// Subpackages under //external can be processed only when
// --experimental_sibling_repository_layout is set.
continue;
}

Expand Down
39 changes: 39 additions & 0 deletions src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2519,4 +2519,43 @@ EOF
bazel build a_bin >& $TEST_log || fail "Expected build/run to succeed"
}

function test_query_external_packages() {
setup_skylib_support

mkdir -p external/nested
mkdir -p not-external

cat > external/BUILD <<EOF
filegroup(
name = "a1",
srcs = [],
)
EOF
cat > external/nested/BUILD <<EOF
filegroup(
name = "a2",
srcs = [],
)
EOF

cat > not-external/BUILD <<EOF
filegroup(
name = "b",
srcs = [],
)
EOF

bazel query //... >& $TEST_log || fail "Expected build/run to succeed"
expect_log "//not-external:b"
expect_not_log "//external:a1"
expect_not_log "//external/nested:a2"

bazel query --experimental_sibling_repository_layout //... >& $TEST_log \ ||
fail "Expected build/run to succeed"
expect_log "//not-external:b"
# Targets in //external aren't supported yet.
expect_not_log "//external:a1"
expect_log "//external/nested:a2"
}

run_suite "external tests"

0 comments on commit 8fce67f

Please sign in to comment.