diff options
author | Orion Hodson <oth@google.com> | 2022-10-14 18:11:18 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-10-14 18:11:18 +0000 |
commit | 8beec355cc7d50339c21023abb586c1458efb35e (patch) | |
tree | 916ee8746874e9a81482bc0a80581982a3d20dcf | |
parent | 6e4f2a25ee3ac2de652b8704a4b70364096c6ef6 (diff) | |
parent | e5aaefde7c211a32dd3956b9e761f068e3236491 (diff) | |
download | vogar-8beec355cc7d50339c21023abb586c1458efb35e.tar.gz |
Ensure file written for d8 is in a unique location am: 6f843c5f16 am: c3a7ae2e8c am: e5aaefde7c
Original change: https://android-review.googlesource.com/c/platform/external/vogar/+/2253645
Change-Id: I3d4a7df5de5a5c955121fda774c4d140224ea725
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | src/vogar/android/AndroidSdk.java | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/vogar/android/AndroidSdk.java b/src/vogar/android/AndroidSdk.java index 6dc5f4a..068508a 100644 --- a/src/vogar/android/AndroidSdk.java +++ b/src/vogar/android/AndroidSdk.java @@ -408,7 +408,7 @@ public class AndroidSdk { case D8: List<String> sanitizedOutputFilePaths; try { - sanitizedOutputFilePaths = removeDexFilesForD8(filePaths); + sanitizedOutputFilePaths = removeDexFilesForD8(filePaths, outputTempDir); } catch (IOException e) { throw new RuntimeException("Error while removing dex files from archive", e); } @@ -484,26 +484,35 @@ public class AndroidSdk { } /** + * Generates a file path for a modified d8 input file. + * @param inputFile the d8 input file. + * @param outputDirectory the directory where the modified file should be written. + * @return the destination for the modified d8 input file. + */ + private static File getModifiedD8Destination(File inputFile, File outputDirectory) { + String name = inputFile.getName(); + int suffixStart = name.lastIndexOf('.'); + if (suffixStart != -1) { + name = name.substring(0, suffixStart); + } + return new File(outputDirectory, name + "-d8.jar"); + } + + /** * Removes DEX files from an archive and preserves the rest. */ - private List<String> removeDexFilesForD8(List<String> fileNames) throws IOException { + private List<String> removeDexFilesForD8(List<String> fileNames, File tempDir) + throws IOException { byte[] buffer = new byte[4096]; List<String> processedFiles = new ArrayList<>(fileNames.size()); for (String inputFileName : fileNames) { - String jarExtension = ".jar"; - String outputFileName; - if (inputFileName.endsWith(jarExtension)) { - outputFileName = - inputFileName.substring(0, inputFileName.length() - jarExtension.length()) - + "-d8" + jarExtension; - } else { - outputFileName = inputFileName + "-d8" + jarExtension; - } + File inputFile = new File(inputFileName); + File outputFile = getModifiedD8Destination(inputFile, tempDir); try (JarOutputStream outputJar = - new JarOutputStream(new FileOutputStream(outputFileName))) { + new JarOutputStream(new FileOutputStream(outputFile))) { copyJarContentExcludingFiles(buffer, inputFileName, outputJar, ".dex"); } - processedFiles.add(outputFileName); + processedFiles.add(outputFile.toString()); } return processedFiles; } |