diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD index 7e676ffaf9c89f..ae85e8bd2925e4 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD @@ -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", diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/StarlarkExecTransitionLoader.java b/src/main/java/com/google/devtools/build/lib/analysis/config/StarlarkExecTransitionLoader.java index dc17be178c60db..730d3335732d83 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/StarlarkExecTransitionLoader.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/StarlarkExecTransitionLoader.java @@ -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; @@ -67,15 +68,15 @@ public interface BzlFileLoader { public static Optional 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 = @@ -85,8 +86,7 @@ public static Optional 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; @@ -94,14 +94,12 @@ public static Optional loadStarlarkExecTran 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));