Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / build / android / gyp / find_sun_tools_jar.py
blob2f15a154abd8915f0e124e1d129a830ae57aa784
1 #!/usr/bin/env python
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.
7 """This finds the java distribution's tools.jar and copies it somewhere.
8 """
10 import argparse
11 import os
12 import re
13 import shutil
14 import sys
16 from util import build_utils
18 RT_JAR_FINDER = re.compile(r'\[Opened (.*)/jre/lib/rt.jar\]')
20 def main():
21 parser = argparse.ArgumentParser(description='Find Sun Tools Jar')
22 parser.add_argument('--depfile',
23 help='Path to depfile. This must be specified as the '
24 'action\'s first output.')
25 parser.add_argument('--output', required=True)
26 args = parser.parse_args()
28 sun_tools_jar_path = FindSunToolsJarPath()
30 if sun_tools_jar_path is None:
31 raise Exception("Couldn\'t find tools.jar")
33 # Using copyfile instead of copy() because copy() calls copymode()
34 # We don't want the locked mode because we may copy over this file again
35 shutil.copyfile(sun_tools_jar_path, args.output)
37 if args.depfile:
38 build_utils.WriteDepfile(
39 args.depfile,
40 [sun_tools_jar_path] + build_utils.GetPythonDependencies())
43 def FindSunToolsJarPath():
44 # This works with at least openjdk 1.6, 1.7 and sun java 1.6, 1.7
45 stdout = build_utils.CheckOutput(
46 ["java", "-verbose", "-version"], print_stderr=False)
47 for ln in stdout.splitlines():
48 match = RT_JAR_FINDER.match(ln)
49 if match:
50 return os.path.join(match.group(1), 'lib', 'tools.jar')
52 return None
55 if __name__ == '__main__':
56 sys.exit(main())