Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.1.0] Do not record any repo mapping entries in the RepoMappingRecorder for WORKSPACE repo rules #21457

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ private RepositoryDirectoryValue.Builder fetchInternal(
StarlarkThread thread = new StarlarkThread(mu, starlarkSemantics);
thread.setPrintHandler(Event.makeDebugPrintHandler(env.getListener()));
var repoMappingRecorder = new Label.RepoMappingRecorder();
repoMappingRecorder.mergeEntries(
rule.getRuleClassObject().getRuleDefinitionEnvironmentRepoMappingEntries());
thread.setThreadLocal(Label.RepoMappingRecorder.class, repoMappingRecorder);
// For repos defined in Bzlmod, record any used repo mappings in the marker file.
// Repos defined in WORKSPACE are impossible to verify given the chunked loading (we'd have to
// record which chunk the repo mapping was used in, and ain't nobody got time for that).
if (!isWorkspaceRepo(rule)) {
repoMappingRecorder.mergeEntries(
rule.getRuleClassObject().getRuleDefinitionEnvironmentRepoMappingEntries());
thread.setThreadLocal(Label.RepoMappingRecorder.class, repoMappingRecorder);
}

new BazelStarlarkContext(
BazelStarlarkContext.Phase.LOADING, // ("fetch")
Expand Down Expand Up @@ -321,17 +326,12 @@ private RepositoryDirectoryValue.Builder fetchInternal(
new RepoRecordedInput.EnvVar(envKey), clientEnvironment.get(envKey));
}

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

env.getListener().post(resolved);
Expand Down
19 changes: 19 additions & 0 deletions src/test/shell/bazel/starlark_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3137,4 +3137,23 @@ EOF
expect_log "I'm running!"
}

function test_unexported_rule() {
# alas, we still need to support this while WORKSPACE is around...
create_new_workspace
touch MODULE.bazel
touch BUILD
cat > r.bzl <<EOF
def _impl(rctx):
rctx.file('BUILD', 'filegroup(name="r")')
def r():
repository_rule(_impl)(name = "r")
EOF
cat > WORKSPACE.bzlmod <<EOF
load('//:r.bzl', 'r')
r()
EOF

bazel build @r >& $TEST_log || fail "expected bazel to succeed"
}

run_suite "local repository tests"
Loading