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

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

Issue 269943005: Add android_library template (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 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 import fnmatch 7 import fnmatch
8 import optparse 8 import optparse
9 import os 9 import os
10 import sys 10 import sys
11 11
12 from util import build_utils 12 from util import build_utils
13 from util import md5_check 13 from util import md5_check
14 14
15 15 def Javac(java_files, classpath, output_dir, chromium_code):
Nico 2014/05/05 22:08:10 docstring
16 def DoJavac(options, args):
17 output_dir = options.output_dir
18
19 src_gendirs = build_utils.ParseGypList(options.src_gendirs)
20 java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java')
21 if options.javac_includes:
22 javac_includes = build_utils.ParseGypList(options.javac_includes)
23 filtered_java_files = []
24 for f in java_files:
25 for include in javac_includes:
26 if fnmatch.fnmatch(f, include):
27 filtered_java_files.append(f)
28 break
29 java_files = filtered_java_files
30
31 # Compiling guava with certain orderings of input files causes a compiler 16 # Compiling guava with certain orderings of input files causes a compiler
32 # crash... Sorted order works, so use that. 17 # crash... Sorted order works, so use that.
33 # See https://code.google.com/p/guava-libraries/issues/detail?id=950 18 # See https://code.google.com/p/guava-libraries/issues/detail?id=950
Nico 2014/05/05 22:08:10 Can we merge in a guava version with this fix even
cjhopman 2014/06/25 01:20:03 Added TODO
34 java_files.sort() 19 java_files = sorted(java_files)
35 classpath = build_utils.ParseGypList(options.classpath)
36 20
37 jar_inputs = [] 21 jar_inputs = []
38 for path in classpath: 22 for path in classpath:
39 if os.path.exists(path + '.TOC'): 23 if os.path.exists(path + '.TOC'):
40 jar_inputs.append(path + '.TOC') 24 jar_inputs.append(path + '.TOC')
41 else: 25 else:
42 jar_inputs.append(path) 26 jar_inputs.append(path)
43 27
44 javac_args = [ 28 javac_args = [
45 '-g', 29 '-g',
46 '-source', '1.5', 30 '-source', '1.5',
47 '-target', '1.5', 31 '-target', '1.5',
48 '-classpath', ':'.join(classpath), 32 '-classpath', ':'.join(classpath),
49 '-d', output_dir] 33 '-d', output_dir]
50 if options.chromium_code: 34 if chromium_code:
51 javac_args.extend(['-Xlint:unchecked', '-Xlint:deprecation']) 35 javac_args.extend(['-Xlint:unchecked', '-Xlint:deprecation'])
52 else: 36 else:
53 # XDignore.symbol.file makes javac compile against rt.jar instead of 37 # XDignore.symbol.file makes javac compile against rt.jar instead of
54 # ct.sym. This means that using a java internal package/class will not 38 # ct.sym. This means that using a java internal package/class will not
55 # trigger a compile warning or error. 39 # trigger a compile warning or error.
56 javac_args.extend(['-XDignore.symbol.file']) 40 javac_args.extend(['-XDignore.symbol.file'])
57 41
58 javac_cmd = ['javac'] + javac_args + java_files 42 javac_cmd = ['javac'] + javac_args + java_files
59 43
60 def Compile(): 44 def Compile():
61 # Delete the classes directory. This ensures that all .class files in the 45 # Delete the classes directory. This ensures that all .class files in the
62 # output are actually from the input .java files. For example, if a .java 46 # output are actually from the input .java files. For example, if a .java
63 # file is deleted or an inner class is removed, the classes directory should 47 # file is deleted or an inner class is removed, the classes directory should
64 # not contain the corresponding old .class file after running this action. 48 # not contain the corresponding old .class file after running this action.
65 build_utils.DeleteDirectory(output_dir) 49 build_utils.DeleteDirectory(output_dir)
66 build_utils.MakeDirectory(output_dir) 50 build_utils.MakeDirectory(output_dir)
67 build_utils.CheckOutput(javac_cmd, print_stdout=options.chromium_code) 51 build_utils.CheckOutput(javac_cmd, print_stdout=chromium_code)
68 52
69 record_path = '%s/javac.md5.stamp' % options.output_dir 53 record_path = '%s/javac.md5.stamp' % output_dir
70 md5_check.CallAndRecordIfStale( 54 md5_check.CallAndRecordIfStale(
71 Compile, 55 Compile,
72 record_path=record_path, 56 record_path=record_path,
73 input_paths=java_files + jar_inputs, 57 input_paths=java_files + jar_inputs,
74 input_strings=javac_cmd) 58 input_strings=javac_cmd)
75 59
76 60
77 def main(): 61 def DoJavac(options, args):
62 output_dir = options.output_dir
63
64 src_gendirs = build_utils.ParseGypList(options.src_gendirs)
65 java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java')
66 if options.javac_includes:
67 javac_includes = build_utils.ParseGypList(options.javac_includes)
68 filtered_java_files = []
69 for f in java_files:
70 for include in javac_includes:
71 if fnmatch.fnmatch(f, include):
72 filtered_java_files.append(f)
73 break
74 java_files = filtered_java_files
75
76 classpath = build_utils.ParseGypList(options.classpath)
77 Javac(java_files, classpath, output_dir, options.chromium_code)
78
79
80 def main(argv):
78 parser = optparse.OptionParser() 81 parser = optparse.OptionParser()
79 parser.add_option('--src-gendirs', 82 parser.add_option('--src-gendirs',
80 help='Directories containing generated java files.') 83 help='Directories containing generated java files.')
81 parser.add_option('--javac-includes', 84 parser.add_option('--javac-includes',
82 help='A list of file patterns. If provided, only java files that match' + 85 help='A list of file patterns. If provided, only java files that match' +
83 'one of the patterns will be compiled.') 86 'one of the patterns will be compiled.')
84 parser.add_option('--classpath', help='Classpath for javac.') 87 parser.add_option('--classpath', help='Classpath for javac.')
85 parser.add_option('--output-dir', help='Directory for javac output.') 88 parser.add_option('--output-dir', help='Directory for javac output.')
86 parser.add_option('--stamp', help='Path to touch on success.') 89 parser.add_option('--stamp', help='Path to touch on success.')
87 parser.add_option('--chromium-code', type='int', help='Whether code being ' 90 parser.add_option('--chromium-code', type='int', help='Whether code being '
88 'compiled should be built with stricter warnings for ' 91 'compiled should be built with stricter warnings for '
89 'chromium code.') 92 'chromium code.')
90 93
91 options, args = parser.parse_args() 94 options, args = parser.parse_args()
92 95
93 DoJavac(options, args) 96 DoJavac(options, args)
94 97
95 if options.stamp: 98 if options.stamp:
96 build_utils.Touch(options.stamp) 99 build_utils.Touch(options.stamp)
97 100
98 101
99 if __name__ == '__main__': 102 if __name__ == '__main__':
100 sys.exit(main()) 103 sys.exit(main(sys.argv))
101 104
102 105
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698