use of com.facebook.buck.model.Flavor in project buck by facebook.
the class VersionedTargetGraphBuilder method getTranslateBuildTarget.
/**
* @return the {@link BuildTarget} to use in the resolved target graph, formed by adding a
* flavor generated from the given version selections.
*/
private Optional<BuildTarget> getTranslateBuildTarget(TargetNode<?, ?> node, ImmutableMap<BuildTarget, Version> selectedVersions) {
BuildTarget originalTarget = node.getBuildTarget();
node = resolveVersions(node, selectedVersions);
BuildTarget newTarget = node.getBuildTarget();
if (TargetGraphVersionTransformations.isVersionPropagator(node)) {
VersionInfo info = getVersionInfo(node);
Collection<BuildTarget> versionedDeps = info.getVersionDomain().keySet();
TreeMap<BuildTarget, Version> versions = new TreeMap<>();
for (BuildTarget depTarget : versionedDeps) {
versions.put(depTarget, selectedVersions.get(depTarget));
}
if (!versions.isEmpty()) {
Flavor versionedFlavor = getVersionedFlavor(versions);
newTarget = node.getBuildTarget().withAppendedFlavors(versionedFlavor);
}
}
return newTarget.equals(originalTarget) ? Optional.empty() : Optional.of(newTarget);
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class AppleBinaryIntegrationTest method testBuildingWithNoDebugDoesNotProduceAllCompileRulesOnDisk.
@Test
public void testBuildingWithNoDebugDoesNotProduceAllCompileRulesOnDisk() throws Exception {
assumeTrue(Platform.detect() == Platform.MACOS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_application_bundle_dwarf_and_dsym", tmp);
workspace.setUp();
workspace.enableDirCache();
Flavor platformFlavor = InternalFlavor.of("iphonesimulator-x86_64");
BuildTarget target = BuildTargetFactory.newInstance("//:DemoApp").withAppendedFlavors(AppleDebugFormat.NONE.getFlavor());
BuildTarget binaryTarget = BuildTargetFactory.newInstance("//:DemoAppBinary").withAppendedFlavors(platformFlavor, AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR);
workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();
workspace.runBuckCommand("clean").assertSuccess();
workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();
BuildTarget appTarget = target.withFlavors(AppleDebugFormat.NONE.getFlavor(), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR);
Path binaryOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, appTarget, "%s").resolve(target.getShortName() + ".app").resolve(target.getShortName()));
Path delegateFileOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, binaryTarget.withFlavors(platformFlavor, InternalFlavor.of("compile-" + sanitize("AppDelegate.m.o")), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR), "%s").resolve("AppDelegate.m.o"));
Path mainFileOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, binaryTarget.withFlavors(platformFlavor, InternalFlavor.of("compile-" + sanitize("main.m.o")), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR), "%s").resolve("main.m.o"));
assertThat(Files.exists(binaryOutput), equalTo(true));
assertThat(Files.exists(delegateFileOutput), equalTo(false));
assertThat(Files.exists(mainFileOutput), equalTo(false));
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class AppleBinaryIntegrationTest method testBuildingWithDwarfAndDsymDoesNotProduceAllCompileRulesOnDisk.
@Test
public void testBuildingWithDwarfAndDsymDoesNotProduceAllCompileRulesOnDisk() throws Exception {
assumeTrue(Platform.detect() == Platform.MACOS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_application_bundle_dwarf_and_dsym", tmp);
workspace.setUp();
workspace.enableDirCache();
Flavor platformFlavor = InternalFlavor.of("iphonesimulator-x86_64");
BuildTarget target = BuildTargetFactory.newInstance("//:DemoApp").withAppendedFlavors(AppleDebugFormat.DWARF_AND_DSYM.getFlavor());
BuildTarget binaryTarget = BuildTargetFactory.newInstance("//:DemoAppBinary").withAppendedFlavors(platformFlavor, AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR);
workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();
workspace.runBuckCommand("clean").assertSuccess();
workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();
BuildTarget appTarget = target.withFlavors(AppleDebugFormat.DWARF_AND_DSYM.getFlavor(), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR);
Path binaryOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, appTarget, "%s").resolve(target.getShortName() + ".app").resolve(target.getShortName()));
Path delegateFileOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, binaryTarget.withFlavors(platformFlavor, InternalFlavor.of("compile-" + sanitize("AppDelegate.m.o")), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR), "%s").resolve("AppDelegate.m.o"));
Path mainFileOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, binaryTarget.withFlavors(platformFlavor, InternalFlavor.of("compile-" + sanitize("main.m.o")), AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR), "%s").resolve("main.m.o"));
assertThat(Files.exists(binaryOutput), equalTo(true));
assertThat(Files.exists(delegateFileOutput), equalTo(false));
assertThat(Files.exists(mainFileOutput), equalTo(false));
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class AppleBundleIntegrationTest method appleBundleDoesNotPropagateIncludeFrameworkFlavors.
@Test
public void appleBundleDoesNotPropagateIncludeFrameworkFlavors() throws Exception {
assumeTrue(Platform.detect() == Platform.MACOS);
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_app_with_extension", tmp);
workspace.setUp();
BuildTarget target = BuildTargetFactory.newInstance("//:DemoAppWithExtension#no-debug");
ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", "--show-output", target.getFullyQualifiedName());
result.assertSuccess();
BuckBuildLog buckBuildLog = workspace.getBuildLog();
ImmutableSet<String> targetsThatShouldContainIncludeFrameworkFlavors = ImmutableSet.of("//:DemoAppWithExtension", "//:DemoExtension");
ImmutableSet<Flavor> includeFrameworkFlavors = ImmutableSet.of(InternalFlavor.of("no-include-frameworks"), InternalFlavor.of("include-frameworks"));
for (BuildTarget builtTarget : buckBuildLog.getAllTargets()) {
if (Sets.intersection(builtTarget.getFlavors(), includeFrameworkFlavors).isEmpty()) {
assertThat(builtTarget.getUnflavoredBuildTarget().getFullyQualifiedName(), not(in(targetsThatShouldContainIncludeFrameworkFlavors)));
} else {
assertThat(builtTarget.getUnflavoredBuildTarget().getFullyQualifiedName(), in(targetsThatShouldContainIncludeFrameworkFlavors));
}
}
}
use of com.facebook.buck.model.Flavor in project buck by facebook.
the class AppleCxxPlatformsTest method constructCompileRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
String source = "source.cpp";
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("source.cpp", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(CxxPlatformUtils.DEFAULT_CONFIG).setCxxPlatform(entry.getValue().getCxxPlatform()).setPicType(CxxSourceRuleFactory.PicType.PIC).build();
CxxPreprocessAndCompile rule;
switch(operation) {
case PREPROCESS_AND_COMPILE:
rule = cxxSourceRuleFactory.createPreprocessAndCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX, new FakeSourcePath(source), ImmutableList.of()));
break;
case COMPILE:
rule = cxxSourceRuleFactory.createCompileBuildRule(source, CxxSource.of(CxxSource.Type.CXX_CPP_OUTPUT, new FakeSourcePath(source), ImmutableList.of()));
break;
default:
throw new IllegalStateException();
}
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
Aggregations