Index: build/android/gyp/javac.py |
diff --git a/build/android/gyp/javac.py b/build/android/gyp/javac.py |
index dcbc48b0fc489f8ee9a8120edf2993973360ce84..4e7997c5a590a7a768ad26c3c9572bbc1fd34a48 100755 |
--- a/build/android/gyp/javac.py |
+++ b/build/android/gyp/javac.py |
@@ -10,6 +10,7 @@ import os |
import shutil |
import re |
import sys |
+import textwrap |
from util import build_utils |
from util import md5_check |
@@ -106,6 +107,43 @@ def DoJavac( |
input_strings=javac_cmd) |
+_MAX_MANIFEST_LINE_LEN = 72 |
+ |
+ |
+def CreateManifest(manifest_path, classpath, main_class=None): |
+ """Creates a manifest file with the given parameters. |
+ |
+ This generates a manifest file that compiles with the spec found at |
+ http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifest |
+ |
+ Args: |
+ manifest_path: The path to the manifest file that should be created. |
+ classpath: The JAR files that should be listed on the manifest file's |
+ classpath. |
+ main_class: If present, the class containing the main() function. |
+ |
+ """ |
+ output = ['Manifest-Version: 1.0'] |
+ if main_class: |
+ output.append('Main-Class: %s' % main_class) |
+ if classpath: |
+ sanitized_paths = [] |
+ for path in classpath: |
+ sanitized_paths.append(os.path.basename(path.strip('"'))) |
+ output.append('Class-Path: %s' % ' '.join(sanitized_paths)) |
+ output.append('Created-By: ') |
+ output.append('') |
+ |
+ wrapper = textwrap.TextWrapper(break_long_words=True, |
+ drop_whitespace=False, |
+ subsequent_indent=' ', |
+ width=_MAX_MANIFEST_LINE_LEN - 2) |
+ output = '\r\n'.join(w for l in output for w in wrapper.wrap(l)) |
+ |
+ with open(manifest_path, 'w') as f: |
+ f.write(output) |
+ |
+ |
def main(argv): |
colorama.init() |
@@ -146,11 +184,17 @@ def main(argv): |
'--classes-dir', |
help='Directory for compiled .class files.') |
parser.add_option('--jar-path', help='Jar output path.') |
+ parser.add_option( |
+ '--main-class', |
+ help='The class containing the main method.') |
parser.add_option('--stamp', help='Path to touch on success.') |
options, args = parser.parse_args(argv) |
+ if options.main_class and not options.jar_path: |
+ parser.error('--main-class requires --jar-path') |
+ |
classpath = [] |
for arg in options.classpath: |
classpath += build_utils.ParseGypList(arg) |
@@ -192,9 +236,16 @@ def main(argv): |
java_files) |
if options.jar_path: |
+ if options.main_class: |
+ manifest_file = os.path.join(temp_dir, 'manifest') |
+ CreateManifest(manifest_file, classpath, |
+ options.main_class) |
+ else: |
+ manifest_file = None |
jar.JarDirectory(classes_dir, |
build_utils.ParseGypList(options.jar_excluded_classes), |
- options.jar_path) |
+ options.jar_path, |
+ manifest_file=manifest_file) |
if options.classes_dir: |
# Delete the old classes directory. This ensures that all .class files in |