blob: 59846226b4bee016ab16f0637575ecbfee148d16 [file] [log] [blame]
Tamas Kenezf2ee2a32017-06-21 10:30:20 +02001#!/usr/bin/env python
2# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6# Run ProGuard, Google's internal version
7
8from __future__ import print_function
Ian Zerny859dd892020-07-03 11:19:03 +02009
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020010import os
11import subprocess
12import sys
Ian Zerny859dd892020-07-03 11:19:03 +020013from exceptions import ValueError
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020014
Ian Zerny859dd892020-07-03 11:19:03 +020015import jdk
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020016import utils
17
Ian Zerny859dd892020-07-03 11:19:03 +020018# Internal constants, these should not be used outside this script.
19# Use the friendly utility methods below.
20PG_DIR = os.path.join(utils.THIRD_PARTY, 'proguard')
21DEFAULT = 'pg6'
22DEFAULT_ALIAS = 'pg'
23VERSIONS = {
24 'pg5': os.path.join(PG_DIR, 'proguard5.2.1', 'lib', 'proguard.jar'),
25 'pg6': os.path.join(PG_DIR, 'proguard6.0.1', 'lib', 'proguard.jar'),
26 'pg7': os.path.join(PG_DIR, 'proguard-7.0.0', 'lib', 'proguard.jar'),
27 'pg_internal': os.path.join(
28 PG_DIR, 'proguard_internal_159423826', 'ProGuard_deploy.jar'),
29}
30# Add alias for the default version.
31VERSIONS[DEFAULT_ALIAS] = VERSIONS[DEFAULT]
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020032
Ian Zerny859dd892020-07-03 11:19:03 +020033# Get versions sorted (nice for argument lists)
34def getVersions():
35 versions = list(VERSIONS.keys())
36 versions.sort()
37 return versions
38
39def isValidVersion(version):
40 return version in VERSIONS
41
42def getValidatedVersion(version):
43 if not isValidVersion(version):
44 raise ValueError("Invalid PG version: '%s'" % version)
45 return version
46
47def getJar(version=DEFAULT):
48 return VERSIONS[getValidatedVersion(version)]
49
50def getRetraceJar(version=DEFAULT):
51 if version == 'pg_internal':
52 raise ValueError("No retrace in internal distribution")
53 return getJar().replace('proguard.jar', 'retrace.jar')
54
55def getCmd(args, version=DEFAULT, jvmArgs=None):
56 cmd = []
57 if jvmArgs:
58 cmd.extend(jvmArgs)
59 cmd.extend([jdk.GetJavaExecutable(), '-jar', getJar(version)])
60 cmd.extend(args)
61 return cmd
62
63def run(args, version=DEFAULT, track_memory_file=None, stdout=None, stderr=None):
Tamas Kenezfc34cd82017-07-13 12:43:57 +020064 cmd = []
65 if track_memory_file:
66 cmd.extend(['tools/track_memory.sh', track_memory_file])
Ian Zerny859dd892020-07-03 11:19:03 +020067 cmd.extend(getCmd(args, version))
Tamas Kenezfc34cd82017-07-13 12:43:57 +020068 utils.PrintCmd(cmd)
Ian Zerny517c7662018-07-11 15:22:29 +020069 subprocess.call(cmd, stdout=stdout, stderr=stderr)
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020070
71def Main():
72 run(sys.argv[1:])
73
74if __name__ == '__main__':
75 sys.exit(Main())