am b57c64fa: Merge change 25008 into eclair

Merge commit 'b57c64fa71d211bafc41e08fbd020a41d5027783' into eclair-plus-aosp

* commit 'b57c64fa71d211bafc41e08fbd020a41d5027783':
  Reorganize android_rules and android_test_rules
This commit is contained in:
Piotr Gurgul
2009-09-15 16:08:35 -07:00
committed by Android Git Automerger
2 changed files with 175 additions and 138 deletions

View File

@@ -40,11 +40,6 @@
<property name="external.libs.dir" value="libs" /> <property name="external.libs.dir" value="libs" />
<property name="external.libs.absolute.dir" location="${external.libs.dir}" /> <property name="external.libs.absolute.dir" location="${external.libs.dir}" />
<!-- In this file it is just alias for external.libs.absolute.dir. It is used for
reusability though, when calling ant targets in this file from other files.
However, it is a temporary solution. -->
<property name="external.jars" location="${external.libs.absolute.dir}" />
<!-- Directory for the native libraries --> <!-- Directory for the native libraries -->
<property name="native.libs.dir" value="libs" /> <property name="native.libs.dir" value="libs" />
<property name="native.libs.absolute.dir" location="${native.libs.dir}" /> <property name="native.libs.absolute.dir" location="${native.libs.dir}" />
@@ -52,7 +47,7 @@
<!-- Output directories --> <!-- Output directories -->
<property name="out.dir" value="bin" /> <property name="out.dir" value="bin" />
<property name="out.absolute.dir" location="${out.dir}" /> <property name="out.absolute.dir" location="${out.dir}" />
<property name="out.classes.dir" value="${out.dir}/classes" /> <property name="out.classes.dir" value="${out.absolute.dir}/classes" />
<property name="out.classes.absolute.dir" location="${out.classes.dir}" /> <property name="out.classes.absolute.dir" location="${out.classes.dir}" />
<!-- Intermediate files --> <!-- Intermediate files -->
@@ -62,17 +57,102 @@
<!-- The final package file to generate --> <!-- The final package file to generate -->
<property name="out.debug.unaligned.package" <property name="out.debug.unaligned.package"
location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" /> location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
<property name="out.debug.package" location="${out.absolute.dir}/${ant.project.name}-debug.apk" /> <property name="out.debug.package"
<property name="out.unsigned.package" location="${out.absolute.dir}/${ant.project.name}-unsigned.apk" /> location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
<property name="out.unsigned.package"
location="${out.absolute.dir}/${ant.project.name}-unsigned.apk" />
<property name="out.unaligned.package" <property name="out.unaligned.package"
location="${out.absolute.dir}/${ant.project.name}-unaligned.apk" /> location="${out.absolute.dir}/${ant.project.name}-unaligned.apk" />
<property name="out.release.package" location="${out.absolute.dir}/${ant.project.name}-release.apk" /> <property name="out.release.package"
location="${out.absolute.dir}/${ant.project.name}-release.apk" />
<!-- Tools --> <!-- Tools -->
<condition property="exe" value=".exe" else=""><os family="windows" /></condition> <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
<property name="adb" location="${android.tools.dir}/adb${exe}" /> <property name="adb" location="${android.tools.dir}/adb${exe}" />
<property name="zipalign" location="${android.tools.dir}/zipalign${exe}" /> <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
<!-- Emma configuration -->
<property name="emma.dir" value="${sdk.dir}/tools/lib" />
<path id="emma.lib">
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
</path>
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
<!-- End of emma configuration -->
<!-- Macros -->
<!-- Configurable macro, which allows to pass as parameters output directory,
output dex filename and external libraries to dex (optional) -->
<macrodef name="dex-helper">
<element name="external-libs" optional="yes" />
<sequential>
<echo>Converting compiled files and external libraries into ${intermediate.dex.file}...
</echo>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=${intermediate.dex.file}" />
<arg path="${out.classes.absolute.dir}" />
<fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
<external-libs />
</apply>
</sequential>
</macrodef>
<!-- This is macro that enable passing variable list of external jar files to ApkBuilder
Example of use:
<package-helper>
<extra-jars>
<jarfolder path="my_jars" />
<jarfile path="foo/bar.jar" />
<jarfolder path="your_jars" />
</extra-jars>
</package-helper> -->
<macrodef name="package-helper">
<element name="extra-jars" optional="yes" />
<sequential>
<apkbuilder
outfolder="${out.absolute.dir}"
basename="${ant.project.name}"
signed="${sign.package}"
verbose="true">
<file path="${intermediate.dex.file}" />
<sourcefolder path="${source.absolute.dir}" />
<nativefolder path="${native.libs.absolute.dir}" />
<jarfolder path="${external.libs.absolute.dir}" />
<extra-jars/>
</apkbuilder>
</sequential>
</macrodef>
<!-- This is macro used only for sharing code among two targets, -debug and
-debug-with-emma which do exactly the same but differ in dependencies -->
<macrodef name="debug-helper">
<sequential>
<echo>Running zip align on final apk...</echo>
<exec executable="${zipalign}" failonerror="true">
<arg value="-f" />
<arg value="4" />
<arg path="${out.debug.unaligned.package}" />
<arg path="${out.debug.package}" />
</exec>
<echo>Debug Package: ${out.debug.package}</echo>
</sequential>
</macrodef>
<!-- This is macro used only for sharing code among two targets, -install and
-install-with-emma which do exactly the same but differ in dependencies -->
<macrodef name="install-helper">
<sequential>
<echo>Installing ${out.debug.package} onto default emulator or device...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="install" />
<arg value="-r" />
<arg path="${out.debug.package}" />
</exec>
</sequential>
</macrodef>
<!-- Rules --> <!-- Rules -->
<!-- Creates the output directories if they don't exist yet. --> <!-- Creates the output directories if they don't exist yet. -->
@@ -134,32 +214,9 @@
</javac> </javac>
</target> </target>
<!-- Configurable macro, which allows to pass as parameters output directory,
output dex filename and external libraries to dex (optional) -->
<macrodef name="dex-helper">
<attribute name="out.absolute.dir" />
<attribute name="out.dex.file" />
<element name="external-libs" optional="yes" />
<sequential>
<echo>Converting compiled files and external libraries into @{out.dex.file}...</echo>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=@{out.dex.file}" />
<arg path="@{out.absolute.dir}" />
<external-libs />
</apply>
</sequential>
</macrodef>
<!-- Converts this project's .class files into .dex files --> <!-- Converts this project's .class files into .dex files -->
<target name="-dex" depends="compile"> <target name="-dex" depends="compile">
<dex-helper out.absolute.dir="${out.absolute.dir}/classes" <dex-helper />
out.dex.file="${intermediate.dex.file}">
<external-libs>
<!-- Temporary solution, before <jarfile> in <apkbuilder> is ready -->
<fileset dir="${external.jars}" includes="*.jar" />
</external-libs>
</dex-helper>
</target> </target>
<!-- Puts the project's resources into the output package file <!-- Puts the project's resources into the output package file
@@ -181,17 +238,8 @@
<!-- Packages the application and (maybe) sign it with a debug key. <!-- Packages the application and (maybe) sign it with a debug key.
This requires the property sign.package to be set to true or false. --> This requires the property sign.package to be set to true or false. -->
<target name="-package"> <target name="-package" depends="-dex, -package-resources">
<apkbuilder <package-helper />
outfolder="${out.absolute.dir}"
basename="${ant.project.name}"
signed="${sign.package}"
verbose="true">
<file path="${intermediate.dex.file}" />
<sourcefolder path="${source.absolute.dir}" />
<jarfolder path="${external.jars}" />
<nativefolder path="${native.libs.absolute.dir}" />
</apkbuilder>
</target> </target>
<target name="-no-sign"> <target name="-no-sign">
@@ -203,21 +251,12 @@
</target> </target>
<!-- Builds debug output package, provided all the necessary files are already dexed --> <!-- Builds debug output package, provided all the necessary files are already dexed -->
<target name="-debug-no-dex" depends="-package-resources, -debug-sign, -package"> <target name="debug" depends="-debug-sign, -package"
<echo>Running zip align on final apk...</echo> description="Builds the application and signs it with a debug key.">
<exec executable="${zipalign}" failonerror="true"> <debug-helper />
<arg value="-f" />
<arg value="4" />
<arg path="${out.debug.unaligned.package}" />
<arg path="${out.debug.package}" />
</exec>
<echo>Debug Package: ${out.debug.package}</echo>
</target> </target>
<target name="debug" depends="-dex, -debug-no-dex" <target name="-release-package" depends="-no-sign, -package" />
description="Builds the application and signs it with a debug key." />
<target name="-release-package" depends="-dex, -package-resources, -no-sign, -package" />
<target name="-release-check"> <target name="-release-check">
<condition property="release.sign"> <condition property="release.sign">
@@ -234,7 +273,7 @@
<echo>and run zipalign from the Android SDK tools.</echo> <echo>and run zipalign from the Android SDK tools.</echo>
</target> </target>
<target name="release" depends="-release-package, -release-nosign" if="release-sign" <target name="release" depends="-release-package, -release-nosign" if="release.sign"
description="Builds the application. The generated apk file must be signed before description="Builds the application. The generated apk file must be signed before
it is published."> it is published.">
<!-- Gets passwords --> <!-- Gets passwords -->
@@ -266,22 +305,12 @@
<echo>Release Package: ${out.release.package}</echo> <echo>Release Package: ${out.release.package}</echo>
</target> </target>
<!-- Installs the package on the default emulator/device --> <target name="install" depends="debug"
<target name="-install-no-deps">
<echo>Installing ${out.debug.package} onto default emulator or device...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="install" />
<arg value="-r" />
<arg path="${out.debug.package}" />
</exec>
</target>
<target name="install" depends="debug, -install-no-deps"
description="Installs/reinstalls the debug package onto a running description="Installs/reinstalls the debug package onto a running
emulator or device. If the application was previously installed, emulator or device. If the application was previously installed,
the signatures must match." /> the signatures must match." >
<install-helper />
<target name="-install-no-dex" depends="-debug-no-dex, -install-no-deps" /> </target>
<target name="-uninstall-check"> <target name="-uninstall-check">
<condition property="uninstall.run"> <condition property="uninstall.run">
@@ -290,8 +319,7 @@
</target> </target>
<target name="-uninstall-error" depends="-uninstall-check" unless="uninstall.run"> <target name="-uninstall-error" depends="-uninstall-check" unless="uninstall.run">
<echo> <echo>Unable to run 'ant uninstall', application.package is not defined in build.properties
Unable to run 'ant uninstall', application.package is not defined in build.properties
</echo> </echo>
</target> </target>
@@ -310,6 +338,53 @@
<delete dir="${gen.absolute.dir}" /> <delete dir="${gen.absolute.dir}" />
</target> </target>
<!-- Targets for code-coverage measurement purposes, invoked from external file -->
<!-- Emma-instruments tested project classes (compiles the tested project if necessary)
and writes instrumented classes to ${instrumentation.absolute.dir}/classes -->
<target name="-emma-instrument" depends="compile">
<echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
<!-- It only instruments class files, not any external libs -->
<emma enabled="true">
<instr verbosity="verbose"
mode="overwrite"
instrpath="${out.absolute.dir}/classes"
outdir="${out.absolute.dir}/classes">
</instr>
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
user defined file -->
</emma>
</target>
<target name="-dex-instrumented" depends="-emma-instrument">
<dex-helper>
<external-libs>
<fileset file="${emma.dir}/emma_device.jar" />
</external-libs>
</dex-helper>
</target>
<!-- Invoked from external files for code coverage purposes -->
<target name="-package-with-emma" depends="-dex-instrumented, -package-resources">
<package-helper>
<extra-jars>
<!-- Injected from external file -->
<jarfile path="${emma.dir}/emma_device.jar" />
</extra-jars>
</package-helper>
</target>
<target name="-debug-with-emma"
depends="-debug-sign, -package-with-emma">
<debug-helper />
</target>
<target name="-install-with-emma" depends="-debug-with-emma">
<install-helper />
</target>
<!-- End of targets for code-coverage measurement purposes -->
<target name="help"> <target name="help">
<!-- displays starts at col 13 <!-- displays starts at col 13
|13 80| --> |13 80| -->

View File

@@ -3,77 +3,17 @@
<import file="android_rules.xml" /> <import file="android_rules.xml" />
<!-- Existence of this property in build.properties or build.xml is an assertion for the test
project
<property name="tested.project.dir" value=".." /> -->
<property name="tested.project.absolute.dir" location="${tested.project.dir}" /> <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
<property name="instrumentation.dir" value="instru" /> <property name="instrumentation.dir" value="instrumented" />
<property name="instrumentation.absolute.dir" location="${instrumentation.dir}" /> <property name="instrumentation.absolute.dir" location="${instrumentation.dir}" />
<property name="test.runner" value="android.test.InstrumentationTestRunner" /> <property name="test.runner" value="android.test.InstrumentationTestRunner" />
<property name="application.package.to.instrument" value="${application.package}.tests" /> <property name="application.package.to.instrument" value="${application.package}.tests" />
<!-- Enables adding tested project classes location to test project classpath -->
<property name="extensible.classpath" value="${tested.project.absolute.dir}/bin/classes" />
<!-- TODO: make it more configurable in the next CL's - now it is default for auto-generated <!-- TODO: make it more configurable in the next CL's - now it is default for auto-generated
project --> project -->
<property name="emma.dump.file" value="/data/data/${application.package}/files/coverage.ec" /> <property name="emma.dump.file" value="/data/data/${application.package}/files/coverage.ec" />
<!-- Emma configuration -->
<property name="emma.dir" value="${sdk.dir}/tools/lib" />
<path id="emma.lib">
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
</path>
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
<!-- End of emma configuration -->
<!-- Runs 'compile' target for tested project -->
<target name="-compile-tested-project">
<subant target="compile">
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
</target>
<!-- Emma-instruments tested project classes (compiles the tested project if necessary)
and writes instrumented classes to ${instrumentation.absolute.dir}/classes -->
<target name="-emma-instrument" depends="-compile-tested-project">
<echo>Instrumenting classes from ${instrumentation.dir}/${out.dir}/classes...</echo>
<!-- It only instruments class files, not any external libs -->
<emma enabled="true">
<instr verbosity="verbose"
mode="copy"
instrpath="${tested.project.absolute.dir}/${out.dir}/classes"
outdir="${instrumentation.absolute.dir}/classes">
</instr>
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
user defined file -->
</emma>
</target>
<!-- Dexes emma-instrumented classes -->
<target name="-dex-instrumented" depends="-emma-instrument">
<dex-helper out.absolute.dir="${instrumentation.absolute.dir}/classes"
out.dex.file="${instrumentation.absolute.dir}/${dex.file.name}">
<external-libs>
<fileset dir="${external.libs.dir}" includes="*.jar" />
<fileset dir="${emma.dir}">
<include name="emma_device.jar" />
</fileset>
</external-libs>
</dex-helper>
</target>
<!-- Installs instrumented package on the default emulator/device -->
<target name="-install-instrumented" depends="-dex-instrumented">
<subant target="-install-no-dex">
<property name="out.absolute.dir" value="${instrumentation.absolute.dir}" />
<property name="external.jars" location="${emma.dir}/emma_device.jar" />
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
</target>
<macrodef name="run-tests-helper"> <macrodef name="run-tests-helper">
<attribute name="emma.enabled" default="false" /> <attribute name="emma.enabled" default="false" />
<sequential> <sequential>
@@ -91,6 +31,20 @@
</sequential> </sequential>
</macrodef> </macrodef>
<!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
classpath in target 'compile' (android_rules.xml) -->
<target name="-set-coverage-classpath">
<property name="extensible.classpath"
location="${instrumentation.absolute.dir}/classes" />
</target>
<!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
classpath in target 'compile' (android_rules.xml) -->
<target name="-set-run-tests-classpath">
<property name="extensible.classpath"
location="${tested.project.absolute.dir}/bin/classes" />
</target>
<!-- Ensures that tested project is installed on the device before we run the tests. <!-- Ensures that tested project is installed on the device before we run the tests.
Used for ordinary tests, without coverage measurement --> Used for ordinary tests, without coverage measurement -->
<target name="-install-tested-project"> <target name="-install-tested-project">
@@ -99,13 +53,21 @@
</subant> </subant>
</target> </target>
<target name="run-tests" depends="-install-tested-project, install" <target name="run-tests" depends="-set-run-tests-classpath, -install-tested-project, install"
description="Runs tests from the package defined in test.package property"> description="Runs tests from the package defined in test.package property">
<run-tests-helper /> <run-tests-helper />
</target> </target>
<target name="coverage" depends="-install-instrumented, install" <target name="-install-instrumented">
description="Runs test on instrumented code and generates code coverage report"> <subant target="-install-with-emma">
<property name="out.absolute.dir" value="${instrumentation.absolute.dir}" />
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
</target>
<target name="coverage" depends="-set-coverage-classpath, -install-instrumented, install"
description="Runs the tests against the instrumented code and generates
code coverage report">
<run-tests-helper emma.enabled="true" /> <run-tests-helper emma.enabled="true" />
<echo>Downloading coverage file into project directory...</echo> <echo>Downloading coverage file into project directory...</echo>
<exec executable="${adb}" failonerror="true"> <exec executable="${adb}" failonerror="true">