use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class AndroidResourceTest method testInputRuleKeyChangesIfDependencySymbolsChanges.
@Test
public void testInputRuleKeyChangesIfDependencySymbolsChanges() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
TargetNode<?, ?> depNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).setManifest(new FakeSourcePath("manifest")).setRes(Paths.get("res")).build();
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:rule"), filesystem).setDeps(ImmutableSortedSet.of(depNode.getBuildTarget())).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, resourceNode);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AndroidResource dep = (AndroidResource) resolver.requireRule(depNode.getBuildTarget());
AndroidResource resource = (AndroidResource) resolver.requireRule(resourceNode.getBuildTarget());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getPathToTextSymbolsFile()));
RuleKey original = new InputBasedRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(resource);
fileHashCache.invalidateAll();
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getPathToTextSymbolsFile()));
RuleKey changed = new InputBasedRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(resource);
assertThat(original, Matchers.not(Matchers.equalTo(changed)));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class AndroidLibraryTest method testAndroidAnnotation.
@Test
public void testAndroidAnnotation() throws Exception {
BuildTarget processorTarget = BuildTargetFactory.newInstance("//java/processor:processor");
TargetNode<?, ?> processorNode = JavaLibraryBuilder.createBuilder(processorTarget).addSrc(Paths.get("java/processor/processor.java")).build();
BuildTarget libTarget = BuildTargetFactory.newInstance("//java/lib:lib");
TargetNode<?, ?> libraryNode = AndroidLibraryBuilder.createBuilder(libTarget).addProcessor("MyProcessor").addProcessorBuildTarget(processorNode.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(processorNode, libraryNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AndroidLibrary library = (AndroidLibrary) ruleResolver.requireRule(libTarget);
assertTrue(library.getGeneratedSourcePath().isPresent());
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class ApkGenruleDescriptionTest method testClasspathTransitiveDepsBecomeFirstOrderDeps.
@Test
public void testClasspathTransitiveDepsBecomeFirstOrderDeps() throws Exception {
SourcePathResolver emptyPathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget installableApkTarget = BuildTargetFactory.newInstance("//:installable");
TargetNode<?, ?> installableApkNode = FakeTargetNodeBuilder.build(new FakeInstallable(installableApkTarget, emptyPathResolver));
TargetNode<?, ?> transitiveDepNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:dep")).addSrc(Paths.get("Dep.java")).build();
TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:target")).addSrc(Paths.get("Other.java")).addDep(transitiveDepNode.getBuildTarget()).build();
TargetNode<?, ?> genruleNode = ApkGenruleBuilder.create(BuildTargetFactory.newInstance("//:rule")).setOut("out").setCmd("$(classpath //exciting:target)").setApk(installableApkTarget).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(installableApkNode, transitiveDepNode, depNode, genruleNode);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule transitiveDep = resolver.requireRule(transitiveDepNode.getBuildTarget());
BuildRule dep = resolver.requireRule(depNode.getBuildTarget());
BuildRule genrule = resolver.requireRule(genruleNode.getBuildTarget());
assertThat(genrule.getDeps(), Matchers.hasItems(dep, transitiveDep));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class AppleBuildRulesTest method linkingStopsAtGenruleDep.
@Test
public void linkingStopsAtGenruleDep() throws Exception {
// Pass a random static lib in a genrule and make sure a framework
// depending on the genrule doesn't link against or copy in the static lib.
BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib");
TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
BuildTarget fooGenruleTarget = BuildTargetFactory.newInstance("//foo:genrule");
TargetNode<?, ?> fooGenruleNode = GenruleBuilder.newGenruleBuilder(fooGenruleTarget).setOut("foo").setCmd("echo hi > $OUT").setSrcs(ImmutableList.of(new DefaultBuildTargetSourcePath(fooLibTarget))).build();
BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).setDeps(ImmutableSortedSet.of(fooGenruleTarget)).build();
BuildTarget barFrameworkTarget = BuildTargetFactory.newInstance("//bar:framework");
TargetNode<?, ?> barFrameworkNode = AppleBundleBuilder.createBuilder(barFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(barLibTarget).build();
ImmutableSet<TargetNode<?, ?>> targetNodes = ImmutableSet.<TargetNode<?, ?>>builder().add(fooLibNode, fooGenruleNode, barLibNode, barFrameworkNode).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.LINKING, barFrameworkNode, Optional.empty());
assertEquals(ImmutableSortedSet.of(fooGenruleNode), ImmutableSortedSet.copyOf(rules));
}
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class AppleBuildRulesTest method copyingStopsAtGenruleDep.
@Test
public void copyingStopsAtGenruleDep() throws Exception {
// Pass a random static lib in a genrule and make sure a framework
// depending on the genrule doesn't link against or copy in the static lib.
BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib");
TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
BuildTarget fooGenruleTarget = BuildTargetFactory.newInstance("//foo:genrule");
TargetNode<?, ?> fooGenruleNode = GenruleBuilder.newGenruleBuilder(fooGenruleTarget).setOut("foo").setCmd("echo hi > $OUT").setSrcs(ImmutableList.of(new DefaultBuildTargetSourcePath(fooLibTarget))).build();
BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).setDeps(ImmutableSortedSet.of(fooGenruleTarget)).build();
BuildTarget barFrameworkTarget = BuildTargetFactory.newInstance("//bar:framework");
TargetNode<?, ?> barFrameworkNode = AppleBundleBuilder.createBuilder(barFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(barLibTarget).build();
ImmutableSet<TargetNode<?, ?>> targetNodes = ImmutableSet.<TargetNode<?, ?>>builder().add(fooLibNode, fooGenruleNode, barLibNode, barFrameworkNode).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, barFrameworkNode, Optional.empty());
assertEquals(ImmutableSortedSet.of(fooGenruleNode), ImmutableSortedSet.copyOf(rules));
}
}
Aggregations