use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AuditInputCommandTest method testJsonContainsRulesWithNoFiles.
@Test
public void testJsonContainsRulesWithNoFiles() throws IOException {
ObjectMapper mapper = ObjectMappers.newDefaultInstance();
final String expectedJson = Joiner.on("").join("{", "\"//:test-exported-dep\":", "[", "],", "\"//:test-java-library\":", "[", mapper.valueToTree(MorePaths.pathWithPlatformSeparators("src/com/facebook/TestJavaLibrary.java")), "]", "}");
BuildTarget exportedTarget = BuildTargetFactory.newInstance("//:test-java-library");
TargetNode<?, ?> exportedNode = JavaLibraryBuilder.createBuilder(exportedTarget).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
BuildTarget rootTarget = BuildTargetFactory.newInstance("//:test-exported-dep");
TargetNode<?, ?> rootNode = JavaLibraryBuilder.createBuilder(rootTarget).addExportedDep(exportedTarget).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(rootNode, exportedNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
auditInputCommand.printJsonInputs(params, targetGraph);
assertEquals(expectedJson, console.getTextWrittenToStdOut());
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class TargetNodeTranslatorTest method noTranslate.
@Test
public void noTranslate() {
BuildTarget a = BuildTargetFactory.newInstance("//:a");
BuildTarget b = BuildTargetFactory.newInstance("//:b");
BuildTarget c = BuildTargetFactory.newInstance("//:c");
TargetNode<CxxLibraryDescription.Arg, ?> node = new CxxLibraryBuilder(a).setDeps(ImmutableSortedSet.of(b)).setExportedDeps(ImmutableSortedSet.of(c)).build();
TargetNodeTranslator translator = new TargetNodeTranslator(ImmutableList.of()) {
@Override
public Optional<BuildTarget> translateBuildTarget(BuildTarget target) {
return Optional.empty();
}
@Override
public Optional<ImmutableMap<BuildTarget, Version>> getSelectedVersions(BuildTarget target) {
return Optional.empty();
}
};
Optional<TargetNode<CxxLibraryDescription.Arg, ?>> translated = translator.translateNode(node);
assertFalse(translated.isPresent());
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class TargetNodeTranslatorTest method translate.
@Test
public void translate() {
BuildTarget a = BuildTargetFactory.newInstance("//:a");
BuildTarget b = BuildTargetFactory.newInstance("//:b");
BuildTarget c = BuildTargetFactory.newInstance("//:c");
final BuildTarget d = BuildTargetFactory.newInstance("//:d");
TargetNode<CxxLibraryDescription.Arg, ?> node = new CxxLibraryBuilder(a).setDeps(ImmutableSortedSet.of(b)).setExportedDeps(ImmutableSortedSet.of(c)).build();
TargetNodeTranslator translator = new TargetNodeTranslator(ImmutableList.of()) {
@Override
public Optional<BuildTarget> translateBuildTarget(BuildTarget target) {
return Optional.of(d);
}
@Override
public Optional<ImmutableMap<BuildTarget, Version>> getSelectedVersions(BuildTarget target) {
return Optional.empty();
}
};
Optional<TargetNode<CxxLibraryDescription.Arg, ?>> translated = translator.translateNode(node);
assertThat(translated.get().getBuildTarget(), Matchers.equalTo(d));
assertThat(translated.get().getDeclaredDeps(), Matchers.equalTo(ImmutableSet.of(d)));
assertThat(translated.get().getExtraDeps(), Matchers.equalTo(ImmutableSet.of(d)));
assertThat(translated.get().getConstructorArg().deps, Matchers.equalTo(ImmutableSortedSet.of(d)));
assertThat(translated.get().getConstructorArg().exportedDeps, Matchers.equalTo(ImmutableSortedSet.of(d)));
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGenerator method generateProjectTarget.
@SuppressWarnings("unchecked")
private Optional<PBXTarget> generateProjectTarget(TargetNode<?, ?> targetNode) throws IOException {
Preconditions.checkState(isBuiltByCurrentProject(targetNode.getBuildTarget()), "should not generate rule if it shouldn't be built by current project");
Optional<PBXTarget> result = Optional.empty();
if (targetNode.getDescription() instanceof AppleLibraryDescription) {
result = Optional.of(generateAppleLibraryTarget(project, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetNode, Optional.empty()));
} else if (targetNode.getDescription() instanceof CxxLibraryDescription) {
result = Optional.of(generateCxxLibraryTarget(project, (TargetNode<CxxLibraryDescription.Arg, ?>) targetNode, ImmutableSet.of(), ImmutableSet.of(), Optional.empty()));
} else if (targetNode.getDescription() instanceof AppleBinaryDescription) {
result = Optional.of(generateAppleBinaryTarget(project, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetNode));
} else if (targetNode.getDescription() instanceof AppleBundleDescription) {
TargetNode<AppleBundleDescription.Arg, ?> bundleTargetNode = (TargetNode<AppleBundleDescription.Arg, ?>) targetNode;
result = Optional.of(generateAppleBundleTarget(project, bundleTargetNode, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetGraph.get(bundleTargetNode.getConstructorArg().binary), Optional.empty()));
} else if (targetNode.getDescription() instanceof AppleTestDescription) {
result = Optional.of(generateAppleTestTarget((TargetNode<AppleTestDescription.Arg, ?>) targetNode));
} else if (targetNode.getDescription() instanceof AppleResourceDescription) {
checkAppleResourceTargetNodeReferencingValidContents((TargetNode<AppleResourceDescription.Arg, ?>) targetNode);
} else if (targetNode.getDescription() instanceof HalideLibraryDescription) {
TargetNode<HalideLibraryDescription.Arg, ?> halideTargetNode = (TargetNode<HalideLibraryDescription.Arg, ?>) targetNode;
BuildTarget buildTarget = targetNode.getBuildTarget();
// The generated target just runs a shell script that invokes the "compiler" with the
// correct target architecture.
result = generateHalideLibraryTarget(project, halideTargetNode);
// Make sure the compiler gets built at project time, since we'll need
// it to generate the shader code during the Xcode build.
requiredBuildTargetsBuilder.add(HalideLibraryDescription.createHalideCompilerBuildTarget(buildTarget));
// headers from.
if (HalideLibraryDescription.isPlatformSupported(halideTargetNode.getConstructorArg(), defaultCxxPlatform)) {
// Run the compiler once at project time to generate the header
// file needed for compilation if the Halide target is for the default
// platform.
requiredBuildTargetsBuilder.add(buildTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, defaultCxxPlatform.getFlavor()));
}
}
buckEventBus.post(ProjectGenerationEvent.processed());
return result;
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGenerator method getCopyFilesBuildPhases.
private ImmutableList<PBXBuildPhase> getCopyFilesBuildPhases(Iterable<TargetNode<?, ?>> copiedNodes) {
// Bucket build rules into bins by their destinations
ImmutableSetMultimap.Builder<CopyFilePhaseDestinationSpec, TargetNode<?, ?>> ruleByDestinationSpecBuilder = ImmutableSetMultimap.builder();
for (TargetNode<?, ?> copiedNode : copiedNodes) {
Optional<CopyFilePhaseDestinationSpec> optionalDestinationSpec = getDestinationSpec(copiedNode);
if (optionalDestinationSpec.isPresent()) {
ruleByDestinationSpecBuilder.put(optionalDestinationSpec.get(), copiedNode);
}
}
ImmutableList.Builder<PBXBuildPhase> phases = ImmutableList.builder();
ImmutableSetMultimap<CopyFilePhaseDestinationSpec, TargetNode<?, ?>> ruleByDestinationSpec = ruleByDestinationSpecBuilder.build();
// Emit a copy files phase for each destination.
for (CopyFilePhaseDestinationSpec destinationSpec : ruleByDestinationSpec.keySet()) {
Iterable<TargetNode<?, ?>> targetNodes = ruleByDestinationSpec.get(destinationSpec);
phases.add(getSingleCopyFilesBuildPhase(destinationSpec, targetNodes));
}
return phases.build();
}
Aggregations