• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 package com.android.tools.r8.dex;
5 
6 import com.android.tools.r8.CompilationException;
7 import com.android.tools.r8.R8Command;
8 import com.android.tools.r8.ToolHelper;
9 import com.android.tools.r8.shaking.ProguardRuleParserException;
10 import com.google.common.collect.ImmutableList;
11 import java.io.IOException;
12 import java.nio.file.Files;
13 import java.nio.file.Path;
14 import java.nio.file.Paths;
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.concurrent.ExecutionException;
18 import org.junit.Assert;
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.rules.TemporaryFolder;
22 
23 public class ExtraFileTest {
24 
25   private static final String EXAMPLE_DIR = ToolHelper.EXAMPLES_BUILD_DIR;
26   private static final String EXAMPLE_DEX = "memberrebinding/classes.dex";
27   private static final String EXAMPLE_LIB = "memberrebindinglib/classes.dex";
28   private static final String EXAMPLE_CLASS = "memberrebinding.Memberrebinding";
29   private static final String EXAMPLE_PACKAGE_MAP = "memberrebinding/package.map";
30   private static final String EXAMPLE_PROGUARD_MAP = "memberrebinding/proguard.map";
31 
32   @Rule
33   public TemporaryFolder temp = ToolHelper.getTemporaryFolderForTest();
34 
35   @Test
splitMemberRebindingTwoFiles()36   public void splitMemberRebindingTwoFiles()
37       throws IOException, ProguardRuleParserException, ExecutionException, CompilationException {
38     if (!ToolHelper.artSupported()) {
39       return;
40     }
41 
42     Path out = temp.getRoot().toPath();
43     Path original = Paths.get(EXAMPLE_DIR, EXAMPLE_DEX);
44     Path packageMap = Paths.get(ToolHelper.EXAMPLES_DIR, EXAMPLE_PACKAGE_MAP);
45     Path proguardMap = Paths.get(ToolHelper.EXAMPLES_DIR, EXAMPLE_PROGUARD_MAP);
46     R8Command command =
47         R8Command.builder()
48             .addProgramFiles(original)
49             .setOutputPath(out)
50             .setMinApiLevel(Constants.ANDROID_L_API) // Allow native multidex.
51             .setProguardMapFile(proguardMap)
52             .setPackageDistributionFile(packageMap)
53             .build();
54     ToolHelper.runR8(command);
55     List<String> outs =
56         new ArrayList<>(
57             ImmutableList.of(
58                 out.resolve("classes.dex").toString(),
59                 out.resolve("classes2.dex").toString(),
60                 EXAMPLE_DIR + EXAMPLE_LIB));
61     outs.forEach(f -> Assert.assertTrue("Failed to find file " + f, Files.exists(Paths.get(f))));
62     ToolHelper.checkArtOutputIdentical(
63         ImmutableList.of(original.toString(), EXAMPLE_DIR + EXAMPLE_LIB),
64         outs,
65         EXAMPLE_CLASS,
66         null,
67         null);
68   }
69 }
70