Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: build/android/gyp/create_java_binary_script.py

Issue 687633003: Greatly improve (non-android) java support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: junit_unittests -> java_binary Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 script_template = """\
20 #!/usr/bin/env python
21 #
22 # 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.
23 # Use of this source code is governed by a BSD-style license that can be
24 # found in the LICENSE file.
25 #
26 # This file was generated by build/android/gyp/create_java_binary_script.py
27
28 import os
29 import select
newt (away) 2014/11/03 22:12:44 not used
cjhopman 2014/11/15 03:37:58 Done.
30 import subprocess
31 import sys
32
33 self_dir = os.path.dirname(__file__)
34 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.
35 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
36 offset = os.path.relpath(self_dir, os.getcwd())
37 classpath = [os.path.join(offset, p) for p in classpath]
38 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.
39 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.
40 javac.wait()
41 sys.exit(javac.returncode)
42 """
43
44 def main(argv):
45 argv = build_utils.ExpandFileArgs(argv)
46 parser = optparse.OptionParser()
47 build_utils.AddDepfileOption(parser)
48 parser.add_option('--output', help='Output path for executable script.')
49 parser.add_option('--jar-path', help='Path to the main jar.')
50 parser.add_option('--main-class',
51 help='Name of the java class with the "main" entry point.')
52 parser.add_option('--classpath', action='append',
53 help='Classpath for running the jar.')
54 options, _ = parser.parse_args(argv)
55
56 classpath = [ options.jar_path ]
newt (away) 2014/11/03 22:12:44 nit: remove spaces
cjhopman 2014/11/15 03:37:58 Done.
57 for cp_arg in options.classpath:
58 classpath += build_utils.ParseGypList(cp_arg)
59
60 run_dir = os.path.dirname(options.output)
61 classpath = [os.path.relpath(p, run_dir) for p in classpath]
62
63 with open(options.output, 'w') as script:
64 script.write(script_template %
65 ("\"%s\"" % "\", \"".join(classpath), options.main_class))
66
67 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.
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:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698