Search in sources :

Example 1 with CxxSourceRuleFactory

use of com.facebook.buck.cxx.CxxSourceRuleFactory 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)

Example 2 with CxxSourceRuleFactory

use of com.facebook.buck.cxx.CxxSourceRuleFactory 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 3 with CxxSourceRuleFactory

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

the class NdkCxxPlatformTest method constructCompileRuleKeys.

// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<NdkCxxPlatforms.TargetCpuType, RuleKey> constructCompileRuleKeys(Operation operation, ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> 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<NdkCxxPlatforms.TargetCpuType, RuleKey> ruleKeys = ImmutableMap.builder();
    for (Map.Entry<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> 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) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) 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

CxxSourceRuleFactory (com.facebook.buck.cxx.CxxSourceRuleFactory)3 BuildTarget (com.facebook.buck.model.BuildTarget)3 CxxPreprocessAndCompile (com.facebook.buck.cxx.CxxPreprocessAndCompile)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 RuleKey (com.facebook.buck.rules.RuleKey)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 Flavor (com.facebook.buck.model.Flavor)1 InternalFlavor (com.facebook.buck.model.InternalFlavor)1 OcamlRuleBuilder.createStaticLibraryBuildTarget (com.facebook.buck.ocaml.OcamlRuleBuilder.createStaticLibraryBuildTarget)1 BuckBuildLog (com.facebook.buck.testutil.integration.BuckBuildLog)1 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)1