summaryrefslogtreecommitdiffstats
path: root/build/android/gyp/javac.py
diff options
context:
space:
mode:
authorcjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-02 10:46:46 +0000
committercjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-02 10:46:46 +0000
commit8322fa954f92f25ea48afb1d7b7af173f16eb20c (patch)
treecd74d41786336fc8c783aef71337cd7ac4a82eef /build/android/gyp/javac.py
parent971cf77e78f6ebc7296e65c9d15087e948818ee3 (diff)
downloadchromium_src-8322fa954f92f25ea48afb1d7b7af173f16eb20c.zip
chromium_src-8322fa954f92f25ea48afb1d7b7af173f16eb20c.tar.gz
chromium_src-8322fa954f92f25ea48afb1d7b7af173f16eb20c.tar.bz2
Add android_library template and build_configs
This is the GN equivalent of build/java.gypi. It is a template for creating an Android library including java code and Android resources. It currently only compiles java files (including files in srcjars from srcjar targets like java_cpp_template) and zips them together in a .jar and creates the corresponding .jar.TOC. Some of the things still to do: proguard_preprocess, android_lint, emma coverage, dex, everything resources. Adds android_java_library rule for base_java, guava, and jsr-305. This add the --java-srcjars argument to javac.py. This will accept a .zip of .java files and include those files in the compilation. This approach is preferred over using the --src-gendirs option. Many of the parts of building Android stuff (libraries, resources, apks) require knowledge of the dependents of that thing. Examples: javac classpath, for resources aapt needs to know about all dependents, dexing for an apk needs to know about all java code going into that apk. For gyp, this is done primarily with all_dependent_settings. There is then some of this logic in two particular steps (dexing and proguard). These steps, when building an instrumentation apk, need to exclude the things in the tested apk and this is done by having the tested apk essentially write a file saying what it did in those steps and the test apk reading that file and excluding stuff. In GN, all_dependent_settings doesn't really work. This change introduces a new way of calculating and using this information. Specifically .build_config files and build_utils.ExpandFileArgs(). The build_config file for a target contains the information that depends on dependents. The logic in write_build_config and the logic in the template specification are very much tied together (in some sense, write_build_config is just the part of the template specification that can actually inspect the dependency graph). With build_utils.ExpandFileArgs() all the other build scripts are essentially unaware of the .build_config files and can just be written in a (mostly) straightforward way. A large part of the information calculated by the build_config is finding input files to later actions. This requires that those later actions writes a depfile that contains any inputs that are specified by the build_config (in the case of this change, javac and the classpath files). Since a action's script shouldn't really know about the build_config file and what information it got from that, it is safest for the action to write *all* of its inputs into the depfile (but to be correct it only has to write those that aren't explicitly specified in the build files). Depends on: https://codereview.chromium.org/341823003/ BUG=359249 Review URL: https://codereview.chromium.org/269943005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280995 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/gyp/javac.py')
-rwxr-xr-xbuild/android/gyp/javac.py71
1 files changed, 51 insertions, 20 deletions
diff --git a/build/android/gyp/javac.py b/build/android/gyp/javac.py
index 599f588..ec2f22a 100755
--- a/build/android/gyp/javac.py
+++ b/build/android/gyp/javac.py
@@ -52,23 +52,22 @@ def ColorJavacOutput(output):
return '\n'.join(map(ApplyColor, output.split('\n')))
+
def DoJavac(
- classpath, javac_includes, classes_dir, chromium_code, java_files):
- if javac_includes:
- javac_includes = build_utils.ParseGypList(javac_includes)
- filtered_java_files = []
- for f in java_files:
- for include in javac_includes:
- if fnmatch.fnmatch(f, include):
- filtered_java_files.append(f)
- break
- java_files = filtered_java_files
+ classpath, classes_dir, chromium_code, java_files):
+ """Runs javac.
+
+ Builds |java_files| with the provided |classpath| and puts the generated
+ .class files into |classes_dir|. If |chromium_code| is true, extra lint
+ checking will be enabled.
+ """
# Compiling guava with certain orderings of input files causes a compiler
# crash... Sorted order works, so use that.
# See https://code.google.com/p/guava-libraries/issues/detail?id=950
+ # TODO(cjhopman): Remove this when we have update guava or the compiler to a
+ # version without this problem.
java_files.sort()
- classpath = build_utils.ParseGypList(classpath)
jar_inputs = []
for path in classpath:
@@ -107,22 +106,32 @@ def DoJavac(
input_strings=javac_cmd)
-def main():
+def main(argv):
colorama.init()
+ argv = build_utils.ExpandFileArgs(argv)
+
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option(
'--src-gendirs',
help='Directories containing generated java files.')
- parser.add_option('--classpath', help='Classpath for javac.')
+ parser.add_option(
+ '--java-srcjars',
+ help='List of srcjars to include in compilation.')
+ parser.add_option(
+ '--classpath',
+ action='append',
+ help='Classpath for javac. If this is specified multiple times, they '
+ 'will all be appended to construct the classpath.')
parser.add_option(
'--javac-includes',
- help='A list of file patterns. If provided, only java files that match' +
+ help='A list of file patterns. If provided, only java files that match'
'one of the patterns will be compiled.')
parser.add_option(
'--jar-excluded-classes',
+ default='',
help='List of .class file patterns to exclude from the jar.')
parser.add_option(
@@ -138,17 +147,39 @@ def main():
parser.add_option('--stamp', help='Path to touch on success.')
- options, args = parser.parse_args()
+ options, args = parser.parse_args(argv)
+
+ classpath = []
+ for arg in options.classpath:
+ classpath += build_utils.ParseGypList(arg)
java_files = args
if options.src_gendirs:
src_gendirs = build_utils.ParseGypList(options.src_gendirs)
java_files += build_utils.FindInDirectories(src_gendirs, '*.java')
- with build_utils.TempDir() as classes_dir:
+ with build_utils.TempDir() as temp_dir:
+ classes_dir = os.path.join(temp_dir, 'classes')
+ os.makedirs(classes_dir)
+ if options.java_srcjars:
+ java_dir = os.path.join(temp_dir, 'java')
+ os.makedirs(java_dir)
+ for srcjar in build_utils.ParseGypList(options.java_srcjars):
+ build_utils.ExtractAll(srcjar, path=java_dir)
+ java_files += build_utils.FindInDirectory(java_dir, '*.java')
+
+ if options.javac_includes:
+ javac_includes = build_utils.ParseGypList(options.javac_includes)
+ filtered_java_files = []
+ for f in java_files:
+ for include in javac_includes:
+ if fnmatch.fnmatch(f, include):
+ filtered_java_files.append(f)
+ break
+ java_files = filtered_java_files
+
DoJavac(
- options.classpath,
- options.javac_includes,
+ classpath,
classes_dir,
options.chromium_code,
java_files)
@@ -170,13 +201,13 @@ def main():
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
- build_utils.GetPythonDependencies())
+ classpath + build_utils.GetPythonDependencies())
if options.stamp:
build_utils.Touch(options.stamp)
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(main(sys.argv[1:]))