diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java index 2376e89542eff5..729e3bedda8561 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java @@ -147,6 +147,9 @@ public static boolean platformIsDefault(Label platform) { OptionEffectTag.CHANGES_INPUTS, OptionEffectTag.LOADING_AND_ANALYSIS }, + metadataTags = { + OptionMetadataTag.IMMUTABLE, + }, help = "The location of a mapping file that describes which platform to use if none is set or " + "which flags to set when a platform already exists. Must be relative to the main " diff --git a/src/main/java/com/google/devtools/build/lib/analysis/producers/BuildConfigurationKeyProducer.java b/src/main/java/com/google/devtools/build/lib/analysis/producers/BuildConfigurationKeyProducer.java index 95108986bb58fd..4614d6187f9202 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/producers/BuildConfigurationKeyProducer.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/producers/BuildConfigurationKeyProducer.java @@ -71,6 +71,8 @@ public StateMachine step(Tasks tasks) { Collection transitionKeys = entry.getValue(); tasks.lookUp( PlatformMappingValue.Key.create(entry.getKey().orElse(null)), + // No need to consider error handling: this flag cannot be changed and so errors were + // detected and handled in SkyframeExecutor.createBuildConfigurationKey. rawValue -> { var value = (PlatformMappingValue) rawValue; // Maps the value from all transition keys with the same platform mappings path. diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index 3d91f010e44733..d9ddfce4b87b4c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -1852,6 +1852,7 @@ private BuildConfigurationKey createBuildConfigurationKey( PlatformMappingValue.Key.create(platformMappingPath); EvaluationResult evaluationResult = evaluateSkyKeys(eventHandler, ImmutableSet.of(platformMappingKey)); + // Handle all possible errors with the platform mapping by reporting them to the user. if (evaluationResult.hasError()) { throw new InvalidConfigurationException( Code.PLATFORM_MAPPING_EVALUATION_FAILURE, evaluationResult.getError().getException()); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingFunction.java index d98108ac846803..43798f1441d3bc 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/config/PlatformMappingFunction.java @@ -115,15 +115,14 @@ public PlatformMappingValue compute(SkyKey skyKey, Environment env) + " '%s' but that path refers to a directory, not a file", workspaceRelativeMappingPath, root), Code.PLATFORM_MAPPINGS_FILE_IS_DIRECTORY), - Location.BUILTIN), - SkyFunctionException.Transience.PERSISTENT); + Location.BUILTIN)); } List lines; try { lines = FileSystemUtils.readLines(fileValue.realRootedPath().asPath(), UTF_8); } catch (IOException e) { - throw new PlatformMappingException(e, SkyFunctionException.Transience.TRANSIENT); + throw new PlatformMappingException(e); } Mappings parsed = parse(env, lines, mainRepoContext); @@ -147,8 +146,7 @@ public PlatformMappingValue compute(SkyKey skyKey, Environment env) + "package path roots, '%s'", workspaceRelativeMappingPath, pathEntries), Code.PLATFORM_MAPPINGS_FILE_NOT_FOUND), - Location.BUILTIN), - SkyFunctionException.Transience.PERSISTENT); + Location.BUILTIN)); } private static FailureDetail createFailureDetail(String message, Code detailedCode) { @@ -161,8 +159,20 @@ private static FailureDetail createFailureDetail(String message, Code detailedCo @VisibleForTesting static final class PlatformMappingException extends SkyFunctionException { - PlatformMappingException(Exception cause, Transience transience) { - super(cause, transience); + PlatformMappingException(OptionsParsingException cause) { + super(cause, Transience.PERSISTENT); + } + + PlatformMappingException(MissingInputFileException cause) { + super(cause, Transience.PERSISTENT); + } + + PlatformMappingException(IOException cause) { + super(cause, Transience.TRANSIENT); + } + + PlatformMappingException(PlatformMappingParsingException cause) { + super(cause, Transience.PERSISTENT); } } @@ -280,7 +290,7 @@ private static NativeAndStarlarkFlags parseStarlarkFlags( return NativeAndStarlarkFlags.create( nativeFlags.build(), fakeNativeParser.getStarlarkOptions()); } catch (OptionsParsingException e) { - throw new PlatformMappingException(e, Transience.PERSISTENT); + throw new PlatformMappingException(e); } } @@ -368,9 +378,7 @@ private static PlatformMappingException parsingException(String message) { } private static PlatformMappingException parsingException(String message, Exception cause) { - return new PlatformMappingException( - new PlatformMappingParsingException(message, cause), - SkyFunctionException.Transience.PERSISTENT); + return new PlatformMappingException(new PlatformMappingParsingException(message, cause)); } /**