Skip to content

Commit

Permalink
Consolidate referneces to --experimental_exec_config.
Browse files Browse the repository at this point in the history
Also more strongly verify that the Starlark exec transition is set for this build.

I thought about removing the generic `context` variable in `StarlarkExecTransitionLoadingException`'s
constructor. All uses today fill that out with `--experiemntal_exec_config`. But it seems nice to
keep that open in case we generalize uses with a wider API.

PiperOrigin-RevId: 588074546
Change-Id: I14f169e2e44d482c9acb34968a97dbb008149299
  • Loading branch information
gregestren authored and copybara-github committed Dec 5, 2023
1 parent aa70121 commit c572286
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@ java_library(
deps = [
":analysis_cluster",
":config/build_options",
":config/common_options",
":config/core_options",
":config/starlark_defined_config_transition",
"//src/main/java/com/google/devtools/build/lib/cmdline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Splitter;
import com.google.common.base.Verify;
import com.google.devtools.build.lib.analysis.starlark.StarlarkAttributeTransitionProvider;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
Expand Down Expand Up @@ -67,15 +68,15 @@ public interface BzlFileLoader {
public static Optional<StarlarkAttributeTransitionProvider> loadStarlarkExecTransition(
@Nullable BuildOptions options, BzlFileLoader bzlFileLoader)
throws StarlarkExecTransitionLoadingException, InterruptedException {
if (options == null) {
if (options == null || options.equals(CommonOptions.EMPTY_OPTIONS)) {
return Optional.empty();
}
String userRef = options.get(CoreOptions.class).starlarkExecConfig;
if (userRef == null) {
return Optional.empty(); // Use the native exec transition.
}
TransitionReference parsedRef =
TransitionReference.create(userRef, "--experimental_exec_config");
String userRef =
Verify.verifyNotNull(
options.get(CoreOptions.class).starlarkExecConfig,
"Cannot apply the exec transition since no transition is defined for this build.");
final String flagName = "--experimental_exec_config";
TransitionReference parsedRef = TransitionReference.create(userRef, flagName);
BzlLoadValue bzlValue;
try {
bzlValue =
Expand All @@ -85,23 +86,20 @@ public static Optional<StarlarkAttributeTransitionProvider> loadStarlarkExecTran
? BzlLoadValue.keyForBuiltins(parsedRef.bzlFile())
: BzlLoadValue.keyForBuild(parsedRef.bzlFile()));
} catch (BzlLoadFailedException e) {
throw new StarlarkExecTransitionLoadingException(
"--experimental_exec_config", userRef, e.getMessage());
throw new StarlarkExecTransitionLoadingException(flagName, userRef, e.getMessage());
}
if (bzlValue == null) {
return null;
}
Object transition = bzlValue.getModule().getGlobal(parsedRef.starlarkSymbolName());
if (transition == null) {
throw new StarlarkExecTransitionLoadingException(
"--experimental_exec_config",
flagName,
userRef,
String.format("%s not found in %s", parsedRef.starlarkSymbolName(), parsedRef.bzlFile()));
} else if (!(transition instanceof StarlarkDefinedConfigTransition)) {
throw new StarlarkExecTransitionLoadingException(
"--experimental_exec_config",
userRef,
parsedRef.starlarkSymbolName() + " is not a Starlark transition");
flagName, userRef, parsedRef.starlarkSymbolName() + " is not a Starlark transition");
}
return Optional.of(
new StarlarkAttributeTransitionProvider((StarlarkDefinedConfigTransition) transition));
Expand Down

0 comments on commit c572286

Please sign in to comment.