Tamas Kenez | 971eec6 | 2017-05-24 11:08:40 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, 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; |
| 5 | |
| 6 | import com.android.tools.r8.compatdx.CompatDx; |
| 7 | import com.google.common.collect.ImmutableList; |
| 8 | import java.io.FileWriter; |
| 9 | import java.io.IOException; |
| 10 | import java.nio.file.Paths; |
| 11 | import java.util.Arrays; |
| 12 | |
Tamas Kenez | 971eec6 | 2017-05-24 11:08:40 +0200 | [diff] [blame] | 13 | public final class D8Logger { |
| 14 | |
| 15 | private static final int STATUS_ERROR = 1; |
| 16 | |
| 17 | private static final String USAGE_MESSAGE = String.join("\n", ImmutableList.of( |
| 18 | "Usage: java -jar d8logger.jar <compiler-options>", |
| 19 | " where <compiler-options> will be", |
| 20 | "", |
| 21 | " 1. forwarded to the 'd8' or 'compatdx' tool (depending on the presence of the '--dex'", |
| 22 | " option), and also", |
| 23 | " 2. appended to the file in the environment variable 'D8LOGGER_OUTPUT'", |
| 24 | "", |
| 25 | " The options will be appended as a new line with TAB characters between the arguments.")); |
| 26 | |
| 27 | public static void main(String[] args) throws IOException { |
| 28 | if (args.length == 0) { |
| 29 | System.err.println(USAGE_MESSAGE); |
| 30 | System.exit(STATUS_ERROR); |
| 31 | } |
| 32 | String output = System.getenv("D8LOGGER_OUTPUT"); |
| 33 | if (output == null) { |
| 34 | throw new IOException("D8Logger: D8LOGGER_OUTPUT environment variable must be set."); |
| 35 | } |
| 36 | |
| 37 | if (output.length() > 0) { |
| 38 | String[] absArgs = Arrays.stream(args) |
| 39 | .map(s -> s.startsWith("-") ? s : Paths.get(s).toAbsolutePath().toString()) |
| 40 | .toArray(String[]::new); |
| 41 | FileWriter fw = new FileWriter(output, true); |
| 42 | fw.write(String.join("\t", absArgs) + "\n"); |
| 43 | fw.close(); |
| 44 | } |
| 45 | |
| 46 | if (Arrays.stream(args).anyMatch(s -> s.equals("--dex"))) { |
| 47 | CompatDx.main(args); |
| 48 | } else { |
| 49 | D8.main(args); |
| 50 | } |
| 51 | } |
| 52 | } |