blob: 1f20559ba25f4f897b193868a8dd2b68abe4c2a0 [file] [log] [blame]
// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.internal;
import static com.android.tools.r8.utils.AndroidApp.DEFAULT_PROGUARD_MAP_FILE;
import com.android.tools.r8.CompilationException;
import com.android.tools.r8.R8;
import com.android.tools.r8.R8Command;
import com.android.tools.r8.shaking.ProguardRuleParserException;
import com.android.tools.r8.utils.FileUtils;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.experimental.theories.Theories;
import org.junit.runner.RunWith;
// Invoke R8 on the dex files extracted from GMSCore.apk to disassemble the dex code.
@RunWith(Theories.class)
public class R8DisassemblerTest {
static final String APP_DIR = "third_party/gmscore/v5/";
public boolean deobfuscate;
@Test
public void disassemble() throws IOException, ExecutionException, ProguardRuleParserException,
CompilationException {
// This test only ensures that we do not break disassembling of dex code. It does not
// check the generated code. To make it fast, we get rid of the output.
PrintStream originalOut = System.out;
System.setOut(new PrintStream(new OutputStream() {
public void write(int b) { /* ignore*/ }
}));
try {
R8Command.Builder builder = R8Command.builder();
if (deobfuscate) {
builder.setProguardMapFile(Paths.get(APP_DIR, DEFAULT_PROGUARD_MAP_FILE));
}
builder.addProgramFiles(
Files.list(Paths.get(APP_DIR))
.filter(FileUtils::isDexFile)
.collect(Collectors.toList()));
R8.disassemble(builder.build());
} finally {
// Restore System.out for good measure.
System.setOut(originalOut);
}
}
}