OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """This finds the java distribution's tools.jar and copies it somewhere. | |
8 """ | |
9 | |
10 import optparse | |
11 import os | |
12 import re | |
13 import shutil | |
14 import sys | |
15 | |
16 from util import build_utils | |
17 | |
18 def main(argv): | |
jbudorick
2015/05/15 18:37:12
nit: drop the argv param and don't pass anything t
raywilliams_chromium
2015/05/18 19:53:23
Done.
| |
19 parser = optparse.OptionParser() | |
jbudorick
2015/05/15 18:37:12
oh, and use argparse.
raywilliams_chromium
2015/05/18 19:53:23
Done.
| |
20 build_utils.AddDepfileOption(parser) | |
21 parser.add_option('--output', help='Path to copy the tools.jar to.') | |
22 options, _ = parser.parse_args(argv) | |
23 | |
24 # This works with at least openjdk 1.6, 1.7 and sun java 1.6, 1.7 | |
25 stdout = build_utils.CheckOutput( | |
jbudorick
2015/05/15 18:37:12
Move the logic for finding sun_tools_jar_path into
raywilliams_chromium
2015/05/18 19:53:23
helper method extracted
raywilliams_chromium
2015/05/18 19:53:23
Done.
| |
26 ["java", "-verbose", "-version"], print_stderr=False, print_stdout=False) | |
27 rt_jar_finder = re.compile(r'\[Opened (.*)/jre/lib/rt.jar\]') | |
jbudorick
2015/05/15 18:37:12
Do this as a constant.
raywilliams_chromium
2015/05/18 19:53:23
Do you mean pull rt_jar_finder out of main() ?
jbudorick
2015/05/18 19:58:31
yes, and name it RT_JAR_FINDER
raywilliams_chromium
2015/05/18 20:50:23
Done.
| |
28 sun_tools_jar_path = None | |
29 for ln in stdout.split('\n'): | |
jbudorick
2015/05/15 18:37:12
splitlines?
raywilliams_chromium
2015/05/18 19:53:23
sure :)
raywilliams_chromium
2015/05/18 19:53:23
Done.
| |
30 match = re.match(rt_jar_finder, ln) | |
31 if match: | |
32 sun_tools_jar_path = os.path.join(match.group(1), 'lib', 'tools.jar') | |
33 break | |
34 | |
35 if sun_tools_jar_path is None: | |
36 raise Exception('Couldn\'t find tools.jar') | |
jbudorick
2015/05/15 18:37:12
nit: use double quotes when the string has a singl
raywilliams_chromium
2015/05/18 19:53:23
Done.
| |
37 | |
38 shutil.copy(sun_tools_jar_path, options.output) | |
39 | |
40 if options.depfile: | |
41 build_utils.WriteDepfile( | |
42 options.depfile, | |
43 [sun_tools_jar_path] + build_utils.GetPythonDependencies()) | |
44 | |
45 | |
46 if __name__ == '__main__': | |
47 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |