use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidBinaryIntegrationTest method testDxFindsReferencedResources.
@Test
public void testDxFindsReferencedResources() throws IOException {
DefaultOnDiskBuildInfo buildInfo = new DefaultOnDiskBuildInfo(BuildTargetFactory.newInstance("//java/com/sample/lib:lib#dex"), new ProjectFilesystem(tmpFolder.getRoot()), ObjectMappers.newDefaultInstance());
Optional<ImmutableList<String>> resourcesFromMetadata = buildInfo.getValues(DexProducedFromJavaLibrary.REFERENCED_RESOURCES);
assertTrue(resourcesFromMetadata.isPresent());
assertEquals(ImmutableSet.of("com.sample.top_layout", "com.sample2.title"), ImmutableSet.copyOf(resourcesFromMetadata.get()));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AaptPackageResourcesIntegrationTest method testEditingLayoutChangesPackageHash.
@Test
public void testEditingLayoutChangesPackageHash() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
// This is too low-level of a test. Ideally, we'd be able to save the rule graph generated
// by the build and query it directly, but runBuckCommand doesn't support that, so just
// test the files directly for now.
Path pathRelativeToProjectRoot = BuildInfo.getPathToMetadataDirectory(BuildTargetFactory.newInstance("//apps/sample:app#aapt_package"), new ProjectFilesystem(workspace.getDestPath())).resolve(AaptPackageResources.RESOURCE_PACKAGE_HASH_KEY);
String firstHash = workspace.getFileContents(pathRelativeToProjectRoot);
workspace.replaceFileContents(PATH_TO_LAYOUT_XML, "white", "black");
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
String secondHash = workspace.getFileContents(pathRelativeToProjectRoot);
Sha1HashCode firstHashCode = Sha1HashCode.of(firstHash);
Sha1HashCode secondHashCode = Sha1HashCode.of(secondHash);
assertNotEquals(firstHashCode, secondHashCode);
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidExopackageBinaryIntegrationTest method setUp.
@Before
public void setUp() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
AssumeAndroidPlatform.assumeNdkIsAvailable();
workspace = TestDataHelper.createProjectWorkspaceForScenario(new AndroidBinaryIntegrationTest(), "android_project", tmpFolder);
workspace.setUp();
Properties properties = System.getProperties();
properties.setProperty("buck.native_exopackage_fake_path", Paths.get("assets/android/native-exopackage-fakes.apk").toAbsolutePath().toString());
workspace.runBuckBuild(DEX_EXOPACKAGE_TARGET, NATIVE_EXOPACKAGE_TARGET, DEX_AND_NATIVE_EXOPACKAGE_TARGET).assertSuccess();
filesystem = new ProjectFilesystem(workspace.getDestPath());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidPackageableCollectorTest method testFindTransitiveDependencies.
/**
* This is a regression test to ensure that an additional 1 second startup cost is not
* re-introduced to fb4a.
*/
@Test
public void testFindTransitiveDependencies() throws Exception {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
Path prebuiltNativeLibraryPath = Paths.get("java/com/facebook/prebuilt_native_library/libs");
projectFilesystem.mkdirs(prebuiltNativeLibraryPath);
// Create an AndroidBinaryRule that transitively depends on two prebuilt JARs. One of the two
// prebuilt JARs will be listed in the AndroidBinaryRule's no_dx list.
BuildTarget guavaTarget = BuildTargetFactory.newInstance("//third_party/guava:guava");
TargetNode<?, ?> guava = PrebuiltJarBuilder.createBuilder(guavaTarget).setBinaryJar(Paths.get("third_party/guava/guava-10.0.1.jar")).build();
BuildTarget jsr305Target = BuildTargetFactory.newInstance("//third_party/jsr-305:jsr-305");
TargetNode<?, ?> jsr = PrebuiltJarBuilder.createBuilder(jsr305Target).setBinaryJar(Paths.get("third_party/jsr-305/jsr305.jar")).build();
TargetNode<?, ?> ndkLibrary = new NdkLibraryBuilder(BuildTargetFactory.newInstance("//java/com/facebook/native_library:library"), projectFilesystem).build();
BuildTarget prebuiltNativeLibraryTarget = BuildTargetFactory.newInstance("//java/com/facebook/prebuilt_native_library:library");
TargetNode<?, ?> prebuiltNativeLibraryBuild = PrebuiltNativeLibraryBuilder.newBuilder(prebuiltNativeLibraryTarget, projectFilesystem).setNativeLibs(prebuiltNativeLibraryPath).setIsAsset(true).build();
BuildTarget libraryRuleTarget = BuildTargetFactory.newInstance("//java/src/com/facebook:example");
TargetNode<?, ?> library = JavaLibraryBuilder.createBuilder(libraryRuleTarget).setProguardConfig(new FakeSourcePath("debug.pro")).addSrc(Paths.get("Example.java")).addDep(guavaTarget).addDep(jsr305Target).addDep(prebuiltNativeLibraryBuild.getBuildTarget()).addDep(ndkLibrary.getBuildTarget()).build();
BuildTarget manifestTarget = BuildTargetFactory.newInstance("//java/src/com/facebook:res");
TargetNode<?, ?> manifest = AndroidResourceBuilder.createBuilder(manifestTarget).setManifest(new PathSourcePath(projectFilesystem, Paths.get("java/src/com/facebook/module/AndroidManifest.xml"))).setAssets(new FakeSourcePath("assets")).build();
BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//keystore:debug");
TargetNode<?, ?> keystore = KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath(projectFilesystem, "keystore/debug.keystore")).setProperties(new FakeSourcePath(projectFilesystem, "keystore/debug.keystore.properties")).build();
ImmutableSortedSet<BuildTarget> originalDepsTargets = ImmutableSortedSet.of(libraryRuleTarget, manifestTarget);
BuildTarget binaryTarget = BuildTargetFactory.newInstance("//java/src/com/facebook:app");
TargetNode<?, ?> binary = AndroidBinaryBuilder.createBuilder(binaryTarget).setOriginalDeps(originalDepsTargets).setBuildTargetsToExcludeFromDex(ImmutableSet.of(BuildTargetFactory.newInstance("//third_party/guava:guava"))).setManifest(new FakeSourcePath("java/src/com/facebook/AndroidManifest.xml")).setKeystore(keystoreTarget).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(binary, library, manifest, keystore, ndkLibrary, prebuiltNativeLibraryBuild, guava, jsr);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
AndroidBinary binaryRule = (AndroidBinary) ruleResolver.requireRule(binaryTarget);
NdkLibrary ndkLibraryRule = (NdkLibrary) ruleResolver.requireRule(ndkLibrary.getBuildTarget());
NativeLibraryBuildRule prebuildNativeLibraryRule = (NativeLibraryBuildRule) ruleResolver.requireRule(prebuiltNativeLibraryTarget);
// Verify that the correct transitive dependencies are found.
AndroidPackageableCollection packageableCollection = binaryRule.getAndroidPackageableCollection();
assertResolvedEquals("Because guava was passed to no_dx, it should not be in the classpathEntriesToDex list", pathResolver, ImmutableSet.of(ruleResolver.getRule(jsr305Target).getSourcePathToOutput(), ruleResolver.getRule(libraryRuleTarget).getSourcePathToOutput()), packageableCollection.getClasspathEntriesToDex());
assertResolvedEquals("Because guava was passed to no_dx, it should not be treated as a third-party JAR whose " + "resources need to be extracted and repacked in the APK. If this is done, then code " + "in the guava-10.0.1.dex.1.jar in the APK's assets/ tmp may try to load the resource " + "from the APK as a ZipFileEntry rather than as a resource within " + "guava-10.0.1.dex.1.jar. Loading a resource in this way could take substantially " + "longer. Specifically, this was observed to take over one second longer to load " + "the resource in fb4a. Because the resource was loaded on startup, this introduced a " + "substantial regression in the startup time for the fb4a app.", pathResolver, ImmutableSet.of(ruleResolver.getRule(jsr305Target).getSourcePathToOutput()), packageableCollection.getPathsToThirdPartyJars());
assertResolvedEquals("Because assets directory was passed an AndroidResourceRule it should be added to the " + "transitive dependencies", pathResolver, ImmutableSet.of(new DefaultBuildTargetSourcePath(manifestTarget.withAppendedFlavors(AndroidResourceDescription.ASSETS_SYMLINK_TREE_FLAVOR))), packageableCollection.getAssetsDirectories());
assertResolvedEquals("Because a native library was declared as a dependency, it should be added to the " + "transitive dependencies.", pathResolver, ImmutableSet.<SourcePath>of(new PathSourcePath(new FakeProjectFilesystem(), ndkLibraryRule.getLibraryPath())), ImmutableSet.copyOf(packageableCollection.getNativeLibsDirectories().values()));
assertResolvedEquals("Because a prebuilt native library was declared as a dependency (and asset), it should " + "be added to the transitive dependecies.", pathResolver, ImmutableSet.<SourcePath>of(new PathSourcePath(new FakeProjectFilesystem(), prebuildNativeLibraryRule.getLibraryPath())), ImmutableSet.copyOf(packageableCollection.getNativeLibAssetsDirectories().values()));
assertEquals(ImmutableSet.of(new FakeSourcePath("debug.pro")), packageableCollection.getProguardConfigs());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class AndroidPrebuiltAarIntegrationTest method testBuildAndroidPrebuiltAar.
@Test
public void testBuildAndroidPrebuiltAar() throws IOException {
String target = "//:app";
workspace.runBuckBuild(target).assertSuccess();
ZipInspector zipInspector = new ZipInspector(workspace.getPath(BuildTargets.getGenPath(new ProjectFilesystem(workspace.getDestPath()), BuildTargetFactory.newInstance(target), "%s.apk")));
zipInspector.assertFileExists("AndroidManifest.xml");
zipInspector.assertFileExists("resources.arsc");
zipInspector.assertFileExists("classes.dex");
zipInspector.assertFileExists("lib/x86/liba.so");
}
Aggregations