Skip to content

Commit

Permalink
[Android] Add chrome_java target for building Java code in the chromi…
Browse files Browse the repository at this point in the history
…um layer.

Also includes a refactoring of the Ant xml scripts to use a common template (contributed by shashishekhar@chromium.org). As part of this, I also continued Torne's effort of removing our reliance on environment variables. Unfortunately this currently means that you have to specify 5 gyp flags:
    ANDROID_SDK, ANDROID_SDK_ROOT, ANDROID_SDK_TOOLS, ANDROID_SDK_VERSION, ANDROID_TOOLCHAIN.

This'll get better as we make further use of the checked in sdk both upstream and downstream. The problem stems from the android tree and released sdk having different configurations.

Review URL: https://chromiumcodereview.appspot.com/10830012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150172 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
yfriedman@chromium.org committed Aug 6, 2012
1 parent 4f3db5b commit 3008004
Show file tree
Hide file tree
Showing 20 changed files with 391 additions and 216 deletions.
55 changes: 9 additions & 46 deletions base/android/java/base.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,15 @@
<!--
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.
-->
<project name="Base" default="dist" basedir=".">
<description>
building base java source code with ant
</description>
<!-- Set global properties for this build -->
<property name="src" location="src"/>
<property name="dist" location="dist"/>
<property name="out.dir" location="${PRODUCT_DIR}/lib.java"/>
<!-- TODO(jrg): establish a standard for the intermediate java
directories. Settle on a standard once ant/jar build files
like this are androidified -->
<property name="dest.dir" location="${PRODUCT_DIR}/java/base"/>
<import file="../../../build/android/ant/chromium-jars.xml" />

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${out.dir}"/>
<mkdir dir="${dest.dir}"/>
</target>

<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<!-- TODO(jrg): adapting this to a proper android antfile will
remove warnings like this:
base.xml:23: warning: 'includeantruntime' was not set,
defaulting to build.sysclasspath=last;
set to false for repeatable builds
-->
<javac srcdir="${src}" destdir="${dest.dir}" debug="true" includeantruntime="false">
<classpath>
<path location="${ANDROID_SDK}/android.jar"/>
</classpath>
</javac>
</target>

<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${out.dir}"/>

<jar jarfile="${out.dir}/chromium_base.jar" basedir="${dest.dir}"/>
</target>

<target name="clean"
description="clean up" >
<!-- Delete the appropriate directory trees -->
<delete dir="${dest.dir}"/>
<delete dir="${dist}"/>
</target>
<path id="javac.custom.classpath">
<pathelement location="${ANDROID_SDK}/android.jar" />
</path>
</project>
64 changes: 64 additions & 0 deletions build/android/ant/chromium-jars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
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.
-->
<project name="chromium-jars" default="dist">
<!--
Common ant build file for for chromium_*.jars.
For creating a new chromium_*.jar :
1. Use build/java.gyp action. This action will set PACKAGE_NAME.
The jar will be created as chromium_${PACKAGE_NAME} in
${PRODUCT_DIR}/lib.java.
2. Set javac.custom.classpath to classpath to use for javac.
3. Override javac.srcdir for providing custom source directory for javac.
-->

<import file="common.xml"/>
<property-location name="src" location="src"/>
<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"/>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${lib.dir}"/>
<mkdir dir="${dest.dir}"/>
</target>

<!--
Compile target for jars. Requires javac.custom.classpath to be set.
Optionally javac.srcdir can be overridden to custom path for src
directories.
-->
<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>
<not><isreference refid="javac.custom.classpath"/></not>
</condition>
</fail>
<property-value name="javac.srcdir" value ="${src}"/>
<echo>Compiling ${javac.srcdir}, classpath: ${toString:javac.custom.classpath}</echo>
<javac srcdir="${javac.srcdir}" destdir="${dest.dir}" debug="true" includeantruntime="false">
<classpath>
<path refid="javac.custom.classpath" />
</classpath>
</javac>
</target>

<target name="dist" depends="compile"
description="Generate chromium_${PACKAGE_NAME}.jar.">
<!-- Create the distribution directory -->
<mkdir dir="${lib.dir}" />
<jar jarfile="${lib.dir}/chromium_${PACKAGE_NAME}.jar" basedir="${dest.dir}"/>
</target>

<target name="clean" description="clean up">
<!-- Delete the appropriate directory trees -->
<delete dir="${dest.dir}" />
</target>
</project>
78 changes: 78 additions & 0 deletions build/android/ant/common.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project name="chrome_common_defines">
<!-- Common build properties for Chrome for android. -->

<!--
Macro for checking that a property is correctly set. Performs checks for:
1. Property is set and not null.
2. String value of property does not contains any '$' signs.
-->
<macrodef name="check-property-value">
<attribute name="property"/>
<sequential>
<fail message ="Property @{property} is not set.">
<condition>
<or>
<not><isset property="@{property}"/></not>
<length string="${@{property}}" trim="true" when="less" length="1"/>
</or>
</condition>
</fail>
<!--
Check for $ signs. This catches errors when properties are initialized from environment
variables. E.g. if we have <property name="foo" value="${env.bar}" /> but env.bar is
not set then foo will have the literal value of '${env.bar}'.
-->
<fail message="Value checked failed for property: @{property} : ${@{property}}.
Property value contains an uninitialized environment variable.">
<condition>
<contains string="${@{property}}" substring="$"/>
</condition>
</fail>
</sequential>
</macrodef>

<!--
A safe setter for location properties. Checks that a location is not
empty and actually exists. For specifying output directories, location
check can be disabled by specifying check-exists="false".
-->
<macrodef name="property-location">
<attribute name="name"/>
<attribute name="location"/>
<attribute name="check-exists" default="true"/>
<sequential>
<property name="@{name}" location="@{location}"/>
<check-property-value property="@{name}"/>
<fail message="Location specified for @{name} : @{location} does not exist.">
<condition>
<and>
<equals arg1="@{check-exists}" arg2="true"/>
<not><available type="dir" file="@{location}"/></not>
</and>
</condition>
</fail>
</sequential>
</macrodef>

<!-- A safe setter for property values -->
<macrodef name="property-value">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="@{value}"/>
<check-property-value property="@{name}"/>
</sequential>
</macrodef>

<!-- Common environment properties. -->
<property-location name="sdk.dir" location="${ANDROID_SDK_ROOT}"/>
<property-value name="target" value="android-${ANDROID_SDK_VERSION}"/>
<property name="source.dir" location="src"/>
<property-location name="toolchain.dir" location="${ANDROID_TOOLCHAIN}"/>
</project>
97 changes: 97 additions & 0 deletions build/android/ant/sdk-targets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project name="chrome_sdk_overrides" >
<!--
Redefinition of targets used by SDK tools.
Supported version: SDK tools revision 20.
SDK tools do not allow easy way of extending classpaths
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
of classpath to be used for javac. Also accepts custom path for
sources: 'javac.custom.sourcepath'.
-->
<target
name="-compile"
depends="-build-setup, -pre-build, -code-gen, -pre-compile">
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..." >
<!-- If souce path is not set, then use the default value -->
<if>
<condition>
<not>
<isreference refid="javac.custom.sourcepath"/>
</not>
</condition>
<then>
<path id="javac.custom.sourcepath">
<pathelement path="${source.absolute.dir}"/>
<pathelement path="${gen.absolute.dir}"/>
</path>
</then>
</if>
<javac
bootclasspathref="project.target.class.path"
classpathref="javac.custom.classpath"
debug="true"
destdir="${out.classes.absolute.dir}"
encoding="${java.encoding}"
extdirs=""
fork="${need.javac.fork}"
includeantruntime="false"
source="${java.source}"
target="${java.target}"
verbose="${verbose}">
<src path="${source.absolute.dir}"/>
<src path="${gen.absolute.dir}"/>
<src>
<path refid="javac.custom.sourcepath"/>
</src>
<compilerarg line="${java.compilerargs}"/>
</javac>
<!--
If the project is instrumented, then instrument the classes
TODO(shashishekhar): Add option to override emma filter.
-->
<if condition="${build.is.instrumented}">
<then>
<echo level="info">
Instrumenting classes from ${out.absolute.dir}/classes...
</echo>
<!-- build the default filter to remove R, Manifest, BuildConfig -->
<getemmafilter
appPackage="${project.app.package}"
filterOut="emma.default.filter"
libraryPackagesRefId="project.library.packages"/>
<!--
Define where the .em file is output.
This may have been setup already if this is a library.
-->
<property name="emma.coverage.absolute.file"
location="${out.absolute.dir}/coverage.em"/>
<!-- It only instruments class files, not any external libs -->

<emma enabled="true">
<instr
instrpath="${out.absolute.dir}/classes"
metadatafile="${emma.coverage.absolute.file}"
mode="overwrite"
outdir="${out.absolute.dir}/classes"
verbosity="${verbosity}">
<filter excludes="${emma.default.filter}"/>
<filter value="${emma.filter}"/>
</instr>
</emma>
</then>
</if>
</do-only-if-manifest-hasCode>
</target>
</project>
13 changes: 12 additions & 1 deletion build/apk_test.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,20 @@
'<(PRODUCT_DIR)/<(test_suite_name)_apk',
'--app_abi',
'<(android_app_abi)',
'--sdk-build=<(sdk_build)',
'--ant-args',
'-DPRODUCT_DIR=<(ant_build_out)',
'--sdk-build=<(sdk_build)',
'--ant-args',
'-DANDROID_SDK=<(android_sdk)',
'--ant-args',
'-DANDROID_SDK_ROOT=<(android_sdk_root)',
'--ant-args',
'-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
'--ant-args',
'-DANDROID_SDK_VERSION=<(android_sdk_version)',
'--ant-args',
'-DANDROID_TOOLCHAIN=<(android_toolchain)',
'--ant-compile'
],
}],
}], # 'OS == "android" and gtest_target_type == "shared_library"
Expand Down
4 changes: 4 additions & 0 deletions build/java.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
'-DPRODUCT_DIR=<(ant_build_out)',
'-DPACKAGE_NAME=<(package_name)',
'-DANDROID_SDK=<(android_sdk)',
'-DANDROID_SDK_ROOT=<(android_sdk_root)',
'-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
'-DANDROID_SDK_VERSION=<(android_sdk_version)',
'-DANDROID_TOOLCHAIN=<(android_toolchain)',
'-buildfile',
'<(java_in_dir)/<(package_name).xml',
]
Expand Down
19 changes: 19 additions & 0 deletions chrome/android/java/chrome.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
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.
-->
<project name="Chrome" default="dist" basedir=".">
<description>
Building chrome.jar from java source code.
</description>
<import file="../../../build/android/ant/chromium-jars.xml" />
<path id="javac.custom.classpath">
<pathelement location="${ANDROID_SDK}/android.jar" />
<pathelement location="${lib.dir}/chromium_content.jar" />
<pathelement location="${lib.dir}/chromium_base.jar" />
<pathelement location="${lib.dir}/chromium_net.jar" />
</path>
<!-- Override javac path to include jars in lib.java directory -->
<property-value name="javac.srcdir" value="${src}" />
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void sendEmail(
send.putExtra(Intent.EXTRA_SUBJECT, subject);
send.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
try {
Intent chooser = Intent.createChooser(send, chooserTitle));
Intent chooser = Intent.createChooser(send, chooserTitle);
// we start this activity outside the main activity.
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(chooser);
Expand Down
19 changes: 19 additions & 0 deletions chrome/chrome.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,5 +1073,24 @@
},
]}, # 'targets'
], # OS=="win"
['OS=="android"',
{
'targets': [
{
'target_name': 'chrome_java',
'type': 'none',
'dependencies': [
'../base/base.gyp:base_java',
'../content/content.gyp:content_java',
'../net/net.gyp:net_java',
],
'variables': {
'package_name': 'chrome',
'java_in_dir': '../chrome/android/java',
},
'includes': [ '../build/java.gypi' ],
},
]}, # 'targets'
], # OS=="android"
], # 'conditions'
}
1 change: 1 addition & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -4591,6 +4591,7 @@
'dependencies': [
'../base/base.gyp:base_java',
'../net/net.gyp:net_java',
'chrome_java',
'unit_tests',
],
'variables': {
Expand Down
Loading

0 comments on commit 3008004

Please sign in to comment.