Translate some ant to python
This moves java compilation, jar, and dex for apks from ant to python. This uses the same javac.py and jar.py that are used by build/java.gypi for libraries and introduces a simple dex.py. BUG=158821 Review URL: https://chromiumcodereview.appspot.com/12880007 git-svn-id: http://src.chromium.org/svn/trunk/src/build@190756 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
c08f3ae53c
Коммит
d63e35e839
|
@ -0,0 +1,146 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2005-2008 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<project default="-obfuscate">
|
||||
<property name="verbose" value="false" />
|
||||
<property name="out.dir" location="${OUT_DIR}" />
|
||||
<!-- Output directories -->
|
||||
<property name="out.dir" value="bin" />
|
||||
<property name="out.absolute.dir" location="${out.dir}" />
|
||||
<property name="out.classes.absolute.dir" location="${out.dir}/classes" />
|
||||
<property name="out.manifest.abs.file" location="${out.dir}/AndroidManifest.xml" />
|
||||
|
||||
<!-- tools location -->
|
||||
<property name="sdk.dir" location="${ANDROID_SDK_ROOT}"/>
|
||||
<property name="target" value="android-${ANDROID_SDK_VERSION}"/>
|
||||
<property name="android.tools.dir" location="${sdk.dir}/tools" />
|
||||
|
||||
|
||||
<!-- jar file from where the tasks are loaded -->
|
||||
<path id="android.antlibs">
|
||||
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
|
||||
</path>
|
||||
|
||||
<!-- Custom tasks -->
|
||||
<taskdef resource="anttasks.properties" classpathref="android.antlibs" />
|
||||
|
||||
<!-- Classpath for javac -->
|
||||
<path id="javac.custom.classpath">
|
||||
<filelist files="${INPUT_JARS_PATHS}"/>
|
||||
</path>
|
||||
|
||||
<condition property="project.is.testapp" value="true" else="false">
|
||||
<equals arg1="${IS_TEST_APK}" arg2="1" />
|
||||
</condition>
|
||||
|
||||
<property name="proguard.enabled" value="${PROGUARD_ENABLED}" />
|
||||
<property name="proguard.config" value="${PROGUARD_FLAGS}" />
|
||||
|
||||
<!-- Obfuscate target
|
||||
This is only active in release builds when proguard.config is defined
|
||||
in default.properties.
|
||||
|
||||
-->
|
||||
<!--
|
||||
Override obfuscate target to pass javac.custom.classpath to Proguard. SDK tools do not provide
|
||||
any way to pass custom class paths to Proguard.
|
||||
-->
|
||||
<target name="-obfuscate">
|
||||
<if condition="${project.is.testapp}">
|
||||
<then>
|
||||
<!-- get the project manifest package -->
|
||||
<xpath input="${out.manifest.abs.file}"
|
||||
expression="/manifest/@package" output="project.app.package" />
|
||||
<property name="create.test.jar.file"
|
||||
location="${CREATE_TEST_JAR_PATH}" />
|
||||
<script language="javascript" src="${create.test.jar.file}"/>
|
||||
</then>
|
||||
</if>
|
||||
<if condition="${proguard.enabled}">
|
||||
<then>
|
||||
<property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard"/>
|
||||
<property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar"/>
|
||||
<property name="obfuscated.jar.file" value="${OBFUSCATED_JAR_PATH}"/>
|
||||
<property name="obfuscated.jar.abs.file" location="${obfuscated.jar.file}"/>
|
||||
|
||||
<!-- Add Proguard Tasks -->
|
||||
<property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar"/>
|
||||
<taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}"/>
|
||||
|
||||
<!-- Set the android classpath Path object into a single property. It'll be
|
||||
all the jar files separated by a platform path-separator.
|
||||
Each path must be quoted if it contains spaces.
|
||||
-->
|
||||
<pathconvert property="project.target.classpath.value" refid="project.target.class.path">
|
||||
<firstmatchmapper>
|
||||
<regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
|
||||
<identitymapper/>
|
||||
</firstmatchmapper>
|
||||
</pathconvert>
|
||||
|
||||
<!-- Build a path object with all the jar files that must be obfuscated.
|
||||
This include the project compiled source code and any 3rd party jar
|
||||
files. -->
|
||||
<path id="project.all.classes.path">
|
||||
<pathelement location="${preobfuscate.jar.file}"/>
|
||||
<!-- Pass javac.custom.classpath for apks. -->
|
||||
<path refid="javac.custom.classpath"/>
|
||||
</path>
|
||||
<!-- Set the project jar files Path object into a single property. It'll be
|
||||
all the jar files separated by a platform path-separator.
|
||||
Each path must be quoted if it contains spaces.
|
||||
-->
|
||||
<pathconvert property="project.all.classes.value" refid="project.all.classes.path">
|
||||
<firstmatchmapper>
|
||||
<regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
|
||||
<identitymapper/>
|
||||
</firstmatchmapper>
|
||||
</pathconvert>
|
||||
|
||||
<!-- Turn the path property ${proguard.config} from an A:B:C property
|
||||
into a series of includes: -include A -include B -include C
|
||||
suitable for processing by the ProGuard task. Note - this does
|
||||
not include the leading '-include "' or the closing '"'; those
|
||||
are added under the <proguard> call below.
|
||||
-->
|
||||
<path id="proguard.configpath">
|
||||
<pathelement path="${proguard.config}"/>
|
||||
</path>
|
||||
<pathconvert pathsep='" -include "' property="proguard.configcmd"
|
||||
refid="proguard.configpath"/>
|
||||
|
||||
<mkdir dir="${obfuscate.absolute.dir}"/>
|
||||
<delete file="${preobfuscate.jar.file}"/>
|
||||
<delete file="${obfuscated.jar.abs.file}"/>
|
||||
<jar basedir="${out.classes.absolute.dir}"
|
||||
destfile="${preobfuscate.jar.file}"/>
|
||||
<proguard>
|
||||
-include "${proguard.configcmd}"
|
||||
-include "${out.absolute.dir}/proguard.txt"
|
||||
-injars ${project.all.classes.value}
|
||||
-outjars "${obfuscated.jar.abs.file}"
|
||||
-libraryjars ${project.target.classpath.value}
|
||||
-dump "${obfuscate.absolute.dir}/dump.txt"
|
||||
-printseeds "${obfuscate.absolute.dir}/seeds.txt"
|
||||
-printusage "${obfuscate.absolute.dir}/usage.txt"
|
||||
-printmapping "${obfuscate.absolute.dir}/mapping.txt"
|
||||
</proguard>
|
||||
</then>
|
||||
</if>
|
||||
<touch file="${STAMP}" />
|
||||
</target>
|
||||
</project>
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import fnmatch
|
||||
import optparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from pylib import build_utils
|
||||
|
||||
|
||||
def DoDex(options, paths):
|
||||
dx_binary = os.path.join(options.android_sdk_root, 'platform-tools', 'dx')
|
||||
dex_cmd = [dx_binary, '--dex', '--output', options.dex_path] + paths
|
||||
subprocess.check_call(dex_cmd)
|
||||
|
||||
|
||||
def main(argv):
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--android-sdk-root', help='Android sdk root directory.')
|
||||
parser.add_option('--dex-path', help='Dex output path.')
|
||||
parser.add_option('--stamp', help='Path to touch on success.')
|
||||
|
||||
# TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
|
||||
parser.add_option('--ignore', help='Ignored.')
|
||||
|
||||
options, paths = parser.parse_args()
|
||||
|
||||
DoDex(options, paths)
|
||||
|
||||
if options.stamp:
|
||||
build_utils.Touch(options.stamp)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
'javac_includes': [],
|
||||
'jar_name': '<(_target_name).jar',
|
||||
'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
|
||||
'excluded_classes': [ '*/R.class', '*/R##*.class' ],
|
||||
'jar_excluded_classes': [ '*/R.class', '*/R##*.class' ],
|
||||
'additional_input_paths': [],
|
||||
'generated_src_dirs': ['>@(generated_R_dirs)'],
|
||||
'generated_R_dirs': [],
|
||||
|
@ -170,7 +170,7 @@
|
|||
'message': 'Compiling <(_target_name) java sources',
|
||||
'variables': {
|
||||
'all_src_dirs': [
|
||||
'>@(java_in_dir)/src',
|
||||
'>(java_in_dir)/src',
|
||||
'>@(additional_src_dirs)',
|
||||
'>@(generated_src_dirs)',
|
||||
],
|
||||
|
@ -212,7 +212,7 @@
|
|||
'python', '<(DEPTH)/build/android/jar.py',
|
||||
'--classes-dir=<(classes_dir)',
|
||||
'--jar-path=<(jar_path)',
|
||||
'--excluded-classes=<(excluded_classes)',
|
||||
'--excluded-classes=<(jar_excluded_classes)',
|
||||
|
||||
# TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
|
||||
'--ignore=>!(echo \'>(_inputs)\' | md5sum)',
|
||||
|
|
121
java_apk.gypi
121
java_apk.gypi
|
@ -60,7 +60,7 @@
|
|||
'proguard_enabled%': 'false',
|
||||
'proguard_flags_path%': '<(DEPTH)/build/android/empty_proguard.flags',
|
||||
'native_libs_paths': [],
|
||||
'jar_name%': 'chromium_apk_<(_target_name).jar',
|
||||
'jar_name': 'chromium_apk_<(_target_name).jar',
|
||||
'resource_dir%':'<(DEPTH)/build/android/ant/empty/res',
|
||||
'R_package%':'',
|
||||
'additional_res_dirs': [],
|
||||
|
@ -73,11 +73,19 @@
|
|||
'asset_location%': '<(intermediate_dir)/assets',
|
||||
'codegen_stamp': '<(intermediate_dir)/codegen.stamp',
|
||||
'compile_stamp': '<(intermediate_dir)/compile.stamp',
|
||||
'jar_stamp': '<(intermediate_dir)/jar.stamp',
|
||||
'obfuscate_stamp': '<(intermediate_dir)/obfuscate.stamp',
|
||||
'classes_dir': '<(intermediate_dir)/classes',
|
||||
'javac_includes': [],
|
||||
'jar_excluded_classes': [],
|
||||
'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
|
||||
'obfuscated_jar_path': '<(intermediate_dir)/obfuscated.jar',
|
||||
'dex_path': '<(intermediate_dir)/classes.dex',
|
||||
'android_manifest': '<(java_in_dir)/AndroidManifest.xml',
|
||||
'codegen_input_paths': [],
|
||||
},
|
||||
'sources': [
|
||||
'<@(native_libs_paths)'
|
||||
'<@(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
|
||||
|
@ -196,21 +204,74 @@
|
|||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'ant_compile_<(_target_name)',
|
||||
'action_name': 'javac_<(_target_name)',
|
||||
'message': 'Compiling java for <(_target_name)',
|
||||
'variables': {
|
||||
'all_src_dirs': [
|
||||
'<(java_in_dir)/src',
|
||||
'<(intermediate_dir)/gen',
|
||||
'>@(additional_src_dirs)',
|
||||
'>@(generated_src_dirs)',
|
||||
],
|
||||
},
|
||||
'inputs': [
|
||||
'<(DEPTH)/build/android/ant/apk-compile.xml',
|
||||
'<(DEPTH)/build/android/ant/create-test-jar.js',
|
||||
'<(DEPTH)/build/android/pylib/build_utils.py',
|
||||
'<(DEPTH)/build/android/javac.py',
|
||||
# If there is a separate find for additional_src_dirs, it will find the
|
||||
# wrong .java files when additional_src_dirs is empty.
|
||||
'>!@(find >(java_in_dir) >(additional_src_dirs) -name "*.java")',
|
||||
'>@(input_jars_paths)',
|
||||
'<(codegen_stamp)',
|
||||
'<(proguard_flags_path)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(compile_stamp)',
|
||||
],
|
||||
'action': [
|
||||
'python', '<(DEPTH)/build/android/javac.py',
|
||||
'--output-dir=<(classes_dir)',
|
||||
'--classpath=>(input_jars_paths) <(android_sdk_jar)',
|
||||
'--src-dirs=>(all_src_dirs)',
|
||||
'--javac-includes=<(javac_includes)',
|
||||
'--stamp=<(compile_stamp)',
|
||||
|
||||
# TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
|
||||
'--ignore=>!(echo \'>(_inputs)\' | md5sum)',
|
||||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'jar_<(_target_name)',
|
||||
'message': 'Creating <(_target_name) jar',
|
||||
'inputs': [
|
||||
'<(DEPTH)/build/android/pylib/build_utils.py',
|
||||
'<(DEPTH)/build/android/jar.py',
|
||||
'<(compile_stamp)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(jar_stamp)',
|
||||
],
|
||||
'action': [
|
||||
'python', '<(DEPTH)/build/android/jar.py',
|
||||
'--classes-dir=<(classes_dir)',
|
||||
'--jar-path=<(jar_path)',
|
||||
'--excluded-classes=<(jar_excluded_classes)',
|
||||
'--stamp=<(jar_stamp)',
|
||||
|
||||
# TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
|
||||
'--ignore=>!(echo \'>(_inputs)\' | md5sum)',
|
||||
]
|
||||
},
|
||||
{
|
||||
'action_name': 'ant_obfuscate_<(_target_name)',
|
||||
'message': 'Obfuscating <(_target_name)',
|
||||
'inputs': [
|
||||
'<(DEPTH)/build/android/ant/apk-obfuscate.xml',
|
||||
'<(DEPTH)/build/android/ant/create-test-jar.js',
|
||||
'<(compile_stamp)',
|
||||
'<(proguard_flags_path)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(obfuscate_stamp)',
|
||||
],
|
||||
'action': [
|
||||
'ant', '-quiet',
|
||||
'-DADDITIONAL_SRC_DIRS=>(additional_src_dirs)',
|
||||
|
@ -223,16 +284,16 @@
|
|||
'-DINPUT_JARS_PATHS=>(input_jars_paths)',
|
||||
'-DIS_TEST_APK=<(is_test_apk)',
|
||||
'-DJAR_PATH=<(PRODUCT_DIR)/lib.java/<(jar_name)',
|
||||
'-DOBFUSCATED_JAR_PATH=<(obfuscated_jar_path)',
|
||||
'-DOUT_DIR=<(intermediate_dir)',
|
||||
'-DPROGUARD_ENABLED=<(proguard_enabled)',
|
||||
'-DPROGUARD_FLAGS=<(proguard_flags_path)',
|
||||
'-DSOURCE_DIR=<(java_in_dir)/src',
|
||||
'-DTEST_JAR_PATH=<(PRODUCT_DIR)/test.lib.java/<(apk_name).jar',
|
||||
|
||||
'-DSTAMP=<(compile_stamp)',
|
||||
'-DSTAMP=<(obfuscate_stamp)',
|
||||
'-Dbasedir=.',
|
||||
'-buildfile',
|
||||
'<(DEPTH)/build/android/ant/apk-compile.xml',
|
||||
'<(DEPTH)/build/android/ant/apk-obfuscate.xml',
|
||||
|
||||
# Add list of inputs to the command line, so if inputs change
|
||||
# (e.g. if a Java file is removed), the command will be re-run.
|
||||
|
@ -240,6 +301,45 @@
|
|||
'-DTHIS_IS_IGNORED=>!(echo \'>(_inputs)\' | md5sum)',
|
||||
],
|
||||
},
|
||||
{
|
||||
'action_name': 'dex_<(_target_name)',
|
||||
'message': 'Dexing <(_target_name) jar',
|
||||
'variables': {
|
||||
'conditions': [
|
||||
['proguard_enabled==1', {
|
||||
'dex_inputs': [ '<(obfuscated_jar_path)' ],
|
||||
'dex_generated_inputs': [],
|
||||
}, {
|
||||
'dex_inputs': [
|
||||
'>@(input_jars_paths)',
|
||||
],
|
||||
'dex_generated_inputs': [
|
||||
'<(classes_dir)',
|
||||
],
|
||||
}],
|
||||
],
|
||||
},
|
||||
'inputs': [
|
||||
'<(DEPTH)/build/android/pylib/build_utils.py',
|
||||
'<(DEPTH)/build/android/dex.py',
|
||||
'<(compile_stamp)',
|
||||
'>@(dex_inputs)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(dex_path)',
|
||||
],
|
||||
'action': [
|
||||
'python', '<(DEPTH)/build/android/dex.py',
|
||||
'--dex-path=<(dex_path)',
|
||||
'--android-sdk-root=<(android_sdk_root)',
|
||||
|
||||
# TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
|
||||
'--ignore=>!(echo >(_inputs) | md5sum)',
|
||||
|
||||
'>@(dex_inputs)',
|
||||
'>@(dex_generated_inputs)',
|
||||
]
|
||||
},
|
||||
{
|
||||
'action_name': 'ant_package_<(_target_name)',
|
||||
'message': 'Packaging <(_target_name).',
|
||||
|
@ -247,8 +347,9 @@
|
|||
'<(DEPTH)/build/android/ant/apk-package.xml',
|
||||
#TODO(cjhopman): this should be the stripped library paths.
|
||||
'>@(native_libs_paths)',
|
||||
'<(dex_path)',
|
||||
'<(codegen_stamp)',
|
||||
'<(compile_stamp)',
|
||||
'<(obfuscate_stamp)',
|
||||
],
|
||||
'conditions': [
|
||||
['is_test_apk == 1', {
|
||||
|
|
Загрузка…
Ссылка в новой задаче