Search in sources :

Example 21 with Flavor

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);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) TreeMap(java.util.TreeMap) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 22 with Flavor

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));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) Test(org.junit.Test)

Example 23 with Flavor

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));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) Test(org.junit.Test)

Example 24 with Flavor

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));
        }
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) NSString(com.dd.plist.NSString) Matchers.containsString(org.hamcrest.Matchers.containsString) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) Test(org.junit.Test)

Example 25 with Flavor

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();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Flavor (com.facebook.buck.model.Flavor)60 InternalFlavor (com.facebook.buck.model.InternalFlavor)42 BuildTarget (com.facebook.buck.model.BuildTarget)33 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)17 Test (org.junit.Test)17 SourcePath (com.facebook.buck.rules.SourcePath)14 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 ImmutableMap (com.google.common.collect.ImmutableMap)14 BuildRule (com.facebook.buck.rules.BuildRule)13 ImmutableSet (com.google.common.collect.ImmutableSet)13 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 HumanReadableException (com.facebook.buck.util.HumanReadableException)12 Path (java.nio.file.Path)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)11 Optional (java.util.Optional)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)9 Map (java.util.Map)9 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)7 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)6