Chromium Code Reviews| 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', help='JVM flag: noverify.') | |
|
agrieve
2016/04/26 14:51:10
nit: Change this to a boolean flag (action='store_
BigBossZhiling
2016/04/26 17:35:58
Done.
| |
| 63 | |
| 61 options, extra_program_args = parser.parse_args(argv) | 64 options, extra_program_args = parser.parse_args(argv) |
| 62 | 65 |
| 66 if (options.noverify == "true"): | |
| 67 noverify_flag = 'java_cmd.append("-noverify")' | |
| 68 else: | |
| 69 noverify_flag = '' | |
| 70 | |
| 63 classpath = [options.jar_path] | 71 classpath = [options.jar_path] |
| 64 for cp_arg in options.classpath: | 72 for cp_arg in options.classpath: |
| 65 classpath += build_utils.ParseGypList(cp_arg) | 73 classpath += build_utils.ParseGypList(cp_arg) |
| 66 | 74 |
| 67 bootclasspath = [] | 75 bootclasspath = [] |
| 68 for bootcp_arg in options.bootclasspath: | 76 for bootcp_arg in options.bootclasspath: |
| 69 bootclasspath += build_utils.ParseGypList(bootcp_arg) | 77 bootclasspath += build_utils.ParseGypList(bootcp_arg) |
| 70 | 78 |
| 71 run_dir = os.path.dirname(options.output) | 79 run_dir = os.path.dirname(options.output) |
| 72 bootclasspath = [os.path.relpath(p, run_dir) for p in bootclasspath] | 80 bootclasspath = [os.path.relpath(p, run_dir) for p in bootclasspath] |
| 73 classpath = [os.path.relpath(p, run_dir) for p in classpath] | 81 classpath = [os.path.relpath(p, run_dir) for p in classpath] |
| 74 | 82 |
| 75 with open(options.output, 'w') as script: | 83 with open(options.output, 'w') as script: |
| 76 script.write(script_template.format( | 84 script.write(script_template.format( |
| 77 classpath=('"%s"' % '", "'.join(classpath)), | 85 classpath=('"%s"' % '", "'.join(classpath)), |
| 78 bootclasspath=('"%s"' % '", "'.join(bootclasspath) | 86 bootclasspath=('"%s"' % '", "'.join(bootclasspath) |
| 79 if bootclasspath else ''), | 87 if bootclasspath else ''), |
| 80 main_class=options.main_class, | 88 main_class=options.main_class, |
| 81 extra_program_args=repr(extra_program_args))) | 89 extra_program_args=repr(extra_program_args), |
| 90 noverify_flag=noverify_flag)) | |
| 82 | 91 |
| 83 os.chmod(options.output, 0750) | 92 os.chmod(options.output, 0750) |
| 84 | 93 |
| 85 if options.depfile: | 94 if options.depfile: |
| 86 build_utils.WriteDepfile( | 95 build_utils.WriteDepfile( |
| 87 options.depfile, | 96 options.depfile, |
| 88 build_utils.GetPythonDependencies()) | 97 build_utils.GetPythonDependencies()) |
| 89 | 98 |
| 90 | 99 |
| 91 if __name__ == '__main__': | 100 if __name__ == '__main__': |
| 92 sys.exit(main(sys.argv[1:])) | 101 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |