diff options
author | John Cater <jcater@google.com> | 2018-03-12 18:50:56 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-12 18:53:23 -0700 |
commit | 0084e16b55ad54f7aeeffd6d003ea3506039d957 (patch) | |
tree | 306210efed020fe8a7fd8645e383d8fe4e3b2947 /src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java | |
parent | cf37b4f3e44564a154ea0535efa61c6c673bab52 (diff) |
Fix toolchain and execution platform registration to use patterns.
This allows more flexibility in registering toolchains and execution
platforms, both in the WORKSPACE and from the command-line.
Change-Id: I6fe75507d1a74de74085b7c927fdf093c152b894
PiperOrigin-RevId: 188813688
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java index d6a8bfe1dd..5d3b580853 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java @@ -14,6 +14,8 @@ package com.google.devtools.build.lib.skyframe; +import static com.google.common.collect.ImmutableList.toImmutableList; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -21,7 +23,9 @@ import com.google.devtools.build.lib.analysis.PlatformConfiguration; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.cmdline.TargetParsingException; import com.google.devtools.build.lib.packages.Package; +import com.google.devtools.build.lib.pkgcache.FilteringPolicies; import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredValueCreationException; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; @@ -51,22 +55,36 @@ public class RegisteredToolchainsFunction implements SkyFunction { } BuildConfiguration configuration = buildConfigurationValue.getConfiguration(); - ImmutableList.Builder<Label> registeredToolchainLabels = new ImmutableList.Builder<>(); + ImmutableList.Builder<String> targetPatterns = new ImmutableList.Builder<>(); // Get the toolchains from the configuration. PlatformConfiguration platformConfiguration = configuration.getFragment(PlatformConfiguration.class); - registeredToolchainLabels.addAll(platformConfiguration.getExtraToolchains()); + targetPatterns.addAll(platformConfiguration.getExtraToolchains()); // Get the registered toolchains from the WORKSPACE. - registeredToolchainLabels.addAll(getWorkspaceToolchains(env)); + targetPatterns.addAll(getWorkspaceToolchains(env)); if (env.valuesMissing()) { return null; } + // Expand target patterns. + ImmutableList<Label> toolchainLabels; + try { + toolchainLabels = + ToolchainUtil.expandTargetPatterns( + env, targetPatterns.build(), FilteringPolicies.ruleType("toolchain", true)); + if (env.valuesMissing()) { + return null; + } + } catch (ToolchainUtil.InvalidTargetPatternException e) { + throw new RegisteredToolchainsFunctionException( + new InvalidToolchainLabelException(e), Transience.PERSISTENT); + } + // Load the configured target for each, and get the declared toolchain providers. ImmutableList<DeclaredToolchainInfo> registeredToolchains = - configureRegisteredToolchains(env, configuration, registeredToolchainLabels.build()); + configureRegisteredToolchains(env, configuration, toolchainLabels); if (env.valuesMissing()) { return null; } @@ -74,23 +92,23 @@ public class RegisteredToolchainsFunction implements SkyFunction { return RegisteredToolchainsValue.create(registeredToolchains); } - private Iterable<? extends Label> getWorkspaceToolchains(Environment env) + private Iterable<? extends String> getWorkspaceToolchains(Environment env) throws InterruptedException { - List<Label> labels = getRegisteredToolchainLabels(env); - if (labels == null) { + List<String> patterns = getRegisteredToolchains(env); + if (patterns == null) { return ImmutableList.of(); } - return labels; + return patterns; } /** - * Loads the external package and then returns the registered toolchain labels. + * Loads the external package and then returns the registered toolchains. * * @param env the environment to use for lookups */ - @Nullable @VisibleForTesting - public static List<Label> getRegisteredToolchainLabels(Environment env) - throws InterruptedException { + @Nullable + @VisibleForTesting + public static List<String> getRegisteredToolchains(Environment env) throws InterruptedException { PackageValue externalPackageValue = (PackageValue) env.getValue(PackageValue.key(Label.EXTERNAL_PACKAGE_IDENTIFIER)); if (externalPackageValue == null) { @@ -98,7 +116,7 @@ public class RegisteredToolchainsFunction implements SkyFunction { } Package externalPackage = externalPackageValue.getPackage(); - return externalPackage.getRegisteredToolchainLabels(); + return externalPackage.getRegisteredToolchains(); } private ImmutableList<DeclaredToolchainInfo> configureRegisteredToolchains( @@ -108,7 +126,7 @@ public class RegisteredToolchainsFunction implements SkyFunction { labels .stream() .map(label -> ConfiguredTargetKey.of(label, configuration)) - .collect(ImmutableList.toImmutableList()); + .collect(toImmutableList()); Map<SkyKey, ValueOrException<ConfiguredValueCreationException>> values = env.getValuesOrThrow(keys, ConfiguredValueCreationException.class); @@ -156,25 +174,27 @@ public class RegisteredToolchainsFunction implements SkyFunction { */ public static final class InvalidToolchainLabelException extends Exception { - private final Label invalidLabel; - public InvalidToolchainLabelException(Label invalidLabel) { super( String.format( "invalid registered toolchain '%s': " + "target does not provide the DeclaredToolchainInfo provider", invalidLabel)); - this.invalidLabel = invalidLabel; } - public InvalidToolchainLabelException(Label invalidLabel, ConfiguredValueCreationException e) { + public InvalidToolchainLabelException(ToolchainUtil.InvalidTargetPatternException e) { + this(e.getInvalidPattern(), e.getTpe()); + } + + public InvalidToolchainLabelException(String invalidPattern, TargetParsingException e) { super( - String.format("invalid registered toolchain '%s': %s", invalidLabel, e.getMessage()), e); - this.invalidLabel = invalidLabel; + String.format("invalid registered toolchain '%s': %s", invalidPattern, e.getMessage()), + e); } - public Label getInvalidLabel() { - return invalidLabel; + public InvalidToolchainLabelException(Label invalidLabel, ConfiguredValueCreationException e) { + super( + String.format("invalid registered toolchain '%s': %s", invalidLabel, e.getMessage()), e); } } |