Support sibling repository execution root layout.
Enable building and depending on targets in subpackages of //external.
Closes #10604.
1) Added --experimental_sibling_repository_layout starlark semantics flag
2) When enabled, the flag changes the execution root of external repository source artifacts (non-default/main repository) from <execroot cwd>/external/reponame to <execroot cwd>/../reponame. Therefore, this allows plantSymlinkForest to plant the "external" top level directory in the execution root, like any other top level source directory in the main repository.
3) The artifact roots (and therefore root relative path) of external repos' source artifacts are left unchanged. This enables RepositoryName#getRunfilesPath and RepositoryName#getSourceRoot to remain unchanged. Thus we only needed to thread StarlarkSemantics#experimentalAllowExternalDirectory from BazelRepositoryModule / ruleContext to callsites of RepositoryName#getExecPath(boolean allowExternalRepository).
This took a while because I had to revert some changes in order to make the other changes less intrusive.
Specifically, for external source artifacts, rosica's change set output_base/external as a source root, instead output_base. This causes all external source artifact's rootRelativePath to drop "external" as a prefix. By retaining the output_base source root, I was able to undo a lot of the intrusive changes.
Another caveat: this change currently clobbers output artifacts from external repositories and subpackages of //external in the same derived output root (bazel-bin/external). This will be a problem if external repository names conflicts with directory names in the top-level external directory. We'll probably have to draft up a design following this change.
PiperOrigin-RevId: 294991422
diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
index af485de..b13f2dc 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
@@ -121,6 +121,7 @@
// <== Add new options here in alphabetic order ==>
"--debug_depset_depth=" + rand.nextBoolean(),
"--experimental_action_args=" + rand.nextBoolean(),
+ "--experimental_sibling_repository_layout=" + rand.nextBoolean(),
"--experimental_allow_incremental_repository_updates=" + rand.nextBoolean(),
"--experimental_aspect_output_propagation=" + rand.nextBoolean(),
"--experimental_build_setting_api=" + rand.nextBoolean(),
@@ -174,6 +175,7 @@
// <== Add new options here in alphabetic order ==>
.debugDepsetDepth(rand.nextBoolean())
.experimentalActionArgs(rand.nextBoolean())
+ .experimentalSiblingRepositoryLayout(rand.nextBoolean())
.experimentalAllowIncrementalRepositoryUpdates(rand.nextBoolean())
.experimentalAspectOutputPropagation(rand.nextBoolean())
.experimentalBuildSettingApi(rand.nextBoolean())