use of com.facebook.buck.rules.BuildRuleResolver in project buck by facebook.
the class AndroidBinaryGraphEnhancerTest method testPackageStringsDependsOnResourcesFilter.
@Test
public void testPackageStringsDependsOnResourcesFilter() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
// set it up.
BuildTarget target = BuildTargetFactory.newInstance("//:target");
BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).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);
PackageStringAssets packageStringAssetsRule = findRuleOfType(ruleResolver, PackageStringAssets.class);
MoreAsserts.assertDepends("PackageStringAssets must depend on AaptPackageResources", packageStringAssetsRule, resourcesFilter);
}
use of com.facebook.buck.rules.BuildRuleResolver in project buck by facebook.
the class AndroidBinaryGraphEnhancerTest method testCreateDepsForPreDexing.
@Test
public void testCreateDepsForPreDexing() throws Exception {
// Create three Java rules, :dep1, :dep2, and :lib. :lib depends on :dep1 and :dep2.
BuildTarget javaDep1BuildTarget = BuildTargetFactory.newInstance("//java/com/example:dep1");
TargetNode<?, ?> javaDep1Node = JavaLibraryBuilder.createBuilder(javaDep1BuildTarget).addSrc(Paths.get("java/com/example/Dep1.java")).build();
BuildTarget javaDep2BuildTarget = BuildTargetFactory.newInstance("//java/com/example:dep2");
TargetNode<?, ?> javaDep2Node = JavaLibraryBuilder.createBuilder(javaDep2BuildTarget).addSrc(Paths.get("java/com/example/Dep2.java")).build();
BuildTarget javaLibBuildTarget = BuildTargetFactory.newInstance("//java/com/example:lib");
TargetNode<?, ?> javaLibNode = JavaLibraryBuilder.createBuilder(javaLibBuildTarget).addSrc(Paths.get("java/com/example/Lib.java")).addDep(javaDep1Node.getBuildTarget()).addDep(javaDep2Node.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(javaDep1Node, javaDep2Node, javaLibNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
BuildRule javaDep1 = ruleResolver.requireRule(javaDep1BuildTarget);
BuildRule javaDep2 = ruleResolver.requireRule(javaDep2BuildTarget);
BuildRule javaLib = ruleResolver.requireRule(javaLibBuildTarget);
// Assume we are enhancing an android_binary rule whose only dep
// is //java/com/example:lib, and that //java/com/example:dep2 is in its no_dx list.
ImmutableSortedSet<BuildRule> originalDeps = ImmutableSortedSet.of(javaLib);
ImmutableSet<BuildTarget> buildRulesToExcludeFromDex = ImmutableSet.of(javaDep2BuildTarget);
BuildTarget apkTarget = BuildTargetFactory.newInstance("//java/com/example:apk");
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleParams originalParams = new BuildRuleParams(apkTarget, Suppliers.ofInstance(originalDeps), Suppliers.ofInstance(originalDeps), filesystem, TestCellBuilder.createCellRoots(filesystem));
AndroidBinaryGraphEnhancer graphEnhancer = new AndroidBinaryGraphEnhancer(originalParams, ruleResolver, ResourcesFilter.ResourceCompressionMode.DISABLED, FilterResourcesStep.ResourceFilter.EMPTY_FILTER, /* bannedDuplicateResourceTypes */
EnumSet.noneOf(RType.class), Optional.empty(), /* locales */
ImmutableSet.of(), createStrictMock(PathSourcePath.class), AndroidBinary.PackageType.DEBUG, /* cpuFilters */
ImmutableSet.of(), /* shouldBuildStringSourceMap */
false, /* shouldPreDex */
true, BuildTargets.getScratchPath(originalParams.getProjectFilesystem(), apkTarget, "%s/classes.dex"), DexSplitMode.NO_SPLIT, buildRulesToExcludeFromDex, /* resourcesToExclude */
ImmutableSet.of(), /* skipCrunchPngs */
false, /* includesVectorDrawables */
false, ANDROID_JAVAC_OPTIONS, EnumSet.noneOf(ExopackageMode.class), /* buildConfigValues */
BuildConfigFields.empty(), /* buildConfigValuesFile */
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()));
BuildTarget aaptPackageResourcesTarget = BuildTargetFactory.newInstance("//java/com/example:apk#aapt_package");
BuildRuleParams aaptPackageResourcesParams = new FakeBuildRuleParamsBuilder(aaptPackageResourcesTarget).build();
AaptPackageResources aaptPackageResources = new AaptPackageResources(aaptPackageResourcesParams, ruleFinder, ruleResolver, /* manifest */
new FakeSourcePath("java/src/com/facebook/base/AndroidManifest.xml"), new IdentityResourcesProvider(ImmutableList.of()), ImmutableList.of(), ImmutableSortedSet.of(), ImmutableSet.of(), /* resourceUnionPackage */
Optional.empty(), false, /* skipCrunchPngs */
false, /* includesVectorDrawables */
false, /* bannedDuplicateResourceTypes */
EnumSet.noneOf(RType.class), /* manifestEntries */
ManifestEntries.empty());
ruleResolver.addToIndex(aaptPackageResources);
AndroidPackageableCollection collection = new AndroidPackageableCollector(/* collectionRoot */
apkTarget, ImmutableSet.of(javaDep2BuildTarget), /* resourcesToExclude */
ImmutableSet.of(), new APKModuleGraph(TargetGraph.EMPTY, apkTarget, Optional.empty())).addClasspathEntry(((HasJavaClassHashes) javaDep1), new FakeSourcePath("ignored")).addClasspathEntry(((HasJavaClassHashes) javaDep2), new FakeSourcePath("ignored")).addClasspathEntry(((HasJavaClassHashes) javaLib), new FakeSourcePath("ignored")).build();
ImmutableMultimap<APKModule, DexProducedFromJavaLibrary> preDexedLibraries = graphEnhancer.createPreDexRulesForLibraries(/* additionalJavaLibrariesToDex */
ImmutableList.of(), collection);
BuildTarget fakeUberRDotJavaCompileTarget = BuildTargetFactory.newInstance("//fake:uber_r_dot_java#compile");
JavaLibrary fakeUberRDotJavaCompile = JavaLibraryBuilder.createBuilder(fakeUberRDotJavaCompileTarget).build(ruleResolver);
BuildTarget fakeUberRDotJavaDexTarget = BuildTargetFactory.newInstance("//fake:uber_r_dot_java#dex");
DexProducedFromJavaLibrary fakeUberRDotJavaDex = new DexProducedFromJavaLibrary(new FakeBuildRuleParamsBuilder(fakeUberRDotJavaDexTarget).build(), fakeUberRDotJavaCompile);
ruleResolver.addToIndex(fakeUberRDotJavaDex);
BuildRule preDexMergeRule = graphEnhancer.createPreDexMergeRule(preDexedLibraries, fakeUberRDotJavaDex);
BuildTarget dexMergeTarget = BuildTargetFactory.newInstance("//java/com/example:apk#dex_merge");
BuildRule dexMergeRule = ruleResolver.getRule(dexMergeTarget);
assertEquals(dexMergeRule, preDexMergeRule);
BuildTarget javaDep1DexBuildTarget = BuildTarget.builder(javaDep1BuildTarget).addFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR).build();
BuildTarget javaDep2DexBuildTarget = BuildTarget.builder(javaDep2BuildTarget).addFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR).build();
BuildTarget javaLibDexBuildTarget = BuildTarget.builder(javaLibBuildTarget).addFlavors(AndroidBinaryGraphEnhancer.DEX_FLAVOR).build();
assertThat("There should be a #dex rule for dep1 and lib, but not dep2 because it is in the no_dx " + "list. And we should depend on uber_r_dot_java", Iterables.transform(dexMergeRule.getDeps(), BuildRule::getBuildTarget), Matchers.allOf(Matchers.not(Matchers.hasItem(javaDep1BuildTarget)), Matchers.hasItem(javaDep1DexBuildTarget), Matchers.not(Matchers.hasItem(javaDep2BuildTarget)), Matchers.not(Matchers.hasItem(javaDep2DexBuildTarget)), Matchers.hasItem(javaLibDexBuildTarget), Matchers.hasItem(fakeUberRDotJavaDex.getBuildTarget())));
}
use of com.facebook.buck.rules.BuildRuleResolver 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);
}
use of com.facebook.buck.rules.BuildRuleResolver in project buck by facebook.
the class AndroidBinaryIntegrationTest method testNativeRelinker.
@Test
public void testNativeRelinker() throws IOException, InterruptedException {
NdkCxxPlatform platform = AndroidNdkHelper.getNdkCxxPlatform(workspace, filesystem);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
Path tmpDir = tmpFolder.newFolder("xdso");
SymbolGetter syms = new SymbolGetter(new DefaultProcessExecutor(new TestConsole()), tmpDir, platform.getObjdump(), pathResolver);
Symbols sym;
Path apkPath = workspace.buildAndReturnOutput("//apps/sample:app_xdso_dce");
sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_top.so");
assertTrue(sym.global.contains("_Z10JNI_OnLoadii"));
assertTrue(sym.undefined.contains("_Z10midFromTopi"));
assertTrue(sym.undefined.contains("_Z10botFromTopi"));
assertFalse(sym.all.contains("_Z6unusedi"));
sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_mid.so");
assertTrue(sym.global.contains("_Z10midFromTopi"));
assertTrue(sym.undefined.contains("_Z10botFromMidi"));
assertFalse(sym.all.contains("_Z6unusedi"));
sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_bot.so");
assertTrue(sym.global.contains("_Z10botFromTopi"));
assertTrue(sym.global.contains("_Z10botFromMidi"));
assertFalse(sym.all.contains("_Z6unusedi"));
// Run some verification on the same apk with native_relinker disabled.
apkPath = workspace.buildAndReturnOutput("//apps/sample:app_no_xdso_dce");
sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_top.so");
assertTrue(sym.all.contains("_Z6unusedi"));
sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_mid.so");
assertTrue(sym.all.contains("_Z6unusedi"));
sym = syms.getSymbols(apkPath, "lib/x86/libnative_xdsodce_bot.so");
assertTrue(sym.all.contains("_Z6unusedi"));
}
use of com.facebook.buck.rules.BuildRuleResolver in project buck by facebook.
the class AndroidBinaryTest method testGetUnsignedApkPath.
@Test
public void testGetUnsignedApkPath() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
Keystore keystore = addKeystoreRule(ruleResolver);
BuildTarget targetInRootDirectory = BuildTargetFactory.newInstance("//:fb4a");
AndroidBinary ruleInRootDirectory = AndroidBinaryBuilder.createBuilder(targetInRootDirectory).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(keystore.getBuildTarget()).build(ruleResolver);
assertEquals(BuildTargets.getGenPath(ruleInRootDirectory.getProjectFilesystem(), targetInRootDirectory, "%s.apk"), pathResolver.getRelativePath(ruleInRootDirectory.getApkInfo().getApkPath()));
BuildTarget targetInNonRootDirectory = BuildTargetFactory.newInstance("//java/com/example:fb4a");
AndroidBinary ruleInNonRootDirectory = AndroidBinaryBuilder.createBuilder(targetInNonRootDirectory).setManifest(new FakeSourcePath("AndroidManifest.xml")).setKeystore(keystore.getBuildTarget()).build(ruleResolver);
assertEquals(BuildTargets.getGenPath(ruleInNonRootDirectory.getProjectFilesystem(), targetInNonRootDirectory, "%s.apk"), pathResolver.getRelativePath(ruleInNonRootDirectory.getApkInfo().getApkPath()));
}
Aggregations