Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / build / android / gyp / javac.py
blob8a62e5f994f51a9e2358583abe107c7144737edf
1 #!/usr/bin/env python
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
5 # found in the LICENSE file.
7 import fnmatch
8 import optparse
9 import os
10 import sys
12 from util import build_utils
15 def DoJavac(options):
16 output_dir = options.output_dir
18 src_dirs = build_utils.ParseGypList(options.src_dirs)
19 java_files = build_utils.FindInDirectories(src_dirs, '*.java')
20 if options.javac_includes:
21 javac_includes = build_utils.ParseGypList(options.javac_includes)
22 filtered_java_files = []
23 for f in java_files:
24 for include in javac_includes:
25 if fnmatch.fnmatch(f, include):
26 filtered_java_files.append(f)
27 break
28 java_files = filtered_java_files
30 # Compiling guava with certain orderings of input files causes a compiler
31 # crash... Sorted order works, so use that.
32 # See https://code.google.com/p/guava-libraries/issues/detail?id=950
33 java_files.sort()
35 classpath = build_utils.ParseGypList(options.classpath)
37 # Delete the classes directory. This ensures that all .class files in the
38 # output are actually from the input .java files. For example, if a .java
39 # file is deleted or an inner class is removed, the classes directory should
40 # not contain the corresponding old .class file after running this action.
41 build_utils.DeleteDirectory(output_dir)
42 build_utils.MakeDirectory(output_dir)
44 cmd = [
45 'javac',
46 '-g',
47 '-source', '1.5',
48 '-target', '1.5',
49 '-classpath', ':'.join(classpath),
50 '-d', output_dir,
51 '-Xlint:unchecked',
52 '-Xlint:deprecation',
55 suppress_output = not options.chromium_code
56 build_utils.CheckCallDie(cmd + java_files, suppress_output=suppress_output)
58 def main(argv):
59 parser = optparse.OptionParser()
60 parser.add_option('--src-dirs', help='Directories containing java files.')
61 parser.add_option('--javac-includes',
62 help='A list of file patterns. If provided, only java files that match' +
63 'one of the patterns will be compiled.')
64 parser.add_option('--classpath', help='Classpath for javac.')
65 parser.add_option('--output-dir', help='Directory for javac output.')
66 parser.add_option('--stamp', help='Path to touch on success.')
67 parser.add_option('--chromium-code', type='int', help='Whether code being '
68 'compiled should be built with stricter warnings for '
69 'chromium code.')
71 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
72 parser.add_option('--ignore', help='Ignored.')
74 options, _ = parser.parse_args()
76 DoJavac(options)
78 if options.stamp:
79 build_utils.Touch(options.stamp)
82 if __name__ == '__main__':
83 sys.exit(main(sys.argv))