Upstream version 8.37.187.0
[platform/framework/web/crosswalk.git] / src / xwalk / app / tools / android / gyp / javac.py
1 #!/usr/bin/env python
2 #
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.
6 # pylint: disable=F0401
7
8 import fnmatch
9 import optparse
10 import os
11 import sys
12
13 from util import build_utils
14 from util import md5_check
15
16
17 def DoJavac(options):
18   output_dir = options.output_dir
19
20   java_files = build_utils.FindInDirectories(options.src_dirs, '*.java')
21   if options.javac_includes:
22     filtered_java_files = []
23     for f in java_files:
24       for include in options.javac_includes:
25         if fnmatch.fnmatch(f, include):
26           filtered_java_files.append(f)
27           break
28     java_files = filtered_java_files
29
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()
34
35   jar_inputs = []
36   for path in options.classpath:
37     if os.path.exists(path + '.TOC'):
38       jar_inputs.append(path + '.TOC')
39     else:
40       jar_inputs.append(path)
41
42   javac_cmd = [
43       'javac',
44       '-g',
45       '-source', '1.5',
46       '-target', '1.5',
47       '-classpath', os.pathsep.join(options.classpath),
48       '-d', output_dir,
49       '-Xlint:unchecked',
50       '-Xlint:deprecation',
51       ] + java_files
52
53   def Compile():
54     # Delete the classes directory. This ensures that all .class files in the
55     # output are actually from the input .java files. For example, if a .java
56     # file is deleted or an inner class is removed, the classes directory should
57     # not contain the corresponding old .class file after running this action.
58     build_utils.DeleteDirectory(output_dir)
59     build_utils.MakeDirectory(output_dir)
60     suppress_output = not options.chromium_code
61     build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output)
62
63   record_path = '%s/javac.md5.stamp' % options.output_dir
64   md5_check.CallAndRecordIfStale(
65       Compile,
66       record_path=record_path,
67       input_paths=java_files + jar_inputs,
68       input_strings=javac_cmd)
69
70
71 def main():
72   parser = optparse.OptionParser()
73   parser.add_option('--src-dirs', action='append',
74                     help='Directories containing java files.')
75   parser.add_option('--javac-includes', action='append',
76       help='A list of file patterns. If provided, only java files that match' +
77         'one of the patterns will be compiled.')
78   parser.add_option('--classpath', action='append',
79                     help='Classpaths for javac.')
80   parser.add_option('--output-dir', help='Directory for javac output.')
81   parser.add_option('--stamp', help='Path to touch on success.')
82   parser.add_option('--chromium-code', type='int', help='Whether code being '
83                     'compiled should be built with stricter warnings for '
84                     'chromium code.')
85
86   options, _ = parser.parse_args()
87
88   DoJavac(options)
89
90   if options.stamp:
91     build_utils.Touch(options.stamp)
92
93
94 if __name__ == '__main__':
95   sys.exit(main())
96
97