From 2ab6e9a6212a16a8d31e9e1b3f333f57ee1110d6 Mon Sep 17 00:00:00 2001 From: Sergey Tyurin Date: Tue, 30 Apr 2019 15:15:28 -0700 Subject: [PATCH] Use UnconfiguredBuildTargetView in ProviderBasedUnresolvedCxxPlatform instead of BuildTarget Summary: Changes `ProviderBasedUnresolvedCxxPlatform` to apply the target configuration passed in `resolve`. This removes the need to pass `TargetConfiguration` in `CxxPlatformsProviderFactory`. Reviewed By: sbalabanov fbshipit-source-id: 316dc07ec2 --- .../buck/cxx/toolchain/CxxBuckConfig.java | 6 +++--- .../toolchain/CxxPlatformsProviderFactory.java | 16 ++++------------ .../ProviderBasedUnresolvedCxxPlatform.java | 14 ++++++++------ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/com/facebook/buck/cxx/toolchain/CxxBuckConfig.java b/src/com/facebook/buck/cxx/toolchain/CxxBuckConfig.java index 65c2c4e412b..4ee48997a71 100644 --- a/src/com/facebook/buck/cxx/toolchain/CxxBuckConfig.java +++ b/src/com/facebook/buck/cxx/toolchain/CxxBuckConfig.java @@ -628,11 +628,11 @@ public BuckConfig getDelegate() { * backed by the specified target. */ public static Optional getProviderBasedPlatform( - BuckConfig config, Flavor flavor, TargetConfiguration targetConfiguration) { + BuckConfig config, Flavor flavor) { String cxxSection = new CxxBuckConfig(config, flavor).cxxSection; - Optional toolchainTarget = - config.getBuildTarget(cxxSection, TOOLCHAIN_TARGET, targetConfiguration); + Optional toolchainTarget = + config.getMaybeUnconfiguredBuildTarget(cxxSection, TOOLCHAIN_TARGET); if (!toolchainTarget.isPresent()) { return Optional.empty(); } diff --git a/src/com/facebook/buck/cxx/toolchain/CxxPlatformsProviderFactory.java b/src/com/facebook/buck/cxx/toolchain/CxxPlatformsProviderFactory.java index b540c49f5c1..c73effaf74d 100644 --- a/src/com/facebook/buck/cxx/toolchain/CxxPlatformsProviderFactory.java +++ b/src/com/facebook/buck/cxx/toolchain/CxxPlatformsProviderFactory.java @@ -21,7 +21,6 @@ import com.facebook.buck.core.model.Flavor; import com.facebook.buck.core.model.FlavorDomain; import com.facebook.buck.core.model.InternalFlavor; -import com.facebook.buck.core.model.TargetConfiguration; import com.facebook.buck.core.toolchain.ToolchainCreationContext; import com.facebook.buck.core.toolchain.ToolchainFactory; import com.facebook.buck.core.toolchain.ToolchainInstantiationException; @@ -55,20 +54,14 @@ public Optional createToolchain( } try { - return Optional.of( - createProvider( - context.getBuckConfig(), - context.getTargetConfiguration().get(), - cxxSystemPlatforms.build())); + return Optional.of(createProvider(context.getBuckConfig(), cxxSystemPlatforms.build())); } catch (HumanReadableException e) { throw ToolchainInstantiationException.wrap(e); } } private static CxxPlatformsProvider createProvider( - BuckConfig config, - TargetConfiguration targetConfiguration, - ImmutableMap cxxSystemPlatforms) { + BuckConfig config, ImmutableMap cxxSystemPlatforms) { Platform platform = Platform.detect(); CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(config); @@ -90,7 +83,7 @@ private static CxxPlatformsProvider createProvider( Map cxxOverridePlatformsMap = updateCxxPlatformsWithOptionsFromBuckConfig( - targetConfiguration, platform, config, cxxSystemPlatformsMap, defaultHostCxxPlatform); + platform, config, cxxSystemPlatformsMap, defaultHostCxxPlatform); UnresolvedCxxPlatform hostCxxPlatform = getHostCxxPlatform(cxxBuckConfig, cxxOverridePlatformsMap); @@ -134,7 +127,6 @@ private static ImmutableMap appendHostPlatformIfN * cxx#{flavor name}. These platforms are overrides for existing system platforms. */ private static Map updateCxxPlatformsWithOptionsFromBuckConfig( - TargetConfiguration targetConfiguration, Platform platform, BuckConfig config, ImmutableMap cxxSystemPlatformsMap, @@ -145,7 +137,7 @@ private static Map updateCxxPlatformsWithOptionsF ImmutableSet cxxFlavors = CxxBuckConfig.getCxxFlavors(config); for (Flavor flavor : cxxFlavors) { Optional newPlatform = - CxxBuckConfig.getProviderBasedPlatform(config, flavor, targetConfiguration); + CxxBuckConfig.getProviderBasedPlatform(config, flavor); if (!newPlatform.isPresent()) { newPlatform = diff --git a/src/com/facebook/buck/cxx/toolchain/ProviderBasedUnresolvedCxxPlatform.java b/src/com/facebook/buck/cxx/toolchain/ProviderBasedUnresolvedCxxPlatform.java index 518ea17ef4a..07a9efd8e75 100644 --- a/src/com/facebook/buck/cxx/toolchain/ProviderBasedUnresolvedCxxPlatform.java +++ b/src/com/facebook/buck/cxx/toolchain/ProviderBasedUnresolvedCxxPlatform.java @@ -18,6 +18,7 @@ import com.facebook.buck.core.model.BuildTarget; import com.facebook.buck.core.model.Flavor; import com.facebook.buck.core.model.TargetConfiguration; +import com.facebook.buck.core.model.UnconfiguredBuildTargetView; import com.facebook.buck.core.rules.BuildRule; import com.facebook.buck.core.rules.BuildRuleResolver; import com.google.common.base.Verify; @@ -25,17 +26,18 @@ /** Used to provide a {@link CxxPlatform} that is specified as a cxx_toolchain build target. */ public class ProviderBasedUnresolvedCxxPlatform implements UnresolvedCxxPlatform { - private final BuildTarget buildTarget; + private final UnconfiguredBuildTargetView unconfiguredBuildTarget; private final Flavor flavor; - public ProviderBasedUnresolvedCxxPlatform(BuildTarget buildTarget, Flavor flavor) { - this.buildTarget = buildTarget; + public ProviderBasedUnresolvedCxxPlatform( + UnconfiguredBuildTargetView unconfiguredBuildTarget, Flavor flavor) { + this.unconfiguredBuildTarget = unconfiguredBuildTarget; this.flavor = flavor; } @Override public CxxPlatform resolve(BuildRuleResolver resolver, TargetConfiguration targetConfiguration) { - BuildRule rule = resolver.getRule(buildTarget); + BuildRule rule = resolver.getRule(unconfiguredBuildTarget.configure(targetConfiguration)); Verify.verify( rule instanceof ProvidesCxxPlatform, "%s isn't a cxx_platform rule", rule.getBuildTarget()); return ((ProvidesCxxPlatform) rule).getPlatformWithFlavor(flavor); @@ -53,12 +55,12 @@ public UnresolvedCxxPlatform withFlavor(Flavor hostFlavor) { @Override public Iterable getParseTimeDeps(TargetConfiguration targetConfiguration) { - return ImmutableList.of(buildTarget); + return ImmutableList.of(unconfiguredBuildTarget.configure(targetConfiguration)); } @Override public Iterable getLinkerParseTimeDeps( TargetConfiguration targetConfiguration) { - return ImmutableList.of(buildTarget); + return ImmutableList.of(unconfiguredBuildTarget.configure(targetConfiguration)); } }