Search in sources :

Example 36 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidExopackageBinaryIntegrationTest method testDexExopackageHasNoSecondary.

@Test
public void testDexExopackageHasNoSecondary() throws IOException {
    ZipInspector zipInspector = new ZipInspector(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(DEX_EXOPACKAGE_TARGET), "%s.apk")));
    zipInspector.assertFileDoesNotExist("assets/secondary-program-dex-jars/metadata.txt");
    zipInspector.assertFileDoesNotExist("assets/secondary-program-dex-jars/secondary-1.dex.jar");
    zipInspector.assertFileDoesNotExist("classes2.dex");
    zipInspector.assertFileExists("classes.dex");
    zipInspector.assertFileExists("lib/armeabi/libfakenative.so");
    // It would be better if we could call getExopackageInfo on the app rule.
    Path secondaryDir = workspace.resolve(BuildTargets.getScratchPath(filesystem, BuildTargetFactory.newInstance(DEX_EXOPACKAGE_TARGET).withFlavors(InternalFlavor.of("dex_merge")), "_%s_output/jarfiles/assets/secondary-program-dex-jars"));
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(secondaryDir)) {
        List<Path> files = Lists.newArrayList(stream);
        assertEquals(2, files.size());
        Collections.sort(files);
        Path secondaryJar = files.get(0);
        ZipInspector zi = new ZipInspector(secondaryJar);
        zi.assertFileExists("classes.dex");
        long jarSize = Files.size(secondaryJar);
        long classesDexSize = zi.getSize("classes.dex");
        Path dexMeta = files.get(1);
        assertEquals(String.format("jar:%s dex:%s", jarSize, classesDexSize), new String(Files.readAllBytes(dexMeta), "US-ASCII"));
    }
}
Also used : Path(java.nio.file.Path) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 37 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidInstrumentationApkIntegrationTest method testCxxLibraryDep.

@Test
public void testCxxLibraryDep() throws IOException {
    AssumeAndroidPlatform.assumeSdkIsAvailable();
    AssumeAndroidPlatform.assumeNdkIsAvailable();
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "android_instrumentation_apk_integration_test", tmpFolder);
    workspace.setUp();
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
    String target = "//:app_cxx_lib_dep";
    workspace.runBuckCommand("build", target).assertSuccess();
    ZipInspector zipInspector = new ZipInspector(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk")));
    zipInspector.assertFileExists("lib/armeabi/libcxx.so");
    zipInspector.assertFileExists("lib/armeabi/libgnustl_shared.so");
    zipInspector.assertFileExists("lib/armeabi-v7a/libcxx.so");
    zipInspector.assertFileExists("lib/armeabi-v7a/libgnustl_shared.so");
    zipInspector.assertFileExists("lib/x86/libcxx.so");
    zipInspector.assertFileExists("lib/x86/libgnustl_shared.so");
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 38 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidBinaryIntegrationTest method testHeaderOnlyCxxLibrary.

@Test
public void testHeaderOnlyCxxLibrary() throws IOException {
    String target = "//apps/sample:app_header_only_cxx_lib_dep";
    workspace.runBuckCommand("build", target).assertSuccess();
    ZipInspector zipInspector = new ZipInspector(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk")));
    zipInspector.assertFileDoesNotExist("lib/x86/libnative_cxx_headeronly.so");
}
Also used : ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 39 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidBinaryIntegrationTest method testCompressAssetLibsModular.

@Test
public void testCompressAssetLibsModular() throws IOException {
    String target = "//apps/sample:app_compress_lib_asset_modular";
    workspace.runBuckCommand("build", target).assertSuccess();
    ZipInspector zipInspector = new ZipInspector(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk")));
    zipInspector.assertFileExists("assets/lib/libs.xzs");
    zipInspector.assertFileExists("assets/lib/metadata.txt");
    zipInspector.assertFileExists("assets/native.cxx.libasset/libs.xzs");
    zipInspector.assertFileExists("assets/native.cxx.libasset/libs.txt");
    zipInspector.assertFileDoesNotExist("assets/lib/x86/libnative_cxx_libasset.so");
    zipInspector.assertFileDoesNotExist("lib/x86/libnative_cxx_libasset.so");
    zipInspector.assertFileExists("lib/x86/libnative_cxx_foo1.so");
    zipInspector.assertFileExists("lib/x86/libnative_cxx_foo2.so");
    zipInspector.assertFileDoesNotExist("assets/lib/x86/libnative_cxx_foo1.so");
    zipInspector.assertFileDoesNotExist("assets/lib/x86/libnative_cxx_foo2.so");
}
Also used : ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 40 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidBinaryIntegrationTest method testNativeLibraryCrossCellMerging.

@Test
public void testNativeLibraryCrossCellMerging() throws IOException, InterruptedException {
    // Set up a cross-cell workspace
    ProjectWorkspace secondary = TestDataHelper.createProjectWorkspaceForScenario(new AndroidBinaryIntegrationTest(), "android_project/secondary", secondaryFolder);
    secondary.setUp();
    NdkCxxPlatform platform = AndroidNdkHelper.getNdkCxxPlatform(workspace, filesystem);
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Path tmpDir = tmpFolder.newFolder("merging_tmp");
    SymbolGetter syms = new SymbolGetter(new DefaultProcessExecutor(new TestConsole()), tmpDir, platform.getObjdump(), pathResolver);
    SymbolsAndDtNeeded info;
    TestDataHelper.overrideBuckconfig(workspace, ImmutableMap.of("ndk", ImmutableMap.of("cpu_abis", "x86"), "repositories", ImmutableMap.of("secondary", secondary.getPath(".").normalize().toString())));
    workspace.replaceFileContents(workspace.getPath("apps/sample/BUCK").normalize().toString(), "#'secondary//merge:G'", "'secondary//merge:G'");
    Path apkPath = workspace.buildAndReturnOutput("//apps/sample:app_with_merged_cross_cell_libs");
    ZipInspector zipInspector = new ZipInspector(apkPath);
    zipInspector.assertFileDoesNotExist("lib/x86/lib1a.so");
    zipInspector.assertFileDoesNotExist("lib/x86/lib1b.so");
    zipInspector.assertFileDoesNotExist("lib/x86/lib1g.so");
    zipInspector.assertFileDoesNotExist("lib/x86/lib1h.so");
    info = syms.getSymbolsAndDtNeeded(apkPath, "lib/x86/lib1.so");
    assertThat(info.symbols.global, Matchers.hasItem("A"));
    assertThat(info.symbols.global, Matchers.hasItem("B"));
    assertThat(info.symbols.global, Matchers.hasItem("G"));
    assertThat(info.symbols.global, Matchers.hasItem("H"));
    assertThat(info.symbols.global, Matchers.hasItem("glue_1"));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_2")));
    assertThat(info.dtNeeded, not(Matchers.hasItem("libnative_merge_B.so")));
    assertThat(info.dtNeeded, not(Matchers.hasItem("libmerge_G.so")));
    assertThat(info.dtNeeded, not(Matchers.hasItem("libmerge_H.so")));
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) SymbolsAndDtNeeded(com.facebook.buck.android.AndroidNdkHelper.SymbolsAndDtNeeded) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) SymbolGetter(com.facebook.buck.android.AndroidNdkHelper.SymbolGetter) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)63 Test (org.junit.Test)62 Path (java.nio.file.Path)34 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 BuildTarget (com.facebook.buck.model.BuildTarget)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 TestConsole (com.facebook.buck.testutil.TestConsole)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)3 Clock (com.facebook.buck.timing.Clock)3 DefaultClock (com.facebook.buck.timing.DefaultClock)3 SymbolGetter (com.facebook.buck.android.AndroidNdkHelper.SymbolGetter)2 SymbolsAndDtNeeded (com.facebook.buck.android.AndroidNdkHelper.SymbolsAndDtNeeded)2 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2