diff options
author | Orion Hodson <oth@google.com> | 2022-10-14 17:23:05 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-10-14 17:23:05 +0000 |
commit | e5aaefde7c211a32dd3956b9e761f068e3236491 (patch) | |
tree | 916ee8746874e9a81482bc0a80581982a3d20dcf | |
parent | bb92e4048c2e3c17d05c26db92fd5dabc471d31a (diff) | |
parent | c3a7ae2e8c5e746ea9c6694002c811fad256cd62 (diff) | |
download | vogar-e5aaefde7c211a32dd3956b9e761f068e3236491.tar.gz |
Ensure file written for d8 is in a unique location am: 6f843c5f16 am: c3a7ae2e8c
Original change: https://android-review.googlesource.com/c/platform/external/vogar/+/2253645
Change-Id: Icc5494632a3f058f618f2e6a2b4cb9e682333715
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; } |