Search in sources :

Example 26 with ZipInspector

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

the class DefaultJavaLibraryIntegrationTest method testSaveClassFilesToDiskWithRemoveClasses.

@Test
public void testSaveClassFilesToDiskWithRemoveClasses() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "spool_class_files_to_disk_remove_classes", tmp);
    workspace.setUp();
    BuildTarget target = BuildTargetFactory.newInstance("//:a");
    ProcessResult result = workspace.runBuckBuild(target.getFullyQualifiedName());
    result.assertSuccess();
    Path classesDir = workspace.getPath(BuildTargets.getScratchPath(filesystem, target, "lib__%s__classes"));
    assertThat("Classes directory should exist.", Files.exists(classesDir), is(Boolean.TRUE));
    Path jarPath = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "lib__%s__output/a.jar"));
    assertTrue("Jar should exist.", Files.exists(jarPath));
    // Check that normal and member classes were removed as expected.
    ZipInspector zipInspector = new ZipInspector(jarPath);
    zipInspector.assertFileExists("test/pkg/A.class");
    zipInspector.assertFileExists("test/pkg/B.class");
    zipInspector.assertFileDoesNotExist("test/pkg/RemovableC.class");
    zipInspector.assertFileDoesNotExist("test/pkg/B$MemberD.class");
    zipInspector.assertFileDoesNotExist("DeletableB.class");
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 27 with ZipInspector

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

the class AndroidBinaryIntegrationTest method testCompressAssetLibs.

@Test
public void testCompressAssetLibs() throws IOException {
    String target = "//apps/sample:app_compress_lib_asset";
    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.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 28 with ZipInspector

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

the class AndroidBinaryIntegrationTest method testCxxLibraryAsAssetWithoutPackaging.

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

Example 29 with ZipInspector

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

the class AndroidBinaryIntegrationTest method testNativeLibraryMerging.

@Test
public void testNativeLibraryMerging() 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("merging_tmp");
    SymbolGetter syms = new SymbolGetter(new DefaultProcessExecutor(new TestConsole()), tmpDir, platform.getObjdump(), pathResolver);
    SymbolsAndDtNeeded info;
    workspace.replaceFileContents(".buckconfig", "#cpu_abis", "cpu_abis = x86");
    Map<String, Path> paths = workspace.buildMultipleAndReturnOutputs("//apps/sample:app_with_merged_libs", "//apps/sample:app_with_alternate_merge_glue", "//apps/sample:app_with_merged_libs_modular");
    Path apkPath = paths.get("//apps/sample:app_with_merged_libs");
    ZipInspector zipInspector = new ZipInspector(apkPath);
    zipInspector.assertFileDoesNotExist("lib/x86/lib1a.so");
    zipInspector.assertFileDoesNotExist("lib/x86/lib1b.so");
    zipInspector.assertFileDoesNotExist("lib/x86/lib2e.so");
    zipInspector.assertFileDoesNotExist("lib/x86/lib2f.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("glue_1"));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_2")));
    assertThat(info.dtNeeded, Matchers.hasItem("libnative_merge_C.so"));
    assertThat(info.dtNeeded, Matchers.hasItem("libnative_merge_D.so"));
    assertThat(info.dtNeeded, not(Matchers.hasItem("libnative_merge_B.so")));
    info = syms.getSymbolsAndDtNeeded(apkPath, "lib/x86/libnative_merge_C.so");
    assertThat(info.symbols.global, Matchers.hasItem("C"));
    assertThat(info.symbols.global, Matchers.hasItem("static_func_C"));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_1")));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_2")));
    assertThat(info.dtNeeded, Matchers.hasItem("libnative_merge_D.so"));
    assertThat(info.dtNeeded, Matchers.hasItem("libprebuilt_for_C.so"));
    info = syms.getSymbolsAndDtNeeded(apkPath, "lib/x86/libnative_merge_D.so");
    assertThat(info.symbols.global, Matchers.hasItem("D"));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_1")));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_2")));
    assertThat(info.dtNeeded, Matchers.hasItem("lib2.so"));
    assertThat(info.dtNeeded, not(Matchers.hasItem("libnative_merge_E.so")));
    assertThat(info.dtNeeded, not(Matchers.hasItem("libnative_merge_F.so")));
    info = syms.getSymbolsAndDtNeeded(apkPath, "lib/x86/lib2.so");
    assertThat(info.symbols.global, Matchers.hasItem("E"));
    assertThat(info.symbols.global, Matchers.hasItem("F"));
    assertThat(info.symbols.global, Matchers.hasItem("static_func_F"));
    assertThat(info.symbols.global, Matchers.hasItem("glue_1"));
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_2")));
    assertThat(info.dtNeeded, Matchers.hasItem("libprebuilt_for_F.so"));
    Path otherPath = paths.get("//apps/sample:app_with_alternate_merge_glue");
    info = syms.getSymbolsAndDtNeeded(otherPath, "lib/x86/lib2.so");
    assertThat(info.symbols.global, not(Matchers.hasItem("glue_1")));
    assertThat(info.symbols.global, Matchers.hasItem("glue_2"));
    assertThat(info.dtNeeded, Matchers.hasItem("libprebuilt_for_F.so"));
    Path modularPath = paths.get("//apps/sample:app_with_merged_libs_modular");
    ZipInspector modularZipInspector = new ZipInspector(modularPath);
    modularZipInspector.assertFileDoesNotExist("lib/x86/lib1a.so");
    modularZipInspector.assertFileDoesNotExist("lib/x86/lib1b.so");
    modularZipInspector.assertFileDoesNotExist("lib/x86/lib2e.so");
    modularZipInspector.assertFileDoesNotExist("lib/x86/lib2f.so");
    modularZipInspector.assertFileExists("assets/native.merge.A/libs.txt");
    modularZipInspector.assertFileExists("assets/native.merge.A/libs.xzs");
    modularZipInspector.assertFileDoesNotExist("lib/x86/lib1.so");
    modularZipInspector.assertFileDoesNotExist("lib/x86/lib2.so");
    Path disassembly = workspace.buildAndReturnOutput("//apps/sample:disassemble_app_with_merged_libs_gencode");
    List<String> disassembledLines = filesystem.readLines(disassembly);
    Pattern fieldPattern = Pattern.compile("^\\.field public static final ([^:]+):Ljava/lang/String; = \"([^\"]+)\"$");
    ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
    for (String line : disassembledLines) {
        Matcher m = fieldPattern.matcher(line);
        if (!m.matches()) {
            continue;
        }
        mapBuilder.put(m.group(1), m.group(2));
    }
    assertThat(mapBuilder.build(), Matchers.equalTo(ImmutableMap.of("lib1a_so", "lib1_so", "lib1b_so", "lib1_so", "lib2e_so", "lib2_so", "lib2f_so", "lib2_so")));
}
Also used : Path(java.nio.file.Path) Pattern(java.util.regex.Pattern) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) SymbolsAndDtNeeded(com.facebook.buck.android.AndroidNdkHelper.SymbolsAndDtNeeded) Matcher(java.util.regex.Matcher) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) SymbolGetter(com.facebook.buck.android.AndroidNdkHelper.SymbolGetter) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 30 with ZipInspector

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

the class AndroidBinaryIntegrationTest method testDisguisedExecutableIsRenamed.

@Test
public void testDisguisedExecutableIsRenamed() throws IOException {
    ZipInspector zipInspector = new ZipInspector(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(SIMPLE_TARGET), "%s.apk")));
    zipInspector.assertFileExists("lib/armeabi/libmybinary.so");
}
Also used : ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) 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