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 """Creates a simple script to run a java "binary". | |
8 | |
9 This creates a script that sets up the java command line for running a java | |
10 jar. This includes correctly setting the classpath and the main class. | |
11 """ | |
12 | |
13 import optparse | |
14 import os | |
15 import sys | |
16 | |
17 from util import build_utils | |
18 | |
19 # The java command must be executed in the current directory because there may | |
20 # be user-supplied paths in the args. The script receives the classpath relative | |
21 # to the directory that the script is written in and then, when run, must | |
22 # recalculate the paths relative to the current directory. | |
23 script_template = """\ | |
24 #!/usr/bin/env python | |
25 # | |
26 # This file was generated by build/android/gyp/create_java_binary_script.py | |
27 | |
28 import os | |
29 import sys | |
30 | |
31 self_dir = os.path.dirname(__file__) | |
32 classpath = [{classpath}] | |
33 if os.getcwd() != self_dir: | |
34 offset = os.path.relpath(self_dir, os.getcwd()) | |
35 classpath = [os.path.join(offset, p) for p in classpath] | |
36 java_args = [ | |
37 "java", | |
38 "-classpath", ":".join(classpath), | |
39 \"{main_class}\"] + sys.argv[1:] | |
40 os.execvp("java", java_args) | |
41 """ | |
42 | |
43 def main(argv): | |
44 argv = build_utils.ExpandFileArgs(argv) | |
45 parser = optparse.OptionParser() | |
46 build_utils.AddDepfileOption(parser) | |
47 parser.add_option('--output', help='Output path for executable script.') | |
48 parser.add_option('--jar-path', help='Path to the main jar.') | |
49 parser.add_option('--main-class', | |
50 help='Name of the java class with the "main" entry point.') | |
51 parser.add_option('--classpath', action='append', | |
52 help='Classpath for running the jar.') | |
53 options, _ = parser.parse_args(argv) | |
54 | |
55 classpath = [options.jar_path] | |
56 for cp_arg in options.classpath: | |
57 classpath += build_utils.ParseGypList(cp_arg) | |
58 | |
59 run_dir = os.path.dirname(options.output) | |
60 classpath = [os.path.relpath(p, run_dir) for p in classpath] | |
61 | |
62 with open(options.output, 'w') as script: | |
63 script.write(script_template.format( | |
64 classpath=("\"%s\"" % "\", \"".join(classpath)), | |
newt (away)
2014/11/15 04:48:51
seems like a good place to use apostrophes:
cla
| |
65 main_class=options.main_class)) | |
66 | |
67 os.chmod(options.output, 0750) | |
68 | |
69 if options.depfile: | |
70 build_utils.WriteDepfile( | |
71 options.depfile, | |
72 build_utils.GetPythonDependencies()) | |
73 | |
74 | |
75 if __name__ == '__main__': | |
76 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |