Skip to content

Commit 1cbf09d

Browse files
Wyveraldcopybara-github
authored andcommitted
Do not record or check repo mapping entries for repos defined in WORKSPACE
Mappings for repos defined in WORKSPACE are extremely annoying to verify given the chunked loading (we'd have to record which chunk the repo mapping was used in, and then load that chunk while verifying). This is extremely not worth the effort (especially since nobody really uses repo mappings in WORKSPACE) so we just don't record it. This also means, during verification, we can safely use the main repo mapping without WORKSPACE (since repos defined in Bzlmod can't see stuff from WORKSPACE anyway). Fixes #21289. Closes #21393. PiperOrigin-RevId: 608258493 Change-Id: Ife6a01221e6f5e1685d859eaa5acc8b370ab8483
1 parent 9cc125e commit 1cbf09d

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,17 @@ private RepositoryDirectoryValue.Builder fetchInternal(
319319
new RepoRecordedInput.EnvVar(envKey), clientEnvironment.get(envKey));
320320
}
321321

322-
for (Table.Cell<RepositoryName, String, RepositoryName> repoMappings :
323-
repoMappingRecorder.recordedEntries().cellSet()) {
324-
recordedInputValues.put(
325-
new RepoRecordedInput.RecordedRepoMapping(
326-
repoMappings.getRowKey(), repoMappings.getColumnKey()),
327-
repoMappings.getValue().getName());
322+
// For repos defined in Bzlmod, record any used repo mappings in the marker file.
323+
// Repos defined in WORKSPACE are impossible to verify given the chunked loading (we'd have to
324+
// record which chunk the repo mapping was used in, and ain't nobody got time for that).
325+
if (!isWorkspaceRepo(rule)) {
326+
for (Table.Cell<RepositoryName, String, RepositoryName> repoMappings :
327+
repoMappingRecorder.recordedEntries().cellSet()) {
328+
recordedInputValues.put(
329+
new RepoRecordedInput.RecordedRepoMapping(
330+
repoMappings.getRowKey(), repoMappings.getColumnKey()),
331+
repoMappings.getValue().getName());
332+
}
328333
}
329334

330335
env.getListener().post(resolved);

src/main/java/com/google/devtools/build/lib/rules/repository/RepoRecordedInput.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,12 @@ public String toStringInternal() {
559559

560560
@Override
561561
public SkyKey getSkyKey(BlazeDirectories directories) {
562-
return RepositoryMappingValue.key(sourceRepo);
562+
// Since we only record repo mapping entries for repos defined in Bzlmod, we can request the
563+
// WORKSPACE-less version of the main repo mapping (as no repos defined in Bzlmod can see
564+
// stuff from WORKSPACE).
565+
return sourceRepo.isMain()
566+
? RepositoryMappingValue.KEY_FOR_ROOT_MODULE_WITHOUT_WORKSPACE_REPOS
567+
: RepositoryMappingValue.key(sourceRepo);
563568
}
564569

565570
@Override

src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package com.google.devtools.build.lib.rules.repository;
1717

18-
import static com.google.devtools.build.lib.cmdline.LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER;
1918
import static java.nio.charset.StandardCharsets.UTF_8;
2019

2120
import com.google.common.annotations.VisibleForTesting;
@@ -394,12 +393,9 @@ private boolean shouldUseVendorRepos(Environment env, RepositoryFunction handler
394393
}
395394

396395
private boolean shouldExcludeRepoFromVendoring(RepositoryFunction handler, Rule rule) {
397-
return handler.isLocal(rule) || handler.isConfigure(rule) || isWorkspaceRepo(rule);
398-
}
399-
400-
private boolean isWorkspaceRepo(Rule rule) {
401-
// All workspace repos are under //external, while bzlmod repo rules are not
402-
return rule.getPackage().getPackageIdentifier().equals(EXTERNAL_PACKAGE_IDENTIFIER);
396+
return handler.isLocal(rule)
397+
|| handler.isConfigure(rule)
398+
|| RepositoryFunction.isWorkspaceRepo(rule);
403399
}
404400

405401
@Nullable

src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.devtools.build.lib.rules.repository;
1616

1717
import static com.google.common.base.Preconditions.checkState;
18+
import static com.google.devtools.build.lib.cmdline.LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER;
1819

1920
import com.google.common.annotations.VisibleForTesting;
2021
import com.google.common.base.Preconditions;
@@ -137,6 +138,11 @@ public static void setupRepoRoot(Path repoRoot) throws RepositoryFunctionExcepti
137138
}
138139
}
139140

141+
public static boolean isWorkspaceRepo(Rule rule) {
142+
// All workspace repos are under //external, while bzlmod repo rules are not
143+
return rule.getPackage().getPackageIdentifier().equals(EXTERNAL_PACKAGE_IDENTIFIER);
144+
}
145+
140146
protected void setupRepoRootBeforeFetching(Path repoRoot) throws RepositoryFunctionException {
141147
setupRepoRoot(repoRoot);
142148
}

src/test/shell/bazel/starlark_repository_test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,10 +2660,12 @@ bazel_dep(name="bar")
26602660
local_path_override(module_name="bar", path="bar")
26612661
EOF
26622662
touch BUILD
2663+
echo 'load("@r//:r.bzl", "pi"); print(pi)' > WORKSPACE.bzlmod
26632664
cat > r.bzl <<EOF
26642665
def _r(rctx):
26652666
print("I see: " + str(Label("@data")))
26662667
rctx.file("BUILD", "filegroup(name='r')")
2668+
rctx.file("r.bzl", "pi=3.14")
26672669
r=repository_rule(_r)
26682670
EOF
26692671
mkdir foo
@@ -2704,11 +2706,13 @@ bazel_dep(name="bar")
27042706
local_path_override(module_name="bar", path="bar")
27052707
EOF
27062708
touch BUILD
2709+
echo 'load("@r//:r.bzl", "pi"); print(pi)' > WORKSPACE.bzlmod
27072710
cat > r.bzl <<EOF
27082711
CONSTANT = Label("@data")
27092712
def _r(rctx):
27102713
print("I see: " + str(CONSTANT))
27112714
rctx.file("BUILD", "filegroup(name='r')")
2715+
rctx.file("r.bzl", "pi=3.14")
27122716
r=repository_rule(_r)
27132717
EOF
27142718
mkdir foo

0 commit comments

Comments
 (0)