OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Creates a simple script to run a java "binary". | 7 """Creates a simple script to run a java "binary". |
8 | 8 |
9 This creates a script that sets up the java command line for running a java | 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. | 10 jar. This includes correctly setting the classpath and the main class. |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 self_dir = os.path.dirname(__file__) | 31 self_dir = os.path.dirname(__file__) |
32 classpath = [{classpath}] | 32 classpath = [{classpath}] |
33 bootclasspath = [{bootclasspath}] | 33 bootclasspath = [{bootclasspath}] |
34 extra_program_args = {extra_program_args} | 34 extra_program_args = {extra_program_args} |
35 if os.getcwd() != self_dir: | 35 if os.getcwd() != self_dir: |
36 offset = os.path.relpath(self_dir, os.getcwd()) | 36 offset = os.path.relpath(self_dir, os.getcwd()) |
37 classpath = [os.path.join(offset, p) for p in classpath] | 37 classpath = [os.path.join(offset, p) for p in classpath] |
38 bootclasspath = [os.path.join(offset, p) for p in bootclasspath] | 38 bootclasspath = [os.path.join(offset, p) for p in bootclasspath] |
39 java_cmd = ["java"] | 39 java_cmd = ["java"] |
| 40 {noverify_flag} |
40 if bootclasspath: | 41 if bootclasspath: |
41 java_cmd.append("-Xbootclasspath/p:" + ":".join(bootclasspath)) | 42 java_cmd.append("-Xbootclasspath/p:" + ":".join(bootclasspath)) |
42 java_cmd.extend( | 43 java_cmd.extend( |
43 ["-classpath", ":".join(classpath), "-enableassertions", \"{main_class}\"]) | 44 ["-classpath", ":".join(classpath), "-enableassertions", \"{main_class}\"]) |
44 java_cmd.extend(extra_program_args) | 45 java_cmd.extend(extra_program_args) |
45 java_cmd.extend(sys.argv[1:]) | 46 java_cmd.extend(sys.argv[1:]) |
46 os.execvp("java", java_cmd) | 47 os.execvp("java", java_cmd) |
47 """ | 48 """ |
48 | 49 |
49 def main(argv): | 50 def main(argv): |
50 argv = build_utils.ExpandFileArgs(argv) | 51 argv = build_utils.ExpandFileArgs(argv) |
51 parser = optparse.OptionParser() | 52 parser = optparse.OptionParser() |
52 build_utils.AddDepfileOption(parser) | 53 build_utils.AddDepfileOption(parser) |
53 parser.add_option('--output', help='Output path for executable script.') | 54 parser.add_option('--output', help='Output path for executable script.') |
54 parser.add_option('--jar-path', help='Path to the main jar.') | 55 parser.add_option('--jar-path', help='Path to the main jar.') |
55 parser.add_option('--main-class', | 56 parser.add_option('--main-class', |
56 help='Name of the java class with the "main" entry point.') | 57 help='Name of the java class with the "main" entry point.') |
57 parser.add_option('--classpath', action='append', default=[], | 58 parser.add_option('--classpath', action='append', default=[], |
58 help='Classpath for running the jar.') | 59 help='Classpath for running the jar.') |
59 parser.add_option('--bootclasspath', action='append', default=[], | 60 parser.add_option('--bootclasspath', action='append', default=[], |
60 help='zip/jar files to add to bootclasspath for java cmd.') | 61 help='zip/jar files to add to bootclasspath for java cmd.') |
| 62 parser.add_option('--noverify', action='store_true', |
| 63 help='JVM flag: noverify.') |
| 64 |
61 options, extra_program_args = parser.parse_args(argv) | 65 options, extra_program_args = parser.parse_args(argv) |
62 | 66 |
| 67 if (options.noverify): |
| 68 noverify_flag = 'java_cmd.append("-noverify")' |
| 69 else: |
| 70 noverify_flag = '' |
| 71 |
63 classpath = [options.jar_path] | 72 classpath = [options.jar_path] |
64 for cp_arg in options.classpath: | 73 for cp_arg in options.classpath: |
65 classpath += build_utils.ParseGypList(cp_arg) | 74 classpath += build_utils.ParseGypList(cp_arg) |
66 | 75 |
67 bootclasspath = [] | 76 bootclasspath = [] |
68 for bootcp_arg in options.bootclasspath: | 77 for bootcp_arg in options.bootclasspath: |
69 bootclasspath += build_utils.ParseGypList(bootcp_arg) | 78 bootclasspath += build_utils.ParseGypList(bootcp_arg) |
70 | 79 |
71 run_dir = os.path.dirname(options.output) | 80 run_dir = os.path.dirname(options.output) |
72 bootclasspath = [os.path.relpath(p, run_dir) for p in bootclasspath] | 81 bootclasspath = [os.path.relpath(p, run_dir) for p in bootclasspath] |
73 classpath = [os.path.relpath(p, run_dir) for p in classpath] | 82 classpath = [os.path.relpath(p, run_dir) for p in classpath] |
74 | 83 |
75 with open(options.output, 'w') as script: | 84 with open(options.output, 'w') as script: |
76 script.write(script_template.format( | 85 script.write(script_template.format( |
77 classpath=('"%s"' % '", "'.join(classpath)), | 86 classpath=('"%s"' % '", "'.join(classpath)), |
78 bootclasspath=('"%s"' % '", "'.join(bootclasspath) | 87 bootclasspath=('"%s"' % '", "'.join(bootclasspath) |
79 if bootclasspath else ''), | 88 if bootclasspath else ''), |
80 main_class=options.main_class, | 89 main_class=options.main_class, |
81 extra_program_args=repr(extra_program_args))) | 90 extra_program_args=repr(extra_program_args), |
| 91 noverify_flag=noverify_flag)) |
82 | 92 |
83 os.chmod(options.output, 0750) | 93 os.chmod(options.output, 0750) |
84 | 94 |
85 if options.depfile: | 95 if options.depfile: |
86 build_utils.WriteDepfile( | 96 build_utils.WriteDepfile( |
87 options.depfile, | 97 options.depfile, |
88 build_utils.GetPythonDependencies()) | 98 build_utils.GetPythonDependencies()) |
89 | 99 |
90 | 100 |
91 if __name__ == '__main__': | 101 if __name__ == '__main__': |
92 sys.exit(main(sys.argv[1:])) | 102 sys.exit(main(sys.argv[1:])) |
OLD | NEW |