Search in sources :

Example 86 with TargetNode

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

the class TargetsCommandTest method testGetMatchingAppleLibraryBuildTarget.

@Test
public void testGetMatchingAppleLibraryBuildTarget() throws CmdLineException, IOException {
    BuildTarget libraryTarget = BuildTargetFactory.newInstance("//foo:lib");
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/foo.m")))).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(libraryNode);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    // No target depends on the referenced file.
    SortedMap<String, TargetNode<?, ?>> matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/bar.m"))), Optional.empty(), Optional.empty(), false, "BUCK");
    assertTrue(matchingBuildRules.isEmpty());
    // The AppleLibrary matches the referenced file.
    matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/foo.m"))), Optional.empty(), Optional.empty(), false, "BUCK");
    assertEquals(ImmutableSet.of("//foo:lib"), matchingBuildRules.keySet());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) Test(org.junit.Test)

Example 87 with TargetNode

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

the class IjModuleFactoryTest method testAndroidPrebuiltAar.

@Test
public void testAndroidPrebuiltAar() {
    final SourcePath androidSupportBinaryPath = new FakeSourcePath("third_party/java/support/support.aar");
    final Path androidSupportSourcesPath = Paths.get("third_party/java/support/support-sources.jar");
    final String androidSupportJavadocUrl = "file:///support/docs";
    final TargetNode<?, ?> androidPrebuiltAar = AndroidPrebuiltAarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/java/support:support")).setBinaryAar(androidSupportBinaryPath).setSourcesJar(androidSupportSourcesPath).setJavadocUrl(androidSupportJavadocUrl).build();
    final BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    final SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
    IjLibraryFactoryResolver ijLibraryFactoryResolver = new IjLibraryFactoryResolver() {

        @Override
        public Path getPath(SourcePath path) {
            return sourcePathResolver.getRelativePath(path);
        }

        @Override
        public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
            if (targetNode.equals(androidPrebuiltAar)) {
                return Optional.of(androidSupportBinaryPath);
            }
            return Optional.empty();
        }
    };
    Optional<IjLibrary> library = new DefaultIjLibraryFactory(ijLibraryFactoryResolver).getLibrary(androidPrebuiltAar);
    assertTrue(library.isPresent());
    assertEquals(library.get().getBinaryJar(), Optional.of(sourcePathResolver.getRelativePath(androidSupportBinaryPath)));
    assertEquals(library.get().getSourceJar(), Optional.of(androidSupportSourcesPath));
    assertEquals(library.get().getJavadocUrl(), Optional.of(androidSupportJavadocUrl));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) TargetNode(com.facebook.buck.rules.TargetNode) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 88 with TargetNode

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

the class IjModuleGraphTest method createModuleGraph.

public static IjModuleGraph createModuleGraph(ImmutableSet<TargetNode<?, ?>> targets, final ImmutableMap<TargetNode<?, ?>, SourcePath> javaLibraryPaths, final Function<? super TargetNode<?, ?>, Optional<Path>> rDotJavaClassPathResolver, AggregationMode aggregationMode) {
    final SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    IjLibraryFactoryResolver sourceOnlyResolver = new IjLibraryFactoryResolver() {

        @Override
        public Path getPath(SourcePath path) {
            return sourcePathResolver.getAbsolutePath(path);
        }

        @Override
        public Optional<SourcePath> getPathIfJavaLibrary(TargetNode<?, ?> targetNode) {
            return Optional.ofNullable(javaLibraryPaths.get(targetNode));
        }
    };
    BuckConfig buckConfig = FakeBuckConfig.builder().build();
    IjProjectConfig projectConfig = IjProjectBuckConfig.create(buckConfig);
    IjModuleFactory moduleFactory = new IjModuleFactory(new FakeProjectFilesystem(), new IjModuleFactoryResolver() {

        @Override
        public Optional<Path> getDummyRDotJavaPath(TargetNode<?, ?> targetNode) {
            return rDotJavaClassPathResolver.apply(targetNode);
        }

        @Override
        public Path getAndroidManifestPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
            return Paths.get("TestAndroidManifest.xml");
        }

        @Override
        public Optional<Path> getLibraryAndroidManifestPath(TargetNode<AndroidLibraryDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getProguardConfigPath(TargetNode<AndroidBinaryDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getAndroidResourcePath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getAssetsPath(TargetNode<AndroidResourceDescription.Arg, ?> targetNode) {
            return Optional.empty();
        }

        @Override
        public Optional<Path> getAnnotationOutputPath(TargetNode<? extends JvmLibraryArg, ?> targetNode) {
            return Optional.empty();
        }
    }, projectConfig, false);
    IjLibraryFactory libraryFactory = new DefaultIjLibraryFactory(sourceOnlyResolver);
    return IjModuleGraph.from(projectConfig, TargetGraphFactory.newInstance(targets), libraryFactory, moduleFactory, aggregationMode);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) TargetNode(com.facebook.buck.rules.TargetNode) Optional(java.util.Optional) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) JvmLibraryArg(com.facebook.buck.jvm.java.JvmLibraryArg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)

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