summaryrefslogtreecommitdiffstats
path: root/build/android
diff options
context:
space:
mode:
authorshashishekhar@chromium.org <shashishekhar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-19 18:19:18 +0000
committershashishekhar@chromium.org <shashishekhar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-19 18:19:18 +0000
commit218b2f4a7766755e64120927d972d47cf95d35c2 (patch)
treed8a8fd59c36ecbd4a073142541bb2d328bee802e /build/android
parentd2e93ec8abd0e35820b1c671aa8a1b20316e3813 (diff)
downloadchromium_src-218b2f4a7766755e64120927d972d47cf95d35c2.zip
chromium_src-218b2f4a7766755e64120927d972d47cf95d35c2.tar.gz
chromium_src-218b2f4a7766755e64120927d972d47cf95d35c2.tar.bz2
Add test jar generation logic for ant builds.
Add a new property generate.test.jar to ant scripts. When this property is set, a jar containing all compiled classes and referred classes is generated and placed in out/{Debug|Release}/test.lib.java directory. This makes it easier and cleaner to write ant build files for test apks. New directory structure for the build: Apks are placed in : out/{Debug|Release}/apks All java libraries in : out/{Debug|Release}/lib.java All test java libraries in : out/{Debug|Release}/test.lib.java This CL also includes cleanup to work with the modified output directory structure. BUG=146583 Review URL: https://chromiumcodereview.appspot.com/10905138 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157570 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android')
-rwxr-xr-xbuild/android/adb_install_content_shell3
-rw-r--r--build/android/ant/chromium-jars.xml19
-rw-r--r--build/android/ant/common.xml12
-rw-r--r--build/android/ant/create-test-jar.js70
-rw-r--r--build/android/ant/sdk-targets.xml19
-rwxr-xr-xbuild/android/buildbot/buildbot_functions.sh2
-rw-r--r--build/android/pylib/constants.py4
-rw-r--r--build/android/pylib/test_options_parser.py15
8 files changed, 119 insertions, 25 deletions
diff --git a/build/android/adb_install_content_shell b/build/android/adb_install_content_shell
index fd883cc..1af1df4 100755
--- a/build/android/adb_install_content_shell
+++ b/build/android/adb_install_content_shell
@@ -11,12 +11,13 @@ import sys
from pylib import android_commands
from pylib import test_options_parser
+from pylib import constants
def InstallContentShell(device, build_type):
apk_path = os.path.join(os.environ['CHROME_SRC'],
'out', build_type,
- 'content_shell', 'ContentShell-debug.apk')
+ constants.SDK_BUILD_APKS_DIR, 'ContentShell-debug.apk')
result = android_commands.AndroidCommands(device=device).ManagedInstall(
apk_path, False, 'org.chromium.content_shell')
print '----- Installed on %s -----' % device
diff --git a/build/android/ant/chromium-jars.xml b/build/android/ant/chromium-jars.xml
index 9521473..aac4064 100644
--- a/build/android/ant/chromium-jars.xml
+++ b/build/android/ant/chromium-jars.xml
@@ -19,11 +19,11 @@
<path id="javac.custom.classpath">
<filelist files="${INPUT_JARS_PATHS}"/>
- <pathelement location="${ANDROID_SDK}/android.jar" />
+ <pathelement location="${ANDROID_SDK}/android.jar"/>
</path>
<path id="javac.srcdirs.additional">
- <filelist files="${ADDITIONAL_SRC_DIRS}" />
+ <filelist files="${ADDITIONAL_SRC_DIRS}"/>
</path>
<property-value
@@ -32,12 +32,6 @@
/>
<property-location
- name="lib.dir"
- location="${PRODUCT_DIR}/lib.java"
- check-exists="false"
- />
-
- <property-location
name="dest.dir"
location="${PRODUCT_DIR}/java/${PACKAGE_NAME}"
check-exists="false"
@@ -47,7 +41,6 @@
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
- <mkdir dir="${lib.dir}"/>
<mkdir dir="${dest.dir}"/>
<!-- Remove all .class files from dest.dir. This prevents inclusion of
@@ -60,7 +53,7 @@
</delete>
</target>
- <target name="compile" depends="init" description="Compiles source." >
+ <target name="compile" depends="init" description="Compiles source.">
<fail message="Error: javac.custom.classpath is not set. Please set it to
classpath for javac.">
<condition>
@@ -85,7 +78,7 @@
description="Generate chromium_${PACKAGE_NAME}.jar.">
<!-- Create the distribution directory -->
<jar
- jarfile="${lib.dir}/chromium_${PACKAGE_NAME}.jar"
+ jarfile="${lib.java.dir}/chromium_${PACKAGE_NAME}.jar"
basedir="${dest.dir}"
/>
@@ -93,11 +86,11 @@
time should still be updated. Otherwise, this target will continue to
be rebuilt in future builds.
-->
- <touch file="${lib.dir}/chromium_${PACKAGE_NAME}.jar"/>
+ <touch file="${lib.java.dir}/chromium_${PACKAGE_NAME}.jar"/>
</target>
<target name="clean" description="clean up">
<!-- Delete the appropriate directory trees -->
- <delete dir="${dest.dir}" />
+ <delete dir="${dest.dir}"/>
</target>
</project>
diff --git a/build/android/ant/common.xml b/build/android/ant/common.xml
index ff88fd0..1001f19 100644
--- a/build/android/ant/common.xml
+++ b/build/android/ant/common.xml
@@ -75,4 +75,16 @@
<property-value name="target" value="android-${ANDROID_SDK_VERSION}"/>
<property name="source.dir" location="src"/>
<property-location name="android.gdbserver" location="${ANDROID_GDBSERVER}"/>
+ <!--
+ Common directories used by SDK Build, when making changes here
+ make sure to update gyp files and test scripts constants in
+ build/android/pylib/constants.py
+ -->
+ <!-- Common directory for chromium_*.jars. -->
+ <property-location name="lib.java.dir" location="${PRODUCT_DIR}/lib.java"/>
+ <!-- Common directory for test jars. -->
+ <property-location name="test.lib.java.dir"
+ location="${PRODUCT_DIR}/test.lib.java"/>
+ <!-- Common directory for apks. -->
+ <property-location name="apks.dir" location="${PRODUCT_DIR}/apks"/>
</project>
diff --git a/build/android/ant/create-test-jar.js b/build/android/ant/create-test-jar.js
new file mode 100644
index 0000000..542a89e
--- /dev/null
+++ b/build/android/ant/create-test-jar.js
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 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.
+
+/**
+ * Combines classes from javac.custom.classpath property and ${out.dir}/classes
+ * into a single jar file ${ant.project.name}-debug.jar and places the file in
+ * ${lib.java.dir}.
+ */
+
+importClass(java.io.File);
+importClass(org.apache.tools.ant.types.Reference);
+importClass(org.apache.tools.ant.types.FileSet);
+importClass(org.apache.tools.ant.types.ZipFileSet);
+importClass(org.apache.tools.ant.taskdefs.Zip);
+
+var echo = project.createTask("echo");
+var jarTask = project.createTask("jar");
+
+// Do not allow duplicates in the jar, the default behavior of Jar task
+// is "add" which means duplicates are allowed.
+// This can cause a class file to be included multiple times, setting the
+// duplicate to "preserve" ensures that only the first definition is included.
+
+var duplicate = Zip.Duplicate();
+duplicate.setValue("preserve");
+jarTask.setDuplicate(duplicate);
+
+var destFile = project.getProperty("ant.project.name") + "-debug.jar";
+var destPath = File(project.getProperty("test.lib.java.dir") + "/" + destFile);
+jarTask.setDestFile(destPath);
+
+// Include all the jars in the classpath.
+var javacCustomClasspath =
+ project.getReference("javac.custom.classpath").list();
+
+for (var i in javacCustomClasspath) {
+ var fileName = javacCustomClasspath[i]
+ var fileExtension = fileName.split("\\.").pop();
+ if(fileExtension == "jar")
+ {
+ var zipFileSet = ZipFileSet();
+ zipFileSet.setIncludes("**/*.class");
+ zipFileSet.setSrc(File(fileName));
+ jarTask.addFileset(zipFileSet);
+ }
+}
+
+// Add the compiled classes in ${out.dir}/classes.
+var projectClasses = FileSet();
+projectClasses.setIncludes("**/*.class");
+projectClasses.setDir(File(project.getProperty("out.dir") + "/classes"));
+jarTask.addFileset(projectClasses);
+
+// Exclude manifest and resource classes.
+var appPackagePath =
+ (project.getProperty("project.app.package")).replace('.','/');
+var excludedClasses = ["R.class", "R$*.class", "Manifest.class",
+ "Manifest$*.class", "BuildConfig.class"]
+
+var exclusionString = "";
+for (var i in excludedClasses) {
+ exclusionString += appPackagePath+ "/" + excludedClasses[i] + " ";
+}
+
+jarTask.setExcludes(exclusionString);
+echo.setMessage("Creating test jar: " +
+ jarTask.getDestFile().getAbsolutePath());
+echo.perform();
+jarTask.perform();
diff --git a/build/android/ant/sdk-targets.xml b/build/android/ant/sdk-targets.xml
index 59913e3..6707b08 100644
--- a/build/android/ant/sdk-targets.xml
+++ b/build/android/ant/sdk-targets.xml
@@ -13,7 +13,6 @@
for aidl and javac. This file defines targets which can be used to
override targets used by tools.
-->
-
<!--
Override the -compile target.
This target requires 'javac.custom.classpath' to be set to reference
@@ -92,6 +91,20 @@
</emma>
</then>
</if>
+ <!--
+ If the project needs a test jar then generate a jar containing
+ all compiled classes and referenced jars.
+ -->
+ <if condition="${generate.test.jar}">
+ <then>
+ <echo level="info">Creating test jar file:
+ ${ant.project.name}-debug.jar</echo>
+ <property-location name="create.test.jar.file"
+ location="${CHROMIUM_SRC}/build/android/ant/create-test-jar.js"/>
+ <script language="javascript" src="${create.test.jar.file}"/>
+ </then>
+ </if>
+
</do-only-if-manifest-hasCode>
</target>
@@ -115,9 +128,9 @@
<!-- SDK tools assume that out.packaged.file is signed and name it "...-unaligned" -->
<property name="out.packaged.file"
- value="${out.dir}/${ant.project.name}-debug-unsigned.apk" />
+ value="${apks.dir}/${ant.project.name}-debug-unsigned.apk" />
<property name="out.unaligned.file"
- value="${out.dir}/${ant.project.name}-debug-unaligned.apk" />
+ value="${apks.dir}/${ant.project.name}-debug-unaligned.apk" />
<!-- By default, the SDK tools build only aligns the APK in the -do-debug target. -->
<target name="-do-debug"
diff --git a/build/android/buildbot/buildbot_functions.sh b/build/android/buildbot/buildbot_functions.sh
index 4136e69..482ec90 100755
--- a/build/android/buildbot/buildbot_functions.sh
+++ b/build/android/buildbot/buildbot_functions.sh
@@ -229,7 +229,7 @@ function bb_run_instrumentation_test {
# Run content shell instrumentation test on device.
function bb_run_instrumentation_tests {
build/android/adb_install_content_shell
- local TEST_APK="content_shell_test/ContentShellTest-debug"
+ local TEST_APK="ContentShellTest"
# Use -I to install the test apk only on the first run.
# TODO(bulach): remove the second once we have a Smoke test.
bb_run_instrumentation_test ${TEST_APK} "-I -A Smoke"
diff --git a/build/android/pylib/constants.py b/build/android/pylib/constants.py
index 0121fd6..876b592 100644
--- a/build/android/pylib/constants.py
+++ b/build/android/pylib/constants.py
@@ -37,3 +37,7 @@ TEST_SERVER_PORT_FILE = '/tmp/test_server_port'
TEST_SERVER_PORT_LOCKFILE = '/tmp/test_server_port.lock'
TEST_EXECUTABLE_DIR = '/data/local/tmp'
+# Directories for common java libraries for SDK build.
+# These constants are defined in build/android/ant/common.xml
+SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java'
+SDK_BUILD_APKS_DIR = 'apks'
diff --git a/build/android/pylib/test_options_parser.py b/build/android/pylib/test_options_parser.py
index 8492ec3..4edd5f9 100644
--- a/build/android/pylib/test_options_parser.py
+++ b/build/android/pylib/test_options_parser.py
@@ -85,10 +85,9 @@ def AddInstrumentationOptions(option_parser):
'of the result. (Default is 1)'))
option_parser.add_option('--test-apk', dest='test_apk',
help=('The name of the apk containing the tests '
- '(without the .apk extension) or for SDK '
- 'builds, the path to the APK from '
- 'out/(Debug|Release) (for example, '
- 'content_shell_test/ContentShellTest-debug).'))
+ '(without the .apk extension). For SDK '
+ 'builds, the apk name without the debug '
+ 'suffix(for example, ContentShellTest).'))
option_parser.add_option('--screenshot', dest='screenshot_failures',
action='store_true',
help='Capture screenshots of test failures')
@@ -119,13 +118,15 @@ def ValidateInstrumentationOptions(option_parser, options, args):
elif options.python_only:
options.run_java_tests = False
+ # In case of SDK Build, the jars and apks have a -debug suffix.
options.test_apk_path = os.path.join(_SDK_OUT_DIR,
options.build_type,
- '%s.apk' % options.test_apk)
+ constants.SDK_BUILD_APKS_DIR,
+ '%s-debug.apk' % options.test_apk)
options.test_apk_jar_path = os.path.join(_SDK_OUT_DIR,
options.build_type,
- '%s.jar'
- % options.test_apk)
+ constants.SDK_BUILD_TEST_JAVALIB_DIR,
+ '%s-debug.jar' % options.test_apk)
if options.annotation_str:
options.annotation = options.annotation_str.split()
elif options.test_filter: