Search in sources :

Example 21 with BuildRuleResolver

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

the class AndroidInstrumentationApkTest method testAndroidInstrumentationApkExcludesClassesFromInstrumentedApk.

@Test
public void testAndroidInstrumentationApkExcludesClassesFromInstrumentedApk() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    BuildTarget javaLibrary1Target = BuildTargetFactory.newInstance("//java/com/example:lib1");
    final FakeJavaLibrary javaLibrary1 = new FakeJavaLibrary(javaLibrary1Target, pathResolver);
    FakeJavaLibrary javaLibrary2 = new FakeJavaLibrary(BuildTargetFactory.newInstance("//java/com/example:lib2"), pathResolver, /* deps */
    ImmutableSortedSet.of((BuildRule) javaLibrary1)) {

        @Override
        public ImmutableSet<SourcePath> getTransitiveClasspaths() {
            return ImmutableSet.of(new DefaultBuildTargetSourcePath(javaLibrary1Target), getSourcePathToOutput());
        }
    };
    BuildTarget javaLibrary3Target = BuildTargetFactory.newInstance("//java/com/example:lib3");
    final FakeJavaLibrary javaLibrary3 = new FakeJavaLibrary(javaLibrary3Target, pathResolver);
    FakeJavaLibrary javaLibrary4 = new FakeJavaLibrary(BuildTargetFactory.newInstance("//java/com/example:lib4"), pathResolver, /* deps */
    ImmutableSortedSet.of((BuildRule) javaLibrary3)) {

        @Override
        public ImmutableSet<SourcePath> getTransitiveClasspaths() {
            return ImmutableSet.of(new DefaultBuildTargetSourcePath(javaLibrary3Target), getSourcePathToOutput());
        }
    };
    ruleResolver.addToIndex(javaLibrary1);
    ruleResolver.addToIndex(javaLibrary2);
    ruleResolver.addToIndex(javaLibrary3);
    ruleResolver.addToIndex(javaLibrary4);
    BuildRule keystore = KeystoreBuilder.createBuilder(BuildTargetFactory.newInstance("//keystores:debug")).setProperties(new FakeSourcePath("keystores/debug.properties")).setStore(new FakeSourcePath("keystores/debug.keystore")).build(ruleResolver);
    // AndroidBinaryRule transitively depends on :lib1, :lib2, and :lib3.
    AndroidBinaryBuilder androidBinaryBuilder = AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//apps:app"));
    ImmutableSortedSet<BuildTarget> originalDepsTargets = ImmutableSortedSet.of(javaLibrary2.getBuildTarget(), javaLibrary3.getBuildTarget());
    androidBinaryBuilder.setManifest(new FakeSourcePath("apps/AndroidManifest.xml")).setKeystore(keystore.getBuildTarget()).setOriginalDeps(originalDepsTargets);
    AndroidBinary androidBinary = androidBinaryBuilder.build(ruleResolver);
    // AndroidInstrumentationApk transitively depends on :lib1, :lib2, :lib3, and :lib4.
    ImmutableSortedSet<BuildTarget> apkOriginalDepsTargets = ImmutableSortedSet.of(javaLibrary2.getBuildTarget(), javaLibrary4.getBuildTarget());
    AndroidInstrumentationApkDescription.Arg arg = new AndroidInstrumentationApkDescription.Arg();
    arg.apk = androidBinary.getBuildTarget();
    arg.deps = apkOriginalDepsTargets;
    arg.manifest = new FakeSourcePath("apps/InstrumentationAndroidManifest.xml");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//apps:instrumentation")).setDeclaredDeps(ruleResolver.getAllRules(apkOriginalDepsTargets)).setExtraDeps(ImmutableSortedSet.of(androidBinary)).build();
    AndroidInstrumentationApk androidInstrumentationApk = (AndroidInstrumentationApk) new AndroidInstrumentationApkDescription(new ProGuardConfig(FakeBuckConfig.builder().build()), DEFAULT_JAVAC_OPTIONS, ImmutableMap.of(), MoreExecutors.newDirectExecutorService(), CxxPlatformUtils.DEFAULT_CONFIG, new DxConfig(FakeBuckConfig.builder().build())).createBuildRule(TargetGraph.EMPTY, params, ruleResolver, arg);
    assertEquals("//apps:app should have three JAR files to dex.", ImmutableSet.of(BuildTargets.getGenPath(javaLibrary1.getProjectFilesystem(), javaLibrary1.getBuildTarget(), "%s.jar"), BuildTargets.getGenPath(javaLibrary2.getProjectFilesystem(), javaLibrary2.getBuildTarget(), "%s.jar"), BuildTargets.getGenPath(javaLibrary3.getProjectFilesystem(), javaLibrary3.getBuildTarget(), "%s.jar")), androidBinary.getAndroidPackageableCollection().getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()));
    assertEquals("//apps:instrumentation should have one JAR file to dex.", ImmutableSet.of(BuildTargets.getGenPath(javaLibrary4.getProjectFilesystem(), javaLibrary4.getBuildTarget(), "%s.jar")), androidInstrumentationApk.getAndroidPackageableCollection().getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 22 with BuildRuleResolver

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

the class AndroidLibraryDescriptionTest method rulesMatchingDepQueryBecomeFirstOrderDeps.

@Test
public void rulesMatchingDepQueryBecomeFirstOrderDeps() throws Exception {
    // Set up target graph: rule -> lib -> sublib -> bottom
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> bottomNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:bottom")).build();
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> sublibNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:sublib")).addDep(bottomNode.getBuildTarget()).build();
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> libNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addDep(sublibNode.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(bottomNode, libNode, sublibNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule bottomRule = resolver.addToIndex(new FakeBuildRule(bottomNode.getBuildTarget(), pathResolver));
    FakeBuildRule sublibRule = resolver.addToIndex(new FakeBuildRule(sublibNode.getBuildTarget(), pathResolver, ImmutableSortedSet.of(bottomRule)));
    FakeBuildRule libRule = resolver.addToIndex(new FakeBuildRule(libNode.getBuildTarget(), pathResolver, ImmutableSortedSet.of(sublibRule)));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule javaLibrary = AndroidLibraryBuilder.createBuilder(target).addDep(libNode.getBuildTarget()).setDepsQuery(Query.of("filter('.*lib', deps($declared_deps))")).build(resolver, targetGraph);
    assertThat(javaLibrary.getDeps(), Matchers.hasItems(libRule, sublibRule));
    // The bottom rule should be filtered since it does not match the regex
    assertThat(javaLibrary.getDeps(), Matchers.not(Matchers.hasItem(bottomRule)));
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 23 with BuildRuleResolver

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

the class AndroidLibraryDescriptionTest method rulesExportedFromProvidedDepsBecomeFirstOrderDeps.

@Test
public void rulesExportedFromProvidedDepsBecomeFirstOrderDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule transitiveExportedRule = resolver.addToIndex(new FakeBuildRule("//:transitive_exported_rule", pathResolver));
    FakeExportDependenciesRule exportedRule = resolver.addToIndex(new FakeExportDependenciesRule("//:exported_rule", pathResolver, transitiveExportedRule));
    FakeExportDependenciesRule exportingRule = resolver.addToIndex(new FakeExportDependenciesRule("//:exporting_rule", pathResolver, exportedRule));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule javaLibrary = AndroidLibraryBuilder.createBuilder(target).addProvidedDep(exportingRule.getBuildTarget()).build(resolver);
    assertThat(javaLibrary.getDeps(), Matchers.allOf(Matchers.hasItem(exportedRule), Matchers.hasItem(transitiveExportedRule)));
}
Also used : FakeExportDependenciesRule(com.facebook.buck.rules.FakeExportDependenciesRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 24 with BuildRuleResolver

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

the class AndroidLibraryGraphEnhancerTest method testEmptyResources.

@Test
public void testEmptyResources() {
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:library");
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(buildTarget, new FakeBuildRuleParamsBuilder(buildTarget).build(), DEFAULT_JAVAC_OPTIONS, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
    false, /* unionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), false);
    Optional<DummyRDotJava> result = graphEnhancer.getBuildableForAndroidResources(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), /* createdBuildableIfEmptyDeps */
    false);
    assertFalse(result.isPresent());
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 25 with BuildRuleResolver

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

the class AndroidLibraryGraphEnhancerTest method testBuildableIsCreated.

@Test
public void testBuildableIsCreated() {
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//java/com/example:library");
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    BuildRule resourceRule1 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res1")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res1")).build());
    BuildRule resourceRule2 = ruleResolver.addToIndex(AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(BuildTargetFactory.newInstance("//android_res/com/example:res2")).setRDotJavaPackage("com.facebook").setRes(new FakeSourcePath("android_res/com/example/res2")).build());
    BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.of(resourceRule1, resourceRule2)).build();
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(buildTarget, buildRuleParams, DEFAULT_JAVAC_OPTIONS, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
    false, /* unionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), false);
    Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(ruleResolver, /* createBuildableIfEmptyDeps */
    false);
    assertTrue(dummyRDotJava.isPresent());
    assertEquals("DummyRDotJava must contain these exact AndroidResourceRules.", // Note: these are the reverse order to which they are in the buildRuleParams.
    ImmutableList.of(resourceRule1, resourceRule2), dummyRDotJava.get().getAndroidResourceDeps());
    assertEquals("//java/com/example:library#dummy_r_dot_java", dummyRDotJava.get().getFullyQualifiedName());
    assertEquals("DummyRDotJava must depend on the two AndroidResourceRules.", ImmutableSet.of("//android_res/com/example:res1", "//android_res/com/example:res2"), dummyRDotJava.get().getDeps().stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)622 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)578 Test (org.junit.Test)540 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)402 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)376 BuildTarget (com.facebook.buck.model.BuildTarget)287 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)240 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)211 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 TargetGraph (com.facebook.buck.rules.TargetGraph)196 BuildRule (com.facebook.buck.rules.BuildRule)185 Path (java.nio.file.Path)136 SourcePath (com.facebook.buck.rules.SourcePath)133 PathSourcePath (com.facebook.buck.rules.PathSourcePath)104 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)83 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)75 RuleKey (com.facebook.buck.rules.RuleKey)71 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)54