Skip to content

Commit

Permalink
Use UnconfiguredBuildTargetView in ProviderBasedUnresolvedCxxPlatform…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Sergey Tyurin authored and facebook-github-bot committed Apr 30, 2019
1 parent 2852cec commit 2ab6e9a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/com/facebook/buck/cxx/toolchain/CxxBuckConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,11 @@ public BuckConfig getDelegate() {
* backed by the specified target.
*/
public static Optional<UnresolvedCxxPlatform> getProviderBasedPlatform(
BuckConfig config, Flavor flavor, TargetConfiguration targetConfiguration) {
BuckConfig config, Flavor flavor) {
String cxxSection = new CxxBuckConfig(config, flavor).cxxSection;

Optional<BuildTarget> toolchainTarget =
config.getBuildTarget(cxxSection, TOOLCHAIN_TARGET, targetConfiguration);
Optional<UnconfiguredBuildTargetView> toolchainTarget =
config.getMaybeUnconfiguredBuildTarget(cxxSection, TOOLCHAIN_TARGET);
if (!toolchainTarget.isPresent()) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,20 +54,14 @@ public Optional<CxxPlatformsProvider> 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<Flavor, UnresolvedCxxPlatform> cxxSystemPlatforms) {
BuckConfig config, ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxSystemPlatforms) {
Platform platform = Platform.detect();
CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(config);

Expand All @@ -90,7 +83,7 @@ private static CxxPlatformsProvider createProvider(

Map<Flavor, UnresolvedCxxPlatform> cxxOverridePlatformsMap =
updateCxxPlatformsWithOptionsFromBuckConfig(
targetConfiguration, platform, config, cxxSystemPlatformsMap, defaultHostCxxPlatform);
platform, config, cxxSystemPlatformsMap, defaultHostCxxPlatform);

UnresolvedCxxPlatform hostCxxPlatform =
getHostCxxPlatform(cxxBuckConfig, cxxOverridePlatformsMap);
Expand Down Expand Up @@ -134,7 +127,6 @@ private static ImmutableMap<Flavor, UnresolvedCxxPlatform> appendHostPlatformIfN
* cxx#{flavor name}. These platforms are overrides for existing system platforms.
*/
private static Map<Flavor, UnresolvedCxxPlatform> updateCxxPlatformsWithOptionsFromBuckConfig(
TargetConfiguration targetConfiguration,
Platform platform,
BuckConfig config,
ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxSystemPlatformsMap,
Expand All @@ -145,7 +137,7 @@ private static Map<Flavor, UnresolvedCxxPlatform> updateCxxPlatformsWithOptionsF
ImmutableSet<Flavor> cxxFlavors = CxxBuckConfig.getCxxFlavors(config);
for (Flavor flavor : cxxFlavors) {
Optional<UnresolvedCxxPlatform> newPlatform =
CxxBuckConfig.getProviderBasedPlatform(config, flavor, targetConfiguration);
CxxBuckConfig.getProviderBasedPlatform(config, flavor);

if (!newPlatform.isPresent()) {
newPlatform =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@
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;
import com.google.common.collect.ImmutableList;

/** 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);
Expand All @@ -53,12 +55,12 @@ public UnresolvedCxxPlatform withFlavor(Flavor hostFlavor) {

@Override
public Iterable<BuildTarget> getParseTimeDeps(TargetConfiguration targetConfiguration) {
return ImmutableList.of(buildTarget);
return ImmutableList.of(unconfiguredBuildTarget.configure(targetConfiguration));
}

@Override
public Iterable<? extends BuildTarget> getLinkerParseTimeDeps(
TargetConfiguration targetConfiguration) {
return ImmutableList.of(buildTarget);
return ImmutableList.of(unconfiguredBuildTarget.configure(targetConfiguration));
}
}

0 comments on commit 2ab6e9a

Please sign in to comment.