Search in sources :

Example 1 with CxxBinaryBuilder

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

the class PythonTestDescriptionTest method runtimeDepOnDeps.

@Test
public void runtimeDepOnDeps() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) {
        CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
        PythonLibraryBuilder pythonLibraryBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
        PythonTestBuilder pythonTestBuilder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:test")).setDeps(ImmutableSortedSet.of(pythonLibraryBuilder.getTarget())).setPackageStyle(packageStyle);
        TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxBinaryBuilder.build(), pythonLibraryBuilder.build(), pythonTestBuilder.build());
        BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        BuildRule cxxBinary = cxxBinaryBuilder.build(resolver, filesystem, targetGraph);
        pythonLibraryBuilder.build(resolver, filesystem, targetGraph);
        PythonTest pythonTest = pythonTestBuilder.build(resolver, filesystem, targetGraph);
        assertThat(String.format("Transitive runtime deps of %s [%s]", pythonTest, packageStyle.toString()), BuildRules.getTransitiveRuntimeDeps(pythonTest, resolver), Matchers.hasItem(cxxBinary.getBuildTarget()));
    }
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 2 with CxxBinaryBuilder

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

the class PythonTestDescriptionTest method nonBuildDepsDoNotAffectRuleKey.

@Test
public void nonBuildDepsDoNotAffectRuleKey() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) {
        // First, calculate the rule key of a python binary with no deps.
        PythonTestBuilder pythonTestBuilder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:bin")).setPackageStyle(packageStyle);
        TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonTestBuilder.build());
        BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        PythonTest pythonTestWithoutDep = pythonTestBuilder.build(resolver, filesystem, targetGraph);
        RuleKey ruleKeyWithoutDep = calculateRuleKey(resolver, pythonTestWithoutDep);
        // Next, calculate the rule key of a python binary with a deps on another binary.
        CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
        pythonTestBuilder.setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
        targetGraph = TargetGraphFactory.newInstance(cxxBinaryBuilder.build(), pythonTestBuilder.build());
        resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        cxxBinaryBuilder.build(resolver, filesystem, targetGraph);
        PythonTest pythonBinaryWithDep = pythonTestBuilder.build(resolver, filesystem, targetGraph);
        RuleKey ruleKeyWithDep = calculateRuleKey(resolver, pythonBinaryWithDep);
        // Verify that the rule keys are identical.
        assertThat(ruleKeyWithoutDep, Matchers.equalTo(ruleKeyWithDep));
    }
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 3 with CxxBinaryBuilder

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

the class CxxPythonExtensionDescriptionTest method runtimeDeps.

@Test
public void runtimeDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep#sandbox")).build()), new DefaultTargetNodeToBuildRuleTransformer());
    BuildTarget depTarget = BuildTargetFactory.newInstance("//:dep");
    BuildRule cxxBinary = new CxxBinaryBuilder(depTarget).build(resolver);
    CxxPythonExtension cxxPythonExtension = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:ext"), FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms()).setDeps(ImmutableSortedSet.of(cxxBinary.getBuildTarget())).build(resolver);
    assertThat(cxxPythonExtension.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(cxxBinary.getBuildTarget()));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 4 with CxxBinaryBuilder

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

the class PythonBinaryDescriptionTest method nonBuildDepsDoNotAffectRuleKey.

@Test
public void nonBuildDepsDoNotAffectRuleKey() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) {
        // First, calculate the rule key of a python binary with no deps.
        PythonBinaryBuilder pythonBinaryBuilder = PythonBinaryBuilder.create(BuildTargetFactory.newInstance("//:bin")).setMainModule("main").setPackageStyle(packageStyle);
        TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonBinaryBuilder.build());
        BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        PythonBinary pythonBinaryWithoutDep = pythonBinaryBuilder.build(resolver, filesystem, targetGraph);
        RuleKey ruleKeyWithoutDep = calculateRuleKey(resolver, pythonBinaryWithoutDep);
        // Next, calculate the rule key of a python binary with a deps on another binary.
        CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
        pythonBinaryBuilder.setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
        targetGraph = TargetGraphFactory.newInstance(cxxBinaryBuilder.build(), pythonBinaryBuilder.build());
        resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        cxxBinaryBuilder.build(resolver, filesystem, targetGraph);
        PythonBinary pythonBinaryWithDep = pythonBinaryBuilder.build(resolver, filesystem, targetGraph);
        RuleKey ruleKeyWithDep = calculateRuleKey(resolver, pythonBinaryWithDep);
        // Verify that the rule keys are identical.
        assertThat(ruleKeyWithoutDep, Matchers.equalTo(ruleKeyWithDep));
    }
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 5 with CxxBinaryBuilder

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

the class PythonBinaryDescriptionTest method runtimeDepOnDeps.

@Test
public void runtimeDepOnDeps() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) {
        CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
        PythonLibraryBuilder pythonLibraryBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
        PythonBinaryBuilder pythonBinaryBuilder = PythonBinaryBuilder.create(BuildTargetFactory.newInstance("//:bin")).setMainModule("main").setDeps(ImmutableSortedSet.of(pythonLibraryBuilder.getTarget())).setPackageStyle(packageStyle);
        TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxBinaryBuilder.build(), pythonLibraryBuilder.build(), pythonBinaryBuilder.build());
        BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        BuildRule cxxBinary = cxxBinaryBuilder.build(resolver, filesystem, targetGraph);
        pythonLibraryBuilder.build(resolver, filesystem, targetGraph);
        PythonBinary pythonBinary = pythonBinaryBuilder.build(resolver, filesystem, targetGraph);
        assertThat(String.format("Transitive runtime deps of %s [%s]", pythonBinary, packageStyle.toString()), BuildRules.getTransitiveRuntimeDeps(pythonBinary, resolver), Matchers.hasItem(cxxBinary.getBuildTarget()));
    }
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

CxxBinaryBuilder (com.facebook.buck.cxx.CxxBinaryBuilder)5 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 Test (org.junit.Test)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 TargetGraph (com.facebook.buck.rules.TargetGraph)4 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 BuildRule (com.facebook.buck.rules.BuildRule)3 RuleKey (com.facebook.buck.rules.RuleKey)2 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)1 BuildTarget (com.facebook.buck.model.BuildTarget)1