Search in sources :

Example 21 with CxxPlatform

use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.

the class CxxPlatformXcodeConfigGeneratorTest method testAllBuildConfigurationsHaveSameConfigs.

@Test
public void testAllBuildConfigurationsHaveSameConfigs() {
    final String someCrazyKey = "SOME_CRAZY_KEY";
    LinkedHashMap<String, String> appendConfig = new LinkedHashMap<String, String>();
    appendConfig.put(someCrazyKey, "value");
    CxxPlatform platform = CxxPlatform.builder().from(DEFAULT_PLATFORM).setFlavor(InternalFlavor.of("macosx-12.0")).setCxxflags(ImmutableList.of("-Wno-warning", "-someflag", "-mmacosx-version-min=10.8")).build();
    ImmutableMap<String, ImmutableMap<String, String>> buildConfigs = CxxPlatformXcodeConfigGenerator.getDefaultXcodeBuildConfigurationsFromCxxPlatform(platform, appendConfig);
    ImmutableMap<String, String> debugConfig = buildConfigs.get(CxxPlatformXcodeConfigGenerator.DEBUG_BUILD_CONFIGURATION_NAME);
    ImmutableMap<String, String> releaseConfig = buildConfigs.get(CxxPlatformXcodeConfigGenerator.RELEASE_BUILD_CONFIGURATION_NAME);
    ImmutableMap<String, String> profileConfig = buildConfigs.get(CxxPlatformXcodeConfigGenerator.PROFILE_BUILD_CONFIGURATION_NAME);
    assertThat(debugConfig, Matchers.equalTo(releaseConfig));
    assertThat(releaseConfig, Matchers.equalTo(profileConfig));
}
Also used : CxxPlatform(com.facebook.buck.cxx.CxxPlatform) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 22 with CxxPlatform

use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.

the class DTestDescriptionTest method cxxLinkerInImplicitTimeDeps.

@Test
public void cxxLinkerInImplicitTimeDeps() {
    CxxPlatform cxxPlatform = CxxPlatformUtils.DEFAULT_PLATFORM;
    DTestBuilder builder = new DTestBuilder(BuildTargetFactory.newInstance("//:rule"), new DBuckConfig(FakeBuckConfig.builder().build()), cxxPlatform);
    ImmutableList<BuildTarget> implicitDeps = ImmutableList.copyOf(builder.findImplicitDeps());
    for (BuildTarget target : cxxPlatform.getLd().getParseTimeDeps()) {
        assertThat(implicitDeps, Matchers.hasItem(target));
    }
}
Also used : CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 23 with CxxPlatform

use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.

the class HalideLibraryDescriptionTest method testCreateBuildRule.

@Test
public void testCreateBuildRule() throws Exception {
    // Set up a #halide-compiler rule, then set up a halide_library rule, and
    // check that the library rule depends on the compiler rule.
    BuildTarget compilerTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(HalideLibraryDescription.HALIDE_COMPILER_FLAVOR);
    BuildTarget libTarget = BuildTargetFactory.newInstance("//:rule");
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    HalideLibraryBuilder compilerBuilder = new HalideLibraryBuilder(compilerTarget);
    compilerBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("main.cpp"))));
    HalideLibraryBuilder libBuilder = new HalideLibraryBuilder(libTarget);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(compilerBuilder.build(), libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    HalideLibrary lib = (HalideLibrary) libBuilder.build(resolver, filesystem, targetGraph);
    // Check that the library rule has the correct preprocessor input.
    CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
    String headerName = "rule.h";
    BuildTarget flavoredLibTarget = libTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor());
    Path headerPath = HalideCompile.headerOutputPath(flavoredLibTarget, lib.getProjectFilesystem(), Optional.empty());
    CxxSymlinkTreeHeaders publicHeaders = (CxxSymlinkTreeHeaders) lib.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC).getIncludes().get(0);
    assertThat(publicHeaders.getIncludeType(), Matchers.equalTo(CxxPreprocessables.IncludeType.SYSTEM));
    assertThat(publicHeaders.getNameToPathMap(), Matchers.equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get(headerName), new ExplicitBuildTargetSourcePath(flavoredLibTarget, headerPath))));
    // Check that the library rule has the correct native linkable input.
    NativeLinkableInput input = lib.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC);
    BuildRule buildRule = FluentIterable.from(input.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).get(0);
    assertThat(buildRule, is(instanceOf(Archive.class)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxSymlinkTreeHeaders(com.facebook.buck.cxx.CxxSymlinkTreeHeaders) Linker(com.facebook.buck.cxx.Linker) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) Step(com.facebook.buck.step.Step) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Matchers.not(org.hamcrest.Matchers.not) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Archive(com.facebook.buck.cxx.Archive) SourcePath(com.facebook.buck.rules.SourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) Matchers.hasItems(org.hamcrest.Matchers.hasItems) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) TargetGraph(com.facebook.buck.rules.TargetGraph) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.hasItem(org.hamcrest.Matchers.hasItem) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) CxxSymlinkTreeHeaders(com.facebook.buck.cxx.CxxSymlinkTreeHeaders) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 24 with CxxPlatform

use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.

the class OCamlIntegrationTest method testCppLibraryDependency.

@Test
public void testCppLibraryDependency() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "ocaml", tmp);
    workspace.setUp();
    BuildTarget target = BuildTargetFactory.newInstance(workspace.getDestPath(), "//clib:clib");
    BuildTarget binary = createOcamlLinkTarget(target);
    BuildTarget libplus = BuildTargetFactory.newInstance(workspace.getDestPath(), "//clib:plus");
    BuildTarget libplusStatic = createStaticLibraryBuildTarget(libplus);
    BuildTarget cclib = BuildTargetFactory.newInstance(workspace.getDestPath(), "//clib:cc");
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), cclib, cxxPlatform);
    BuildTarget cclibbin = CxxDescriptionEnhancer.createStaticLibraryBuildTarget(cclib, cxxPlatform.getFlavor(), CxxSourceRuleFactory.PicType.PDC);
    String sourceName = "cc/cc.cpp";
    BuildTarget ccObj = cxxSourceRuleFactory.createCompileBuildTarget(sourceName);
    BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(cclib, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget exportedHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(cclib, HeaderVisibility.PUBLIC, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally(binary.toString());
    buildLog.assertTargetBuiltLocally(libplusStatic.toString());
    buildLog.assertTargetBuiltLocally(cclibbin.toString());
    buildLog.assertTargetBuiltLocally(ccObj.toString());
    buildLog.assertTargetBuiltLocally(headerSymlinkTreeTarget.toString());
    buildLog.assertTargetBuiltLocally(exportedHeaderSymlinkTreeTarget.toString());
    workspace.resetBuildLogFile();
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    buildLog = workspace.getBuildLog();
    buildLog.assertTargetHadMatchingRuleKey(binary.toString());
    buildLog.assertTargetHadMatchingRuleKey(target.toString());
    workspace.resetBuildLogFile();
    workspace.replaceFileContents("clib/cc/cc.cpp", "Hi there", "hi there");
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally(binary.toString());
    buildLog.assertTargetBuiltLocally(libplusStatic.toString());
    buildLog.assertTargetBuiltLocally(cclibbin.toString());
    buildLog.assertTargetBuiltLocally(ccObj.toString());
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) OcamlRuleBuilder.createStaticLibraryBuildTarget(com.facebook.buck.ocaml.OcamlRuleBuilder.createStaticLibraryBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Test(org.junit.Test)

Example 25 with CxxPlatform

use of com.facebook.buck.cxx.CxxPlatform in project buck by facebook.

the class KnownBuildRuleTypesTest method whenRegisteringDescriptionsLastOneWins.

@Test
public void whenRegisteringDescriptionsLastOneWins() throws Exception {
    FlavorDomain<CxxPlatform> cxxPlatforms = FlavorDomain.of("C/C++ platform");
    CxxPlatform defaultPlatform = CxxPlatformUtils.DEFAULT_PLATFORM;
    KnownBuildRuleTypes.Builder buildRuleTypesBuilder = KnownBuildRuleTypes.builder();
    buildRuleTypesBuilder.register(new KnownRuleTestDescription("Foo"));
    buildRuleTypesBuilder.register(new KnownRuleTestDescription("Bar"));
    buildRuleTypesBuilder.register(new KnownRuleTestDescription("Raz"));
    buildRuleTypesBuilder.setCxxPlatforms(cxxPlatforms);
    buildRuleTypesBuilder.setDefaultCxxPlatform(defaultPlatform);
    KnownBuildRuleTypes buildRuleTypes = buildRuleTypesBuilder.build();
    assertEquals("Only one description should have wound up in the final KnownBuildRuleTypes", KnownBuildRuleTypes.builder().setCxxPlatforms(cxxPlatforms).setDefaultCxxPlatform(defaultPlatform).build().getAllDescriptions().size() + 1, buildRuleTypes.getAllDescriptions().size());
    boolean foundTestDescription = false;
    for (Description<?> description : buildRuleTypes.getAllDescriptions()) {
        if (Description.getBuildRuleType(description).equals(Description.getBuildRuleType(KnownRuleTestDescription.class))) {
            assertFalse("Should only find one test description", foundTestDescription);
            foundTestDescription = true;
            assertEquals("Last description should have won", "Raz", ((KnownRuleTestDescription) description).getValue());
        }
    }
}
Also used : CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Test(org.junit.Test)

Aggregations

CxxPlatform (com.facebook.buck.cxx.CxxPlatform)52 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)24 Path (java.nio.file.Path)22 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)20 BuildTarget (com.facebook.buck.model.BuildTarget)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)19 SourcePath (com.facebook.buck.rules.SourcePath)17 BuildRule (com.facebook.buck.rules.BuildRule)14 ImmutableList (com.google.common.collect.ImmutableList)11 HumanReadableException (com.facebook.buck.util.HumanReadableException)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 FakeExecutableFinder (com.facebook.buck.io.FakeExecutableFinder)8 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)8 Optional (java.util.Optional)8 Flavor (com.facebook.buck.model.Flavor)7 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)7 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)6 Linker (com.facebook.buck.cxx.Linker)6