Search in sources :

Example 71 with TargetNode

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());
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 72 with TargetNode

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());
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 73 with TargetNode

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)));
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 74 with TargetNode

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;
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) AppleResourceDescription(com.facebook.buck.apple.AppleResourceDescription) TargetNode(com.facebook.buck.rules.TargetNode) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) HalideLibraryDescription(com.facebook.buck.halide.HalideLibraryDescription) AppleTestDescription(com.facebook.buck.apple.AppleTestDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleBinaryDescription(com.facebook.buck.apple.AppleBinaryDescription) AppleLibraryDescription(com.facebook.buck.apple.AppleLibraryDescription)

Example 75 with TargetNode

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();
}
Also used : CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableList(com.google.common.collect.ImmutableList) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)

Aggregations

TargetNode (com.facebook.buck.rules.TargetNode)88 BuildTarget (com.facebook.buck.model.BuildTarget)73 TargetGraph (com.facebook.buck.rules.TargetGraph)43 Test (org.junit.Test)40 Path (java.nio.file.Path)36 ImmutableSet (com.google.common.collect.ImmutableSet)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 Map (java.util.Map)18 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 ImmutableList (com.google.common.collect.ImmutableList)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)13 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)13 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 Cell (com.facebook.buck.rules.Cell)13 IOException (java.io.IOException)13 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)12