From dacd1ae54cf6959a7fa01361475b711475bcebb9 Mon Sep 17 00:00:00 2001 From: "cjhopman@chromium.org" Date: Tue, 2 Apr 2013 03:23:14 +0000 Subject: [PATCH] Convert native strip from rule to action First, this allows us to correctly have the output of the copy/strip action be an input to the apk package action. Second, this step now uses the list of libraries created by ordered libraries step. This is required to support the component build where we can not manually list the required libraries. BUG=158821 Review URL: https://chromiumcodereview.appspot.com/13058003 git-svn-id: http://src.chromium.org/svn/trunk/src/build@191754 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- android/strip_library_for_apk.py | 22 ++++++++++--- java_apk.gypi | 56 ++++++++++++++++---------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/android/strip_library_for_apk.py b/android/strip_library_for_apk.py index 9b526484f..59c1ae141 100755 --- a/android/strip_library_for_apk.py +++ b/android/strip_library_for_apk.py @@ -4,6 +4,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import json import optparse import os import sys @@ -25,19 +26,32 @@ def main(argv): help='Path to the toolchain\'s strip binary') parser.add_option('--android-strip-arg', action='append', help='Argument to be passed to strip') + parser.add_option('--libraries-dir', + help='Directory for un-stripped libraries') parser.add_option('--stripped-libraries-dir', help='Directory for stripped libraries') + parser.add_option('--libraries-file', + help='Path to json file containing list of libraries') + parser.add_option('--stamp', help='Path to touch on success') - options, paths = parser.parse_args() + + options, _ = parser.parse_args() + + with open(options.libraries_file, 'r') as libfile: + libraries = json.load(libfile) build_utils.MakeDirectory(options.stripped_libraries_dir) - for library_path in paths: - stripped_library_path = os.path.join(options.stripped_libraries_dir, - os.path.basename(library_path)) + for library in libraries: + library_path = os.path.join(options.libraries_dir, library) + stripped_library_path = os.path.join( + options.stripped_libraries_dir, library) StripLibrary(options.android_strip, options.android_strip_arg, library_path, stripped_library_path) + if options.stamp: + build_utils.Touch(options.stamp) + if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/java_apk.gypi b/java_apk.gypi index d1ea1cdc1..0a1122df5 100644 --- a/java_apk.gypi +++ b/java_apk.gypi @@ -74,6 +74,7 @@ 'asset_location%': '<(intermediate_dir)/assets', 'codegen_stamp': '<(intermediate_dir)/codegen.stamp', 'compile_input_paths': [ ], + 'package_input_paths': [ ], 'ordered_libraries_file': '<(intermediate_dir)/native_libraries.json', # TODO(cjhopman): build/ shouldn't refer to content/. The libraryloader and # nativelibraries template should be moved out of content/ (to base/?). @@ -88,6 +89,7 @@ 'compile_stamp': '<(intermediate_dir)/compile.stamp', 'jar_stamp': '<(intermediate_dir)/jar.stamp', 'obfuscate_stamp': '<(intermediate_dir)/obfuscate.stamp', + 'strip_stamp': '<(intermediate_dir)/strip.stamp', 'classes_dir': '<(intermediate_dir)/classes', 'javac_includes': [], 'jar_excluded_classes': [], @@ -97,9 +99,6 @@ 'android_manifest': '<(java_in_dir)/AndroidManifest.xml', 'codegen_input_paths': [], }, - 'sources': [ - '<@(native_libs_paths)', - ], # Pass the jar path to the apk's "fake" jar target. This would be better as # direct_dependent_settings, but a variable set by a direct_dependent_settings # cannot be lifted in a dependent to all_dependent_settings. @@ -108,29 +107,6 @@ 'apk_output_jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)', }, }, - 'rules': [ - { - 'rule_name': 'copy_and_strip_native_libraries', - 'extension': 'so', - 'variables': { - 'apk_libraries_dir': '<(intermediate_dir)/libs/<(android_app_abi)', - 'stripped_library_path': '<(apk_libraries_dir)/<(RULE_INPUT_ROOT).so', - }, - 'inputs': [ - '<(DEPTH)/build/android/strip_library_for_apk.py', - ], - 'outputs': [ - '<(stripped_library_path)', - ], - 'action': [ - 'python', '<(DEPTH)/build/android/strip_library_for_apk.py', - '--android-strip=<(android_strip)', - '--android-strip-arg=--strip-unneeded', - '--stripped-libraries-dir=<(apk_libraries_dir)', - '<(RULE_INPUT_PATH)', - ], - }, - ], 'conditions': [ ['resource_dir!=""', { 'variables': { @@ -150,6 +126,7 @@ 'variables': { 'compile_input_paths': [ '<(native_libraries_java_stamp)' ], 'generated_src_dirs': [ '<(native_libraries_java_dir)' ], + 'package_input_paths': [ '<(strip_stamp)' ], }, 'actions': [ { @@ -207,6 +184,30 @@ '--stamp=<(native_libraries_java_stamp)', ], }, + { + 'action_name': 'strip_native_libraries', + 'message': 'Stripping libraries for <(_target_name)', + 'variables': { + 'apk_libraries_dir': '<(intermediate_dir)/libs/<(android_app_abi)', + }, + 'inputs': [ + '<(DEPTH)/build/android/pylib/build_utils.py', + '<(DEPTH)/build/android/strip_library_for_apk.py', + '<(ordered_libraries_file)' + ], + 'outputs': [ + '<(strip_stamp)', + ], + 'action': [ + 'python', '<(DEPTH)/build/android/strip_library_for_apk.py', + '--android-strip=<(android_strip)', + '--android-strip-arg=--strip-unneeded', + '--stripped-libraries-dir=<(apk_libraries_dir)', + '--libraries-dir=<(SHARED_LIB_DIR)', + '--libraries-file=<(ordered_libraries_file)', + '--stamp=<(strip_stamp)', + ], + }, ], }], # native_libs_paths != [] ['java_strings_grd != ""', { @@ -424,11 +425,10 @@ 'message': 'Packaging <(_target_name).', 'inputs': [ '<(DEPTH)/build/android/ant/apk-package.xml', - #TODO(cjhopman): this should be the stripped library paths. - '>@(native_libs_paths)', '<(dex_path)', '<(codegen_stamp)', '<(obfuscate_stamp)', + '>@(package_input_paths)', ], 'conditions': [ ['is_test_apk == 1', {