Chromium Code Reviews| Index: build/android/gyp/create_java_binary_script.py |
| diff --git a/build/android/gyp/create_java_binary_script.py b/build/android/gyp/create_java_binary_script.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..7b1f3a3c7c97b30a3d37d087bf0e41f35b192d75 |
| --- /dev/null |
| +++ b/build/android/gyp/create_java_binary_script.py |
| @@ -0,0 +1,76 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Creates a simple script to run a java "binary". |
| + |
| +This creates a script that sets up the java command line for running a java |
| +jar. This includes correctly setting the classpath and the main class. |
| +""" |
| + |
| +import optparse |
| +import os |
| +import sys |
| + |
| +from util import build_utils |
| + |
| +script_template = """\ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
|
newt (away)
2014/11/03 22:12:44
Generated files probably don't need a copyright he
cjhopman
2014/11/15 03:37:59
Done.
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# |
| +# This file was generated by build/android/gyp/create_java_binary_script.py |
| + |
| +import os |
| +import select |
|
newt (away)
2014/11/03 22:12:44
not used
cjhopman
2014/11/15 03:37:58
Done.
|
| +import subprocess |
| +import sys |
| + |
| +self_dir = os.path.dirname(__file__) |
| +classpath = [%s] |
|
newt (away)
2014/11/03 22:12:44
s/%s/{classpath}
and use "".format() below instea
cjhopman
2014/11/15 03:37:59
Done.
|
| +if os.getcwd() != self_dir: |
|
newt (away)
2014/11/03 22:12:44
you could just cd into self_dir, instead of doing
cjhopman
2014/11/15 03:37:59
Added a comment above the script_template that exp
|
| + offset = os.path.relpath(self_dir, os.getcwd()) |
| + classpath = [os.path.join(offset, p) for p in classpath] |
| +javac_cmd = ["java", "-classpath", ":".join(classpath), \"%s\"] + sys.argv[1:] |
|
newt (away)
2014/11/03 22:12:44
s/%s/{main_class}
cjhopman
2014/11/15 03:37:58
Done.
|
| +javac = subprocess.Popen(javac_cmd, stdout=sys.stdout, stderr=sys.stderr) |
|
newt (away)
2014/11/03 22:12:44
You could use os.execv(), which avoids the need to
cjhopman
2014/11/15 03:37:59
Done.
|
| +javac.wait() |
| +sys.exit(javac.returncode) |
| +""" |
| + |
| +def main(argv): |
| + argv = build_utils.ExpandFileArgs(argv) |
| + parser = optparse.OptionParser() |
| + build_utils.AddDepfileOption(parser) |
| + parser.add_option('--output', help='Output path for executable script.') |
| + parser.add_option('--jar-path', help='Path to the main jar.') |
| + parser.add_option('--main-class', |
| + help='Name of the java class with the "main" entry point.') |
| + parser.add_option('--classpath', action='append', |
| + help='Classpath for running the jar.') |
| + options, _ = parser.parse_args(argv) |
| + |
| + classpath = [ options.jar_path ] |
|
newt (away)
2014/11/03 22:12:44
nit: remove spaces
cjhopman
2014/11/15 03:37:58
Done.
|
| + for cp_arg in options.classpath: |
| + classpath += build_utils.ParseGypList(cp_arg) |
| + |
| + run_dir = os.path.dirname(options.output) |
| + classpath = [os.path.relpath(p, run_dir) for p in classpath] |
| + |
| + with open(options.output, 'w') as script: |
| + script.write(script_template % |
| + ("\"%s\"" % "\", \"".join(classpath), options.main_class)) |
| + |
| + os.chmod(options.output, 0744) |
|
newt (away)
2014/11/03 22:12:44
Why not 750? (like most of our python scripts?)
cjhopman
2014/11/15 03:37:59
Done.
|
| + |
| + if options.depfile: |
| + build_utils.WriteDepfile( |
| + options.depfile, |
| + build_utils.GetPythonDependencies()) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |