Upstream version 7.36.152.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   src_dirs = options.src_dirs.split()
21   java_files = build_utils.FindInDirectories(src_dirs, '*.java')
22   if options.javac_includes:
23     javac_includes = options.javac_includes.split()
24     filtered_java_files = []
25     for f in java_files:
26       for include in javac_includes:
27         if fnmatch.fnmatch(f, include):
28           filtered_java_files.append(f)
29           break
30     java_files = filtered_java_files
31
32   # Compiling guava with certain orderings of input files causes a compiler
33   # crash... Sorted order works, so use that.
34   # See https://code.google.com/p/guava-libraries/issues/detail?id=950
35   java_files.sort()
36   classpath = options.classpath.split()
37
38   jar_inputs = []
39   for path in classpath:
40     if os.path.exists(path + '.TOC'):
41       jar_inputs.append(path + '.TOC')
42     else:
43       jar_inputs.append(path)
44
45   javac_cmd = [
46       'javac',
47       '-g',
48       '-source', '1.5',
49       '-target', '1.5',
50       '-classpath', os.pathsep.join(classpath),
51       '-d', output_dir,
52       '-Xlint:unchecked',
53       '-Xlint:deprecation',
54       ] + java_files
55
56   def Compile():
57     # Delete the classes directory. This ensures that all .class files in the
58     # output are actually from the input .java files. For example, if a .java
59     # file is deleted or an inner class is removed, the classes directory should
60     # not contain the corresponding old .class file after running this action.
61     build_utils.DeleteDirectory(output_dir)
62     build_utils.MakeDirectory(output_dir)
63     suppress_output = not options.chromium_code
64     build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output)
65
66   record_path = '%s/javac.md5.stamp' % options.output_dir
67   md5_check.CallAndRecordIfStale(
68       Compile,
69       record_path=record_path,
70       input_paths=java_files + jar_inputs,
71       input_strings=javac_cmd)
72
73
74 def main():
75   parser = optparse.OptionParser()
76   parser.add_option('--src-dirs', help='Directories containing java files.')
77   parser.add_option('--javac-includes',
78       help='A list of file patterns. If provided, only java files that match' +
79         'one of the patterns will be compiled.')
80   parser.add_option('--classpath', help='Classpath for javac.')
81   parser.add_option('--output-dir', help='Directory for javac output.')
82   parser.add_option('--stamp', help='Path to touch on success.')
83   parser.add_option('--chromium-code', type='int', help='Whether code being '
84                     'compiled should be built with stricter warnings for '
85                     'chromium code.')
86
87   options, _ = parser.parse_args()
88
89   DoJavac(options)
90
91   if options.stamp:
92     build_utils.Touch(options.stamp)
93
94
95 if __name__ == '__main__':
96   sys.exit(main())
97
98