use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class DistBuildTargetGraphCodec method createTargetGraph.
public TargetGraphAndBuildTargets createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph, Function<Integer, Cell> cellLookup) throws IOException {
ImmutableMap.Builder<BuildTarget, TargetNode<?, ?>> targetNodeIndexBuilder = ImmutableMap.builder();
ImmutableSet.Builder<BuildTarget> buildTargetsBuilder = ImmutableSet.builder();
for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
Cell cell = cellLookup.apply(remoteNode.getCellIndex());
ProjectFilesystem projectFilesystem = cell.getFilesystem();
BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);
if (topLevelTargets.contains(target.getFullyQualifiedName())) {
buildTargetsBuilder.add(target);
}
@SuppressWarnings("unchecked") Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());
TargetNode<?, ?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target, rawNode, input -> SimplePerfEvent.scope(Optional.empty(), input));
targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
}
ImmutableSet<BuildTarget> buildTargets = buildTargetsBuilder.build();
Preconditions.checkArgument(topLevelTargets.size() == buildTargets.size());
ImmutableMap<BuildTarget, TargetNode<?, ?>> targetNodeIndex = targetNodeIndexBuilder.build();
MutableDirectedGraph<TargetNode<?, ?>> mutableTargetGraph = new MutableDirectedGraph<>();
for (TargetNode<?, ?> targetNode : targetNodeIndex.values()) {
mutableTargetGraph.addNode(targetNode);
for (BuildTarget dep : targetNode.getDeps()) {
mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
}
}
// TODO(tophyr): make this work with TargetGroups
TargetGraph targetGraph = new TargetGraph(mutableTargetGraph, targetNodeIndex, ImmutableSet.of());
return TargetGraphAndBuildTargets.builder().setTargetGraph(targetGraph).addAllBuildTargets(buildTargets).build();
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AndroidResourceTest method testRuleKeyForDifferentInputFilenames.
@Test
public void testRuleKeyForDifferentInputFilenames() throws Exception {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base:res");
Function<Path, BuildRuleResolver> createResourceRule = (Path resourcePath) -> {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
projectFilesystem.createNewFile(resourcePath);
projectFilesystem.createNewFile(Paths.get("java/src/com/facebook/base/assets/drawable/B.xml"));
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(buildTarget, projectFilesystem).setRes(new FakeSourcePath(projectFilesystem, "java/src/com/facebook/base/res")).setRDotJavaPackage("com.facebook").setAssets(new FakeSourcePath(projectFilesystem, "java/src/com/facebook/base/assets")).setManifest(new PathSourcePath(projectFilesystem, Paths.get("java/src/com/facebook/base/AndroidManifest.xml"))).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode);
return new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
};
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("java/src/com/facebook/base/AndroidManifest.xml", "bbbbbbbbbb", "java/src/com/facebook/base/assets/drawable/B.xml", "aaaaaaaaaaaa", "java/src/com/facebook/base/res/drawable/A.xml", "dddddddddd", "java/src/com/facebook/base/res/drawable/C.xml", "eeeeeeeeee"));
BuildRuleResolver resolver1 = createResourceRule.apply(Paths.get("java/src/com/facebook/base/res/drawable/A.xml"));
BuildRuleResolver resolver2 = createResourceRule.apply(Paths.get("java/src/com/facebook/base/res/drawable/C.xml"));
BuildRule androidResource1 = resolver1.requireRule(buildTarget);
SourcePathRuleFinder ruleFinder1 = new SourcePathRuleFinder(resolver1);
SourcePathResolver pathResolver1 = new SourcePathResolver(ruleFinder1);
BuildRule androidResource2 = resolver2.requireRule(buildTarget);
SourcePathRuleFinder ruleFinder2 = new SourcePathRuleFinder(resolver2);
SourcePathResolver pathResolver2 = new SourcePathResolver(ruleFinder2);
RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashCache, pathResolver1, ruleFinder1).build(androidResource1);
RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashCache, pathResolver2, ruleFinder2).build(androidResource2);
assertNotEquals("The two android_resource rules should have different rule keys.", ruleKey1, ruleKey2);
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class DuplicateResourcesTest method getAaptStepShellCommand.
private ImmutableList<String> getAaptStepShellCommand(TargetNode<AndroidBinaryDescription.Arg, AndroidBinaryDescription> binary) {
TargetGraph targetGraph = TargetGraphFactory.newInstance(binary, mainRes, directDepRes, transitiveDepRes, transitiveDepLib, bottomDepRes, library, keystore);
ActionGraphAndResolver actionGraphAndResolver = ActionGraphCache.getFreshActionGraph(BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1))), new DefaultTargetNodeToBuildRuleTransformer(), targetGraph);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(actionGraphAndResolver.getResolver()));
ImmutableSet<ImmutableList<Step>> ruleSteps = RichStream.from(actionGraphAndResolver.getActionGraph().getNodes()).filter(AaptPackageResources.class).filter(r -> androidBinaryTarget.getUnflavoredBuildTarget().equals(r.getBuildTarget().getUnflavoredBuildTarget())).map(b -> b.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext())).map(steps -> steps.stream().filter(step -> step instanceof AaptStep).collect(MoreCollectors.toImmutableList())).filter(steps -> !steps.isEmpty()).collect(MoreCollectors.toImmutableSet());
assertEquals(1, ruleSteps.size());
assertEquals(1, Iterables.getOnlyElement(ruleSteps).size());
AaptStep step = (AaptStep) Iterables.getOnlyElement(Iterables.getOnlyElement(ruleSteps));
AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver(Optional.of(filesystem.getPath("/android-sdk")), Optional.of(filesystem.getPath("/android-build-tools")), Optional.empty(), Optional.empty());
AndroidPlatformTarget androidPlatformTarget = AndroidPlatformTarget.createFromDefaultDirectoryStructure("", androidDirectoryResolver, "", ImmutableSet.of(), Optional.empty());
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
return step.getShellCommand(context);
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AuditInputCommandTest method testNonExistentInputFileThrows.
@Test
public void testNonExistentInputFileThrows() throws IOException {
thrown.expect(HumanReadableException.class);
thrown.expectMessage("Target //:test-java-library refers to non-existent input file: " + MorePaths.pathWithPlatformSeparators("src/com/facebook/NonExistentFile.java"));
BuildTarget rootTarget = BuildTargetFactory.newInstance("//:test-java-library");
TargetNode<?, ?> rootNode = JavaLibraryBuilder.createBuilder(rootTarget).addSrc(Paths.get("src/com/facebook/NonExistentFile.java")).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(rootNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
auditInputCommand.printJsonInputs(params, targetGraph);
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AuditInputCommandTest method testJsonClassPathOutput.
@Test
public void testJsonClassPathOutput() throws IOException {
ObjectMapper mapper = ObjectMappers.newDefaultInstance();
final String expectedJson = Joiner.on("").join("{", "\"//:test-android-library\":", "[", mapper.valueToTree(MorePaths.pathWithPlatformSeparators("src/com/facebook/AndroidLibraryTwo.java")), ",", mapper.valueToTree(MorePaths.pathWithPlatformSeparators("src/com/facebook/TestAndroidLibrary.java")), "],", "\"//:test-java-library\":", "[", mapper.valueToTree(MorePaths.pathWithPlatformSeparators("src/com/facebook/TestJavaLibrary.java")), "]", "}");
BuildTarget rootTarget = BuildTargetFactory.newInstance("//:test-java-library");
TargetNode<?, ?> rootNode = JavaLibraryBuilder.createBuilder(rootTarget).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
BuildTarget libraryTarget = BuildTargetFactory.newInstance("//:test-android-library");
TargetNode<?, ?> libraryNode = JavaLibraryBuilder.createBuilder(libraryTarget).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addSrc(Paths.get("src/com/facebook/AndroidLibraryTwo.java")).addDep(rootTarget).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(rootNode, libraryNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
auditInputCommand.printJsonInputs(params, targetGraph);
assertEquals(expectedJson, console.getTextWrittenToStdOut());
assertEquals("", console.getTextWrittenToStdErr());
}
Aggregations