blob: 4a3ae7d400a4b940ec03c78a0085ff977602a5d7 [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Tamas Kenezf2ee2a32017-06-21 10:30:20 +02002# 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
Tamas Kenezf2ee2a32017-06-21 10:30:20 +02008import os
9import subprocess
10import sys
11
Ian Zerny859dd892020-07-03 11:19:03 +020012import jdk
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020013import utils
14
Ian Zerny859dd892020-07-03 11:19:03 +020015# Internal constants, these should not be used outside this script.
16# Use the friendly utility methods below.
17PG_DIR = os.path.join(utils.THIRD_PARTY, 'proguard')
18DEFAULT = 'pg6'
19DEFAULT_ALIAS = 'pg'
20VERSIONS = {
21 'pg5': os.path.join(PG_DIR, 'proguard5.2.1', 'lib', 'proguard.jar'),
22 'pg6': os.path.join(PG_DIR, 'proguard6.0.1', 'lib', 'proguard.jar'),
23 'pg7': os.path.join(PG_DIR, 'proguard-7.0.0', 'lib', 'proguard.jar'),
24 'pg_internal': os.path.join(
25 PG_DIR, 'proguard_internal_159423826', 'ProGuard_deploy.jar'),
26}
27# Add alias for the default version.
28VERSIONS[DEFAULT_ALIAS] = VERSIONS[DEFAULT]
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020029
Ian Zerny859dd892020-07-03 11:19:03 +020030# Get versions sorted (nice for argument lists)
31def getVersions():
32 versions = list(VERSIONS.keys())
33 versions.sort()
34 return versions
35
36def isValidVersion(version):
37 return version in VERSIONS
38
39def getValidatedVersion(version):
40 if not isValidVersion(version):
41 raise ValueError("Invalid PG version: '%s'" % version)
42 return version
43
44def getJar(version=DEFAULT):
45 return VERSIONS[getValidatedVersion(version)]
46
47def getRetraceJar(version=DEFAULT):
48 if version == 'pg_internal':
49 raise ValueError("No retrace in internal distribution")
50 return getJar().replace('proguard.jar', 'retrace.jar')
51
52def getCmd(args, version=DEFAULT, jvmArgs=None):
53 cmd = []
54 if jvmArgs:
55 cmd.extend(jvmArgs)
56 cmd.extend([jdk.GetJavaExecutable(), '-jar', getJar(version)])
57 cmd.extend(args)
58 return cmd
59
60def run(args, version=DEFAULT, track_memory_file=None, stdout=None, stderr=None):
Tamas Kenezfc34cd82017-07-13 12:43:57 +020061 cmd = []
62 if track_memory_file:
63 cmd.extend(['tools/track_memory.sh', track_memory_file])
Ian Zerny859dd892020-07-03 11:19:03 +020064 cmd.extend(getCmd(args, version))
Tamas Kenezfc34cd82017-07-13 12:43:57 +020065 utils.PrintCmd(cmd)
Ian Zerny517c7662018-07-11 15:22:29 +020066 subprocess.call(cmd, stdout=stdout, stderr=stderr)
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020067
68def Main():
69 run(sys.argv[1:])
70
71if __name__ == '__main__':
72 sys.exit(Main())