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

Unified Diff: build/android/gyp/javac.py

Issue 328893003: Make javac and jar a single build action (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: build/android/gyp/javac.py
diff --git a/build/android/gyp/javac.py b/build/android/gyp/javac.py
index a0725cf8ee62722d4289cf163bb634fadb23490d..694dd3aeb42721619fda0c367bce8b3b61a4bf56 100755
--- a/build/android/gyp/javac.py
+++ b/build/android/gyp/javac.py
@@ -7,12 +7,15 @@
import fnmatch
import optparse
import os
+import shutil
import re
import sys
from util import build_utils
from util import md5_check
+import jar
+
sys.path.append(build_utils.COLORAMA_ROOT)
import colorama
@@ -49,14 +52,10 @@ def ColorJavacOutput(output):
return '\n'.join(map(ApplyColor, output.split('\n')))
-
-def DoJavac(options, args):
- output_dir = options.output_dir
-
- src_gendirs = build_utils.ParseGypList(options.src_gendirs)
- java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java')
- if options.javac_includes:
- javac_includes = build_utils.ParseGypList(options.javac_includes)
+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:
@@ -69,7 +68,7 @@ def DoJavac(options, args):
# crash... Sorted order works, so use that.
# See https://code.google.com/p/guava-libraries/issues/detail?id=950
java_files.sort()
- classpath = build_utils.ParseGypList(options.classpath)
+ classpath = build_utils.ParseGypList(classpath)
jar_inputs = []
for path in classpath:
@@ -83,8 +82,8 @@ def DoJavac(options, args):
'-source', '1.5',
'-target', '1.5',
'-classpath', ':'.join(classpath),
- '-d', output_dir]
- if options.chromium_code:
+ '-d', classes_dir]
+ if chromium_code:
javac_args.extend(['-Xlint:unchecked', '-Xlint:deprecation'])
else:
# XDignore.symbol.file makes javac compile against rt.jar instead of
@@ -95,19 +94,12 @@ def DoJavac(options, args):
javac_cmd = ['javac'] + javac_args + java_files
def Compile():
- # Delete the classes directory. This ensures that all .class files in the
- # output are actually from the input .java files. For example, if a .java
- # file is deleted or an inner class is removed, the classes directory should
- # not contain the corresponding old .class file after running this action.
- build_utils.DeleteDirectory(output_dir)
- build_utils.MakeDirectory(output_dir)
build_utils.CheckOutput(
javac_cmd,
- print_stdout=options.chromium_code,
+ print_stdout=chromium_code,
stderr_filter=ColorJavacOutput)
-
- record_path = '%s/javac.md5.stamp' % options.output_dir
+ record_path = os.path.join(classes_dir, 'javac.md5.stamp')
md5_check.CallAndRecordIfStale(
Compile,
record_path=record_path,
@@ -119,21 +111,59 @@ def main():
colorama.init()
parser = optparse.OptionParser()
- parser.add_option('--src-gendirs',
+ parser.add_option(
+ '--src-gendirs',
help='Directories containing generated java files.')
- parser.add_option('--javac-includes',
- help='A list of file patterns. If provided, only java files that match' +
- 'one of the patterns will be compiled.')
parser.add_option('--classpath', help='Classpath for javac.')
- parser.add_option('--output-dir', help='Directory for javac output.')
+ parser.add_option(
+ '--javac-includes',
+ 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',
+ help='List of .class file patterns to exclude from the jar.')
+
+ parser.add_option(
+ '--chromium-code',
+ type='int',
+ help='Whether code being compiled should be built with stricter '
+ 'warnings for chromium code.')
+
+ parser.add_option(
+ '--classes-dir',
+ help='Directory for compiled .class files.')
+ parser.add_option('--jar-path', help='Jar output path.')
+
parser.add_option('--stamp', help='Path to touch on success.')
- parser.add_option('--chromium-code', type='int', help='Whether code being '
- 'compiled should be built with stricter warnings for '
- 'chromium code.')
options, args = parser.parse_args()
- DoJavac(options, args)
+ 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:
+ DoJavac(
+ options.classpath,
+ options.javac_includes,
+ classes_dir,
+ options.chromium_code,
+ java_files)
+
+ if options.jar_path:
+ jar.JarDirectory(classes_dir,
+ build_utils.ParseGypList(options.jar_excluded_classes),
+ options.jar_path)
+
+ if options.classes_dir:
+ # Delete the old classes directory. This ensures that all .class files in
+ # the output are actually from the input .java files. For example, if a
+ # .java file is deleted or an inner class is removed, the classes
+ # directory should not contain the corresponding old .class file after
+ # running this action.
+ build_utils.DeleteDirectory(options.classes_dir)
+ shutil.copytree(classes_dir, options.classes_dir)
if options.stamp:
build_utils.Touch(options.stamp)

Powered by Google App Engine
This is Rietveld 408576698