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));
}
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));
}
}
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)));
}
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());
}
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());
}
}
}
Aggregations