| // Copyright (c) 2017, 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; |
| |
| import com.android.tools.r8.ToolHelper.DexVm; |
| import com.android.tools.r8.utils.AndroidApiLevel; |
| import com.google.common.collect.ImmutableList; |
| import com.google.common.collect.ImmutableMap; |
| import java.nio.file.Path; |
| import java.nio.file.Paths; |
| import java.util.List; |
| import java.util.Map; |
| import java.util.concurrent.ExecutionException; |
| import java.util.function.UnaryOperator; |
| import org.junit.Test; |
| |
| public class R8RunExamplesAndroidPTest extends RunExamplesAndroidPTest<R8Command.Builder> { |
| |
| private static Map<DexVm.Version, List<String>> alsoFailsOn = |
| ImmutableMap.of( |
| DexVm.Version.V4_4_4, ImmutableList.of( |
| "invokecustom-with-shrinking" |
| ), |
| DexVm.Version.V5_1_1, ImmutableList.of( |
| "invokecustom-with-shrinking" |
| ), |
| DexVm.Version.V6_0_1, ImmutableList.of( |
| "invokecustom-with-shrinking" |
| ), |
| DexVm.Version.V7_0_0, ImmutableList.of( |
| "invokecustom-with-shrinking" |
| ), |
| DexVm.Version.DEFAULT, ImmutableList.of( |
| ) |
| ); |
| |
| @Test |
| public void invokeCustomWithShrinking() throws Throwable { |
| test("invokecustom-with-shrinking", "invokecustom", "InvokeCustom") |
| .withMinApiLevel(AndroidApiLevel.P.getLevel()) |
| .withBuilderTransformation(builder -> |
| builder.addProguardConfigurationFiles( |
| Paths.get(ToolHelper.EXAMPLES_ANDROID_P_DIR, "invokecustom/keep-rules.txt"))) |
| .run(); |
| } |
| |
| class R8TestRunner extends TestRunner<R8TestRunner> { |
| |
| R8TestRunner(String testName, String packageName, String mainClass) { |
| super(testName, packageName, mainClass); |
| } |
| |
| @Override |
| R8TestRunner withMinApiLevel(int minApiLevel) { |
| return withBuilderTransformation(builder -> builder.setMinApiLevel(minApiLevel)); |
| } |
| |
| @Override |
| void build(Path inputFile, Path out) throws Throwable { |
| try { |
| R8Command.Builder builder = R8Command.builder(); |
| for (UnaryOperator<R8Command.Builder> transformation : builderTransformations) { |
| builder = transformation.apply(builder); |
| } |
| // TODO(mikaelpeltier) Add new android.jar build from aosp and use it |
| builder.addLibraryFiles(Paths.get(ToolHelper.getAndroidJar(AndroidApiLevel.O.getLevel()))); |
| R8Command command = builder.addProgramFiles(inputFile).setOutputPath(out).build(); |
| ToolHelper.runR8(command, this::combinedOptionConsumer); |
| } catch (ExecutionException e) { |
| throw e.getCause(); |
| } |
| } |
| |
| @Override |
| R8TestRunner self() { |
| return this; |
| } |
| } |
| |
| @Override |
| R8TestRunner test(String testName, String packageName, String mainClass) { |
| return new R8TestRunner(testName, packageName, mainClass); |
| } |
| |
| @Override |
| boolean expectedToFail(String name) { |
| return super.expectedToFail(name) || failsOn(alsoFailsOn, name); |
| } |
| } |