Search in sources :

Example 1 with FakeBuildRule

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

the class AndroidBinaryGraphEnhancerTest method testResourceRulesDependOnRulesBehindResourceSourcePaths.

@Test
public void testResourceRulesDependOnRulesBehindResourceSourcePaths() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FakeBuildRule resourcesDep = ruleResolver.addToIndex(new FakeBuildRule(BuildTargetFactory.newInstance("//:resource_dep"), pathResolver));
    resourcesDep.setOutputFile("foo");
    AndroidResource resource = ruleResolver.addToIndex(new AndroidResource(new FakeBuildRuleParamsBuilder("//:resources").build().copyAppendingExtraDeps(ImmutableSortedSet.of(resourcesDep)), ruleFinder, ImmutableSortedSet.of(), resourcesDep.getSourcePathToOutput(), ImmutableSortedMap.of(), null, null, ImmutableSortedMap.of(), new FakeSourcePath("manifest"), false));
    // set it up.
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(resource)).build();
    AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(originalParams, ruleResolver, ResourcesFilter.ResourceCompressionMode.ENABLED_WITH_STRINGS_AS_ASSETS, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
    EnumSet.noneOf(RType.class), Optional.empty(), /* locales */
    ImmutableSet.of(), new FakeSourcePath("AndroidManifest.xml"), AndroidBinary.PackageType.DEBUG, /* cpuFilters */
    ImmutableSet.of(), /* shouldBuildStringSourceMap */
    false, /* shouldPreDex */
    false, BuildTargets.getScratchPath(originalParams.getProjectFilesystem(), target, "%s/classes.dex"), DexSplitMode.NO_SPLIT, /* buildRulesToExcludeFromDex */
    ImmutableSet.of(), /* resourcesToExclude */
    ImmutableSet.of(), /* skipCrunchPngs */
    false, /* includesVectorDrawables */
    false, ANDROID_JAVAC_OPTIONS, EnumSet.of(ExopackageMode.SECONDARY_DEX), /* buildConfigValues */
    BuildConfigFields.empty(), /* buildConfigValuesFiles */
    Optional.empty(), /* xzCompressionLevel */
    Optional.empty(), /* trimResourceIds */
    false, /* keepResourcePattern */
    Optional.empty(), /* nativePlatforms */
    ImmutableMap.of(), /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), /* nativeLibraryMergeCodeGenerator */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, MoreExecutors.newDirectExecutorService(), /* manifestEntries */
    ManifestEntries.empty(), CxxPlatformUtils.DEFAULT_CONFIG, new APKModuleGraph(TargetGraph.EMPTY, originalParams.getBuildTarget(), Optional.empty()), new DxConfig(FakeBuckConfig.builder().build()));
    graphEnhancer.createAdditionalBuildables();
    ResourcesFilter resourcesFilter = findRuleOfType(ruleResolver, ResourcesFilter.class);
    MoreAsserts.assertDepends("ResourcesFilter must depend on rules behind resources source paths", resourcesFilter, resourcesDep);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) RType(com.facebook.buck.android.aapt.RDotTxtEntry.RType) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule 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 3 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule 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 4 with FakeBuildRule

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

the class AndroidLibraryGraphEnhancerTest method testDummyRDotJavaRuleInheritsJavacOptionsDeps.

@Test
public void testDummyRDotJavaRuleInheritsJavacOptionsDeps() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule dep = new FakeBuildRule(BuildTargetFactory.newInstance("//:dep"), pathResolver);
    dep.setOutputFile("foo");
    resolver.addToIndex(dep);
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    JavacOptions options = JavacOptions.builder().setSourceLevel("5").setTargetLevel("5").setJavacJarPath(dep.getSourcePathToOutput()).build();
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(target, new FakeBuildRuleParamsBuilder(target).build(), options, DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
    false, /* unionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), false);
    Optional<DummyRDotJava> result = graphEnhancer.getBuildableForAndroidResources(resolver, /* createdBuildableIfEmptyDeps */
    true);
    assertTrue(result.isPresent());
    assertThat(result.get().getDeps(), Matchers.<BuildRule>hasItem(dep));
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) 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 5 with FakeBuildRule

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

the class NdkLibraryDescriptionTest method transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule.

@Test
public void transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule transitiveInput = resolver.addToIndex(new FakeBuildRule("//:transitive_input", pathResolver));
    transitiveInput.setOutputFile("out");
    FakeNativeLinkable transitiveDep = resolver.addToIndex(new FakeNativeLinkable("//:transitive_dep", pathResolver, transitiveInput.getSourcePathToOutput()));
    FakeBuildRule firstOrderInput = resolver.addToIndex(new FakeBuildRule("//:first_order_input", pathResolver));
    firstOrderInput.setOutputFile("out");
    FakeNativeLinkable firstOrderDep = resolver.addToIndex(new FakeNativeLinkable("//:first_order_dep", pathResolver, firstOrderInput.getSourcePathToOutput(), transitiveDep));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule ndkLibrary = new NdkLibraryBuilder(target).addDep(firstOrderDep.getBuildTarget()).build(resolver);
    assertThat(ndkLibrary.getDeps(), Matchers.allOf(Matchers.<BuildRule>hasItem(firstOrderInput), Matchers.<BuildRule>hasItem(transitiveInput)));
}
Also used : 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)

Aggregations

FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)48 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)46 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)46 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)44 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)43 Test (org.junit.Test)43 BuildTarget (com.facebook.buck.model.BuildTarget)34 BuildRule (com.facebook.buck.rules.BuildRule)24 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)14 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 RuleKey (com.facebook.buck.rules.RuleKey)11 SourcePath (com.facebook.buck.rules.SourcePath)10 BuildRuleEvent (com.facebook.buck.rules.BuildRuleEvent)9 BuckEventBus (com.facebook.buck.event.BuckEventBus)8 BuildEvent (com.facebook.buck.rules.BuildEvent)8 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)8 Clock (com.facebook.buck.timing.Clock)8 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 ParseEvent (com.facebook.buck.parser.ParseEvent)7