Search in sources :

Example 31 with SourcePathRuleFinder

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

the class AndroidResourceTest method testGetRDotJavaPackageWhenPackageIsNotSpecified.

@Test
public void testGetRDotJavaPackageWhenPackageIsNotSpecified() throws IOException {
    ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createRealTempFilesystem();
    BuildTarget buildTarget = BuildTargetFactory.newInstance(projectFilesystem, "//java/src/com/facebook/base:res");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(buildTarget).setProjectFilesystem(projectFilesystem).build();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    AndroidResource androidResource = new AndroidResource(params, ruleFinder, /* deps */
    ImmutableSortedSet.of(), new FakeSourcePath("foo/res"), ImmutableSortedMap.of(Paths.get("values/strings.xml"), new FakeSourcePath("foo/res/values/strings.xml")), /* rDotJavaPackage */
    null, /* assets */
    null, /* assetsSrcs */
    ImmutableSortedMap.of(), /* manifestFile */
    new PathSourcePath(projectFilesystem, Paths.get("foo/AndroidManifest.xml")), /* hasWhitelistedStrings */
    false);
    projectFilesystem.writeContentsToPath("com.ex.pkg\n", resolver.getRelativePath(androidResource.getPathToRDotJavaPackageFile()));
    FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo();
    androidResource.initializeFromDisk(onDiskBuildInfo);
    assertEquals("com.ex.pkg", androidResource.getRDotJavaPackage());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 32 with SourcePathRuleFinder

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

the class AndroidResourceTest method testInputRuleKeyChangesIfDependencySymbolsChanges.

@Test
public void testInputRuleKeyChangesIfDependencySymbolsChanges() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    TargetNode<?, ?> depNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).setManifest(new FakeSourcePath("manifest")).setRes(Paths.get("res")).build();
    TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:rule"), filesystem).setDeps(ImmutableSortedSet.of(depNode.getBuildTarget())).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, resourceNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    AndroidResource dep = (AndroidResource) resolver.requireRule(depNode.getBuildTarget());
    AndroidResource resource = (AndroidResource) resolver.requireRule(resourceNode.getBuildTarget());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getPathToTextSymbolsFile()));
    RuleKey original = new InputBasedRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(resource);
    fileHashCache.invalidateAll();
    filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getPathToTextSymbolsFile()));
    RuleKey changed = new InputBasedRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(resource);
    assertThat(original, Matchers.not(Matchers.equalTo(changed)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 33 with SourcePathRuleFinder

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

the class AndroidLibraryGraphEnhancerTest method testCreatedBuildableHasOverriddenJavacConfig.

@Test
public void testCreatedBuildableHasOverriddenJavacConfig() {
    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, JavacOptions.builder(ANDROID_JAVAC_OPTIONS).setAnnotationProcessingParams(new AnnotationProcessingParams.Builder().setProcessOnly(true).build()).setSourceLevel("7").setTargetLevel("7").build(), DependencyMode.FIRST_ORDER, /* forceFinalResourceIds */
    false, /* unionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), false);
    Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(ruleResolver, /* createBuildableIfEmptyDeps */
    false);
    assertTrue(dummyRDotJava.isPresent());
    JavacOptions javacOptions = dummyRDotJava.get().getJavacOptions();
    assertFalse(javacOptions.getAnnotationProcessingParams().getProcessOnly());
    assertEquals("7", javacOptions.getSourceLevel());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) JavacOptions(com.facebook.buck.jvm.java.JavacOptions) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) AnnotationProcessingParams(com.facebook.buck.jvm.java.AnnotationProcessingParams) Test(org.junit.Test)

Example 34 with SourcePathRuleFinder

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

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

the class AndroidNativeLibsPackageableGraphEnhancerTest method testNdkLibrary.

@Test
public void testNdkLibrary() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    NdkLibrary ndkLibrary = new NdkLibraryBuilder(BuildTargetFactory.newInstance("//:ndklib")).build(ruleResolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(ndkLibrary)).build();
    APKModuleGraph apkModuleGraph = new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty());
    AndroidNativeLibsPackageableGraphEnhancer enhancer = new AndroidNativeLibsPackageableGraphEnhancer(ruleResolver, originalParams, ImmutableMap.of(), ImmutableSet.of(), CxxPlatformUtils.DEFAULT_CONFIG, /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
    AndroidPackageableCollector collector = new AndroidPackageableCollector(target, ImmutableSet.of(), ImmutableSet.of(), apkModuleGraph);
    collector.addPackageables(AndroidPackageableCollector.getPackageableRules(ImmutableSet.of(ndkLibrary)));
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibrariesOptional = enhancer.enhance(collector.build()).getCopyNativeLibraries();
    CopyNativeLibraries copyNativeLibraries = copyNativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule());
    assertThat(copyNativeLibraries.getStrippedObjectDescriptions(), Matchers.empty());
    assertThat(copyNativeLibraries.getNativeLibDirectories().stream().map(sourcePathResolver::getRelativePath).collect(MoreCollectors.toImmutableList()), Matchers.contains(ndkLibrary.getLibraryPath()));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)517 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)466 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)405 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)376 Test (org.junit.Test)352 BuildTarget (com.facebook.buck.model.BuildTarget)250 BuildRule (com.facebook.buck.rules.BuildRule)188 SourcePath (com.facebook.buck.rules.SourcePath)151 Path (java.nio.file.Path)151 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)149 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)139 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)131 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)94 PathSourcePath (com.facebook.buck.rules.PathSourcePath)92 TargetGraph (com.facebook.buck.rules.TargetGraph)91 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)87 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)72 ImmutableList (com.google.common.collect.ImmutableList)52 ExecutionContext (com.facebook.buck.step.ExecutionContext)50