added Android build and test support

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@13363 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
michelou 2007-11-27 19:49:42 +00:00
parent 9dc83d1e52
commit bb1577ea86
4 changed files with 148 additions and 30 deletions

View File

@ -692,7 +692,7 @@ CLDC
</target>
<target name="cldclib"
<target name="cldc.libraries"
depends="setup.quick, cldc.sources"
description="Builds the Scala library for J2ME (CLDC)"
>
@ -778,7 +778,7 @@ CLDC
destdir="${cldc.dir}/lib/preverified"
/>
<jar
destfile="${cldc.dir}/lib/scala-cldc-library.jar"
destfile="${cldc.dir}/lib/scalaapi10-unverified.jar"
basedir="${cldc.dir}/lib/library"
includes="scala/**/*.class">
<manifest>
@ -787,7 +787,7 @@ CLDC
</jar>
<!-- see http://java.sun.com/j2me/docs/uei_specs.pdf -->
<jar
destfile="${cldc.dir}/lib/scala-cldc-api.jar"
destfile="${cldc.dir}/lib/scalaapi10.jar"
basedir="${cldc.dir}/lib/preverified"
includes="scala/**/*.class">
<manifest>
@ -800,10 +800,16 @@ CLDC
</jar>
</target>
<target name="cldc" depends="cldc.libraries">
<!-- exemples ? -->
</target>
<!-- ===========================================================================
ANDROID
============================================================================ -->
<property name="dx.jar" value="${android.home}/tools/lib/dx.jar"/>
<target name="android.sources"
description="Create the source directory for Android library"
>
@ -825,7 +831,7 @@ ANDROID
</copy>
</target>
<target name="android.lib"
<target name="android.libraries"
depends="setup.quick, android.sources"
description="Builds the Scala library for Android">
<fail message="Android home is not set or could not find android.jar in ${android.home}">
@ -838,9 +844,6 @@ ANDROID
<javac
srcdir="${android.dir}/src"
destdir="${android.dir}/lib/library"
compiler="javac1.4"
source="1.1"
target="1.1"
deprecation="${jc.deprecation}"
>
<bootclasspath>
@ -882,6 +885,30 @@ ANDROID
</quick>
</target>
<target name="android" depends="android.libraries"
description="Convert this project's .class files into .dex files">
<java jar="${dx.jar}" fork="true" failonerror="true">
<jvmarg value="-Djava.ext.dirs=${android.home}${file.separator}tools${file.separator}lib"/>
<jvmarg value="-Xmx384M"/>
<arg value="--dex"/>
<arg value="--output=${android.dir}/lib/classes.dex"/>
<arg value="--locals=full"/>
<arg value="--positions=lines"/>
<arg value="${android.dir}/lib/library"/>
</java>
<jar
destfile="${android.dir}/lib/scala.jar"
basedir="${android.dir}/lib"
includes="classes.dex"
/>
<jar
destfile="${android.dir}/lib/scala-android.jar"
basedir="${android.dir}/lib/library"
includes="scala/**/*.class"
/>
<!-- examples ? -->
</target>
<!-- ===========================================================================
MSIL
============================================================================ -->
@ -1671,7 +1698,7 @@ GENERATES A DISTRIBUTION
</target>
<target name="build.dist"
depends="binaries,docs,docs.manual,msil"
depends="binaries,docs,docs.manual,msil,cldc,android"
description="Creates the latest Scala distribution">
<!-- Copy the API, examples and man -->
<copy todir="${dist.current.dir}/doc/scala">
@ -1698,7 +1725,7 @@ GENERATES A DISTRIBUTION
</target>
<!-- Create the SBaz packages -->
<target name="build.sbaz" depends="build.dist,cldclib">
<target name="build.sbaz" depends="build.dist">
<property name="sbaz.universe" value="http://www.scala-lang.org/downloads/packages"/>
<mkdir dir="${dist.dir}"/>
<!-- Create the Scala library package -->
@ -1772,6 +1799,16 @@ GENERATES A DISTRIBUTION
link="${sbaz.universe}/scala-cldc-${version.number}.sbp">
<libset dir="${cldc.dir}/lib" includes="*.jar"/>
</quicksbaz>
<!-- Creates the Android package -->
<quicksbaz
file="${dist.dir}/scala-android-${version.number}.sbp"
adfile="${dist.dir}/scala-android-${version.number}.advert"
name="scala-android"
version="${version.number}"
desc="The Scala Android package contains everything needed to use Scala on Android."
link="${sbaz.universe}/scala-android-${version.number}.sbp">
<libset dir="${android.dir}/lib" includes="*.jar"/>
</quicksbaz>
</target>
<target name="build.archive" depends="build.dist">

View File

@ -0,0 +1,16 @@
//package examples.hello3
import android.app.Activity
import android.os.Bundle
import android.widget.TextView
//class HelloAndroid extends Activity {
class Test extends Activity {
/** Called when the activity is first created. */
override def onCreate(icicle: Bundle) {
super.onCreate(icicle)
val tv = new TextView(this)
tv setText "Hello, Android (Scala)"
setContentView(tv)
}
}

View File

@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="">
<application>
<activity class="HelloAndroid" android:label="HelloAndroid">
<intent-filter>
<action android:value="android.intent.action.MAIN" />
<category android:value="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -293,7 +293,7 @@ MSIL="msil"
EXE="exe"
# Tests the .NET backend.
test_run_msil() {
assemblies=`get_os_pathlist $LATEST_ASSEM`;
assemblies=`get_os_pathlist $SCALA_ASSEM`;
rm -f "$dstbase".$MSIL &&
rm -f "$dstbase".$EXE &&
@ -315,7 +315,7 @@ test_run_msil() {
rm -f "$dstbase".$MSIL;
}
# Tests the CLDC backend/runtime.
# Tests the CLDC target platform.
test_run_cldc() {
rm -rf "$dstbase".unverified "$dstbase".preverified &&
mkdir -p "$dstbase".unverified "$dstbase".preverified &&
@ -335,12 +335,33 @@ test_run_cldc() {
echo MIDlet-Jar-Size: $jarsize;
echo MicroEdition-Profile: MIDP-1.0;
echo MicroEdition-Configuration: CLDC-1.0 ) > "$dstbase".jad &&
cpath=`get_os_pathlist $SCALA_CLDC_API:"$dstbase".jar` &&
cpath=`get_os_pathlist $SCALA_CLDCAPI:"$dstbase".jar` &&
$KVEM_EMULATOR -cp $cpath -Xdescriptor:"$dstbase".jad 2> /dev/null &&
head $logfile -n 4 | tail -n 1 > $logfile.0 &&
mv $logfile.0 $logfile
}
# Tests the Android target platform.
test_run_android() {
rm -rf "$dstbase" &&
os_classes=`get_os_filename "$dstbase"/classes` &&
mkdir -p "$os_classes" &&
xml_file=`get_os_filename "$dstbase"/AndroidManifest.xml` &&
cp "$srcbase".xml $xml_file &&
cpath=`get_os_pathlist $ANDROID_LIB:"$dstbase"` &&
$SCALAC -bootclasspath $cpath -cp "$os_classes" -d "$os_classes" -encoding ascii "$os_srcbase".scala &&
# echo $JAVACCMD -bootclasspath $cpath -cp "$os_classes" -d "$os_classes" -encoding ascii "$os_srcbase"/**/*.java &&
(cd "$os_classes" && $JARCMD xf $SCALA_LIB) &&
extdirs=`get_os_pathlist "$ANDROID_HOME/tools/lib"` &&
dex_file=`get_os_filename "$os_dstbase"/classes.dex` &&
$JAVACMD -Djava.ext.dirs=$extdirs -Xmx384M -jar $DX_LIB \
--dex --output=$dex_file --locals=full --positions=lines \
"$os_classes" &&
(cd "$dstbase" && zip -9q Test.apk *.xml *.dex &&
$ANDROID_ADB shell '"cd data/app; rm Test.apk"' 2>&1 1> /dev/null &&
$ANDROID_ADB install Test.apk 2> /dev/null)
}
# Tests a script with Scala code embedded in it
test_run_script() {
argsfile="$srcbase.args"
@ -501,9 +522,11 @@ test_check_all() {
test_check_kind "Testing resident compiler" \
"res" $FILES_RES;
test_check_kind "Testing shootout benchmarks" \
"shootout" $FILES_SHOOTOUT;
"shootout" $FILES_SHOOTOUT;
test_check_kind "Testing CLDC benchmarks" \
"cldc" $FILES_CLDC;
test_check_kind "Testing Android benchmarks" \
"android" $FILES_ANDROID;
}
@ -523,6 +546,7 @@ test_add_file() {
TEST_ALL="false";
case "$TEST_TYPE" in
auto ) ;;
android) FILES_ANDROID="$FILES_ANDROID $1"; return;;
cldc ) FILES_CLDC="$FILES_CLDC $1"; return;;
dis ) FILES_DIS="$FILES_DIS $1"; return;;
run ) FILES_RUN="$FILES_RUN $1"; return;;
@ -537,6 +561,7 @@ test_add_file() {
* ) abort "unknown test type \`$TEST_TYPE'";;
esac;
case "$1" in
android | */android | */android/* | android/* ) FILES_ANDROID="$FILES_ANDROID $1";;
cldc | */cldc | */cldc/* | cldc/* ) FILES_CLDC="$FILES_CLDC $1";;
dis | */dis | */dis/* | dis/* ) FILES_DIS="$FILES_DIS $1";;
run | */run | */run/* | run/* ) FILES_RUN="$FILES_RUN $1";;
@ -628,13 +653,15 @@ FILES_DIS="";
FILES_ANT="";
FILES_SHOOTOUT="";
FILES_CLDC="";
FILES_ANDROID="";
QUICK="$PREFIX/build/quick/bin"
QUICK_LIB="$PREFIX/build/quick/lib/library"
QUICK_COMP="$PREFIX/build/quick/lib/compiler"
QUICK_ACT="$PREFIX/build/quick/lib/actors"
QUICK_CLDC="$PREFIX/build/cldc/lib/scala-cldc-library.jar" # unverified
QUICK_CLDC_API="$PREFIX/build/cldc/lib/scala-cldc-api.jar" # preverified
QUICK_PREDEF="$PREFIX/build/quick/lib/predef.dll"
QUICK_CLDC="$PREFIX/build/cldc/lib/scalaapi10-unverified.jar" # unverified
QUICK_CLDCAPI="$PREFIX/build/cldc/lib/scalaapi10.jar" # preverified
JVM_EXT_CLASSPATH=`get_ext_classpath $TESTROOT/files/lib`
@ -643,20 +670,23 @@ if [ -d "$PREFIX/dists" ]; then
LATEST_LIB="$PREFIX/dists/latest/lib/scala-library.jar";
LATEST_COMP="$PREFIX/dists/latest/lib/scala-compiler.jar";
LATEST_PREDEF="$PREFIX/dists/latest/lib/predef.dll";
LATEST_ASSEM="$LATEST_PREDEF;$PREFIX/lib/scalaruntime.dll:$PREFIX/lib/mscorlib.dll";
LATEST_CLDC=$QUICK_CLDC;
LATEST_CLDCAPI=$QUICK_CLDCAPI;
elif [ -d "$PREFIX/build" ]; then
LATEST="$QUICK";
LATEST_LIB=$QUICK_LIB
LATEST_COMP=$QUICK_COMP
LATEST_ACT=$QUICK_ACT
LATEST_PREDEF="$PREFIX/build/quick/lib/predef.dll";
LATEST_ASSEM="$LATEST_PREDEF:$PREFIX/build/quick/lib/scalaruntime.dll:$PREFIX/build/quick/lib/mscorlib.dll";
LATEST_LIB=$QUICK_LIB;
LATEST_COMP=$QUICK_COMP;
LATEST_ACT=$QUICK_ACT;
LATEST_PREDEF=$QUICK_PREDEF;
LATEST_CLDC=$QUICK_CLDC;
LATEST_CLDCAPI=$QUICK_CLDCAPI;
elif [ -d "$PREFIX/bin" ]; then
LATEST="$PREFIX/bin";
LATEST_LIB="$PREFIX/lib/scala-library.jar";
LATEST_COMP="$PREFIX/lib/scala-compiler.jar";
LATEST_PREDEF="$PREFIX/lib/predef.dll";
LATEST_ASSEM="$LATEST_PREDEF:$PREFIX/lib/scalaruntime.dll:$PREFIX/lib/mscorlib.dll";
LATEST_CLDC="$PREFIX/lib/scalaapi10-unverified.jar";
LATEST_CLDCAPI="$PREFIX/lib/scalaapi10.jar";
else
abort "Scala binaries could not be found";
fi;
@ -666,8 +696,8 @@ BIN_DIR="$LATEST/" # BIN_DIR should have a trailing / when needed, so that
SCALA_LIB="$LATEST_LIB";
SCALA_COMP="$LATEST_COMP";
SCALA_ACT="$LATEST_ACT";
SCALA_CLDC="$QUICK_CLDC";
SCALA_CLDC_API="$QUICK_CLDC_API";
SCALA_CLDC="$LATEST_CLDC";
SCALA_CLDCAPI="$LATEST_CLDCAPI";
[ -x "$JAVACMD" ] || JAVACMD=java;
[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms16M";
@ -686,6 +716,7 @@ esac;
while [ $# -gt 0 ]; do
case "$1" in
--android ) TEST_TYPE="android"; shift 1;;
--auto ) TEST_TYPE="auto"; shift 1;;
--cldc ) TEST_TYPE="cldc"; shift 1;;
--dis ) TEST_TYPE="dis"; shift 1;;
@ -699,7 +730,8 @@ while [ $# -gt 0 ]; do
--ant ) TEST_TYPE="ant"; shift 1;;
--shootout ) TEST_TYPE="shootout"; shift 1;;
--quick ) BIN_DIR="$QUICK/"; SCALA_LIB=$QUICK_LIB;
SCALA_COMP=$QUICK_COMP; SCALA_ACT=$QUICK_ACT; shift 1;;
SCALA_COMP=$QUICK_COMP; SCALA_ACT=$QUICK_ACT;
SCALA_PREDEF=$QUICK_PREDEF; shift 1;;
--installed ) BIN_DIR=""; shift 1;;
--no-run ) NORUN="true"; shift 1;;
--show-log ) SHOWLOG="true"; shift 1;;
@ -735,6 +767,9 @@ fi;
printf_initialization "${COLOR:-many}";
if [ "$TEST_ALL" = "true" ]; then
case "$TEST_TYPE" in
android ) FILES_ANDROID="$FILES_ANDROID $SRCDIR/android";;
esac;
case "$TEST_TYPE" in
cldc ) FILES_CLDC="$FILES_CLDC $SRCDIR/cldc";;
esac;
@ -791,6 +826,7 @@ SCALAC="$SCALAC_CMD $SCALAC_OPTS";
SCALAP="scalap";
CLASSPATH=$SCALA_COMP:$SCALA_ACT
SCALA_ASSEM=$SCALA_PREDEF:$PREFIX/lib/scalaruntime.dll:$PREFIX/lib/mscorlib.dll
if [ -z "$ANT" ]; then
if [ -d "$ANT_HOME" ]; then
@ -838,8 +874,8 @@ if [ $TEST_TYPE = "msil" ]; then
printf_outline "ILasm version is : $ilasm_version\\n";
mono_version=`$MONO --version | head -1`;
printf_outline "Mono version is : $mono_version\\n";
if [ -f "$LATEST_PREDEF" ]; then
printf_outline "DLL library is : $LATEST_PREDEF\\n";
if [ -f "$SCALA_PREDEF" ]; then
printf_outline "DLL library is : $SCALA_PREDEF\\n";
else
printf_failure "Missing library \"predef.dll\"; run 'ant msil'.\\n";
exit 1;
@ -862,17 +898,35 @@ else
if [ -d "$KVEM_HOME" ]; then
KVEM_PREVERIFY="$KVEM_HOME/bin/preverify";
KVEM_EMULATOR="$KVEM_HOME/bin/emulator";
KVEM_CLDC=$PREFIX/lib/cldcapi10.jar;
KVEM_CLDC=$KVEM_HOME/lib/cldcapi10.jar;
KVEM_MIDP=$KVEM_HOME/lib/midpapi10.jar;
JARCMD=$bin_dir/jar;
JARCMD="$bin_dir/jar";
elif [ -d "/home/linuxsoft/apps/" ]; then
error "option '--cldc' requires variable KVEM_HOME to be set"
abort "(eg. export KVEM_HOME=/home/linuxsoft/apps/java-wtk)";
else
abort "option '--cldc' requires variable KVEM_HOME to be set";
fi
fi;
kvem_version=`$KVEM_EMULATOR -version | head -1`;
printf_outline "Emulator version is : $kvem_version\\n";
elif [ "$TEST_TYPE" = "android" ]; then
if [ -s "$ANDROID_HOME" ]; then
ANDROID_ADB="$ANDROID_HOME/tools/adb";
ANDROID_EMULATOR="$ANDROID_HOME/tools/emulator";
ANDROID_LIB="$ANDROID_HOME/android.jar";
DX_LIB="$ANDROID_HOME/tools/lib/dx.jar";
JAVACCMD="$bin_dir/javac";
JARCMD="$bin_dir/jar";
elif [ -d "/home/linuxsoft/apps/" ]; then
error "option '--android' requires variable ANDROID_HOME to be set"
abort "(eg. export ANDROID_HOME=/home/linuxsoft/apps/android)";
else
abort "option '--android' requires variable ANDROID_HOME to be set";
fi;
android_version="m3-rc22a"; #not yet available through command
printf_outline "Emulator version is : $android_version\\n";
status=`$ANDROID_ADB shell '"exit"' 2>&1 | wc -l` &&
[ "$status" = "0" ] || abort "Start the Android emulator before running the tests!!!";
fi
fi;
printf_outline "\\n";