Search in sources :

Example 21 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class AppleBuildRulesTest method testRecursiveTargetsIncludesBundleBinaryFromOutsideBundle.

@Test
public void testRecursiveTargetsIncludesBundleBinaryFromOutsideBundle() throws Exception {
    BuildTarget libraryTarget = BuildTargetFactory.newInstance("//foo:lib");
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).build();
    BuildTarget bundleTarget = BuildTargetFactory.newInstance("//foo:bundle");
    TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.XCTEST)).setBinary(libraryTarget).build();
    BuildTarget rootTarget = BuildTargetFactory.newInstance("//foo:root");
    TargetNode<?, ?> rootNode = AppleLibraryBuilder.createBuilder(rootTarget).setDeps(ImmutableSortedSet.of(libraryTarget, bundleTarget)).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(ImmutableSet.of(libraryNode, bundleNode, rootNode));
    Optional<AppleDependenciesCache> cache = useCache ? Optional.of(new AppleDependenciesCache(targetGraph)) : Optional.empty();
    for (int i = 0; i < (useCache ? 2 : 1); i++) {
        Iterable<TargetNode<?, ?>> rules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.BUILDING, rootNode, Optional.empty());
        assertTrue(Iterables.elementsEqual(ImmutableSortedSet.of(libraryNode, bundleNode), rules));
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) Test(org.junit.Test)

Example 22 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class AppleBuildRulesTest method exportedDepsAreCollectedForCopying.

@Test
public void exportedDepsAreCollectedForCopying() throws Exception {
    BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
    TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
    BuildTarget fooFrameworkTarget = BuildTargetFactory.newInstance("//foo:framework");
    TargetNode<?, ?> fooFrameworkNode = AppleBundleBuilder.createBuilder(fooFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(fooLibTarget).build();
    BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
    TargetNode<?, ?> barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).setDeps(ImmutableSortedSet.of(fooFrameworkTarget)).setExportedDeps(ImmutableSortedSet.of(fooFrameworkTarget)).build();
    BuildTarget barFrameworkTarget = BuildTargetFactory.newInstance("//bar:framework");
    TargetNode<?, ?> barFrameworkNode = AppleBundleBuilder.createBuilder(barFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(barLibTarget).build();
    BuildTarget bazLibTarget = BuildTargetFactory.newInstance("//baz:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
    TargetNode<?, ?> bazLibNode = AppleLibraryBuilder.createBuilder(bazLibTarget).setDeps(ImmutableSortedSet.of(barFrameworkTarget)).build();
    BuildTarget bazFrameworkTarget = BuildTargetFactory.newInstance("//baz:framework");
    TargetNode<?, ?> bazFrameworkNode = AppleBundleBuilder.createBuilder(bazFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(bazLibTarget).build();
    ImmutableSet<TargetNode<?, ?>> targetNodes = ImmutableSet.<TargetNode<?, ?>>builder().add(fooLibNode, fooFrameworkNode, barLibNode, barFrameworkNode, bazLibNode, bazFrameworkNode).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(targetNodes);
    Optional<AppleDependenciesCache> cache = useCache ? Optional.of(new AppleDependenciesCache(targetGraph)) : Optional.empty();
    for (int i = 0; i < (useCache ? 2 : 1); i++) {
        Iterable<TargetNode<?, ?>> rules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.COPYING, bazFrameworkNode, Optional.empty());
        assertEquals(ImmutableSortedSet.of(barFrameworkNode, fooFrameworkNode), ImmutableSortedSet.copyOf(rules));
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) Test(org.junit.Test)

Example 23 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class RobolectricTestRuleTest method runtimeDepsIncludeTransitiveResources.

@Test
public void runtimeDepsIncludeTransitiveResources() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem(temporaryFolder.getRoot());
    BuildTarget genRuleTarget = BuildTargetFactory.newInstance("//:gen");
    TargetNode<?, ?> genRuleNode = GenruleBuilder.newGenruleBuilder(genRuleTarget).setOut("out").build();
    BuildTarget res2RuleTarget = BuildTargetFactory.newInstance("//:res2");
    TargetNode<?, ?> res2Node = AndroidResourceBuilder.createBuilder(res2RuleTarget).setRes(new DefaultBuildTargetSourcePath(genRuleTarget)).setRDotJavaPackage("foo.bar").build();
    BuildTarget robolectricBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base/robolectricTest:robolectricTest");
    TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(robolectricBuildTarget, filesystem).addDep(res2RuleTarget).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genRuleNode, res2Node, robolectricTestNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule genRule = resolver.requireRule(genRuleTarget);
    RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricBuildTarget);
    assertThat(robolectricTest.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(genRule.getBuildTarget()));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 24 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class ApplePackageDescriptionTest method descriptionExpandsLocationMacrosAndTracksDependencies.

@Test
public void descriptionExpandsLocationMacrosAndTracksDependencies() throws Exception {
    ApplePackageDescription description = descriptionWithCommand("echo $(location :exportfile)");
    BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//foo:binary");
    BuildTarget bundleBuildTarget = BuildTargetFactory.newInstance("//foo:bundle");
    BuildTarget exportFileBuildTarget = BuildTargetFactory.newInstance("//foo:exportfile");
    TargetGraph graph = TargetGraphFactory.newInstance(ExportFileBuilder.newExportFileBuilder(exportFileBuildTarget).build(), AppleBinaryBuilder.createBuilder(binaryBuildTarget).build(), AppleBundleBuilder.createBuilder(bundleBuildTarget).setBinary(binaryBuildTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).build());
    ApplePackageDescription.Arg arg = description.createUnpopulatedConstructorArg();
    arg.bundle = bundleBuildTarget;
    BuildTarget packageBuildTarget = BuildTargetFactory.newInstance("//foo:package#macosx-x86_64");
    BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(packageBuildTarget).build();
    resolver.requireAllRules(description.findDepsForTargetFromConstructorArgs(packageBuildTarget, params.getCellRoots(), arg));
    BuildRule rule = description.createBuildRule(graph, params, resolver, arg);
    assertThat(rule.getDeps(), hasItem(resolver.getRule(exportFileBuildTarget)));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 25 with TargetGraph

use of com.facebook.buck.rules.TargetGraph in project buck by facebook.

the class ApplePackageDescriptionTest method descriptionCreatesExternallyBuiltPackageRuleIfConfigExists.

@Test
public void descriptionCreatesExternallyBuiltPackageRuleIfConfigExists() throws Exception {
    ApplePackageDescription description = descriptionWithCommand("echo");
    BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//foo:binary");
    BuildTarget bundleBuildTarget = BuildTargetFactory.newInstance("//foo:bundle");
    TargetGraph graph = TargetGraphFactory.newInstance(AppleBinaryBuilder.createBuilder(binaryBuildTarget).build(), AppleBundleBuilder.createBuilder(bundleBuildTarget).setBinary(binaryBuildTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).build());
    ApplePackageDescription.Arg arg = description.createUnpopulatedConstructorArg();
    arg.bundle = bundleBuildTarget;
    BuildTarget packageBuildTarget = BuildTargetFactory.newInstance("//foo:package#macosx-x86_64");
    BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(packageBuildTarget).build();
    resolver.requireAllRules(description.findDepsForTargetFromConstructorArgs(packageBuildTarget, params.getCellRoots(), arg));
    BuildRule rule = description.createBuildRule(graph, new FakeBuildRuleParamsBuilder(packageBuildTarget).build(), resolver, arg);
    assertThat(rule, instanceOf(ExternallyBuiltApplePackage.class));
    assertThat(rule.getDeps(), hasItem(resolver.getRule(bundleBuildTarget.withFlavors(InternalFlavor.of("macosx-x86_64")))));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

TargetGraph (com.facebook.buck.rules.TargetGraph)267 Test (org.junit.Test)230 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)195 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)179 BuildTarget (com.facebook.buck.model.BuildTarget)157 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)126 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)119 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)96 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)88 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)75 BuildRule (com.facebook.buck.rules.BuildRule)60 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)58 Path (java.nio.file.Path)48 PathSourcePath (com.facebook.buck.rules.PathSourcePath)45 TargetNode (com.facebook.buck.rules.TargetNode)44 SourcePath (com.facebook.buck.rules.SourcePath)37 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)36 ImmutableSet (com.google.common.collect.ImmutableSet)29 Optional (java.util.Optional)25 ImmutableList (com.google.common.collect.ImmutableList)24