blob: f0791b0d751ebf2ca34cc4f5176497e5f1ebecb9 [file] [log] [blame]
Tamas Kenez971eec62017-05-24 11:08:40 +02001// 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.
4package com.android.tools.r8;
5
6import com.android.tools.r8.compatdx.CompatDx;
7import com.google.common.collect.ImmutableList;
8import java.io.FileWriter;
9import java.io.IOException;
10import java.nio.file.Paths;
11import java.util.Arrays;
12
Tamas Kenez971eec62017-05-24 11:08:40 +020013public 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}