|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<project name="build-scala"> |
| 3 | + |
| 4 | + <!-- This file is imported by the main Ant script. --> |
| 5 | + |
| 6 | + <!-- Add Proguard tasks (proguard.sourceforge.net) --> |
| 7 | + <property name="proguard.jar" location="${proguard.dir}/lib/proguard.jar" /> |
| 8 | + <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" /> |
| 9 | + |
| 10 | + <!-- Add Scala tasks (www.scala-lang.org) --> |
| 11 | + <property name="scala-compiler.jar" value="${scala.dir}/lib/scala-compiler.jar" /> |
| 12 | + <property name="scala-library.jar" value="${scala.dir}/lib/scala-library.jar" /> |
| 13 | + <path id="scala.path"> |
| 14 | + <pathelement path="${scala-compiler.jar}" /> |
| 15 | + <pathelement path="${scala-library.jar}" /> |
| 16 | + </path> |
| 17 | + <taskdef resource="scala/tools/ant/antlib.xml" classpathref="scala.path" /> |
| 18 | + <property prefix="scala" resource="compiler.properties" classpathref="scala.path" /> |
| 19 | + <property |
| 20 | + name="scalac.banner" |
| 21 | + value="Scala compiler version ${scala.version.number} - http://scala-lang.org" /> |
| 22 | + <property name="scala.compilerargs" value="" /> |
| 23 | + |
| 24 | + <!-- Rules --> |
| 25 | + |
| 26 | + <resourcecount property="scala.files.count"> |
| 27 | + <fileset dir="${source.dir}" includes="**/*.scala" /> |
| 28 | + </resourcecount> |
| 29 | + <condition property="contains.scala.sources"> |
| 30 | + <not><equals arg1="${scala.files.count}" arg2="0" /></not> |
| 31 | + </condition> |
| 32 | + |
| 33 | + <target name="-compile-scala" depends="-compile" if="contains.scala.sources" |
| 34 | + description="Compiles project's .scala files into .class files"> |
| 35 | + <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..."> |
| 36 | + <condition property="logging" value="verbose" else="none"> |
| 37 | + <istrue value="${verbose}" /> |
| 38 | + </condition> |
| 39 | + <echo message="${scalac.banner}" level="info" taskname="scalac" /> |
| 40 | + <scalac |
| 41 | + destdir="${out.classes.absolute.dir}" |
| 42 | + bootclasspathref="android.target.classpath" |
| 43 | + logging="${logging}" addparams="${scala.compilerargs}" |
| 44 | + classpath="${extensible.classpath}" |
| 45 | + classpathref="jar.libs.ref"> |
| 46 | + <src path="${source.absolute.dir}" /> |
| 47 | + <src path="${gen.absolute.dir}" /> |
| 48 | + <classpath> |
| 49 | + <pathelement location="${scala-library.jar}" /> |
| 50 | + <!-- include compiled resources --> |
| 51 | + <pathelement location="${out.classes.absolute.dir}" /> |
| 52 | + <fileset dir="${extensible.libs.classpath}" includes="*.jar" /> |
| 53 | + </classpath> |
| 54 | + </scalac> |
| 55 | + <!-- if the project is a library then we generate a jar file --> |
| 56 | + <if condition="${project.is.library}"> |
| 57 | + <then> |
| 58 | + <echo>Updating library output jar file...</echo> |
| 59 | + <jar destfile="${out.library.jar.file}" update="true"> |
| 60 | + <fileset dir="${out.classes.absolute.dir}" excludes="**/R.class **/R$*.class"/> |
| 61 | + <fileset dir="${source.absolute.dir}" excludes="**/*.scala" /> |
| 62 | + </jar> |
| 63 | + </then> |
| 64 | + </if> |
| 65 | + |
| 66 | + <!-- if the project is instrumented, intrument the classes --> |
| 67 | + <if condition="${build.is.instrumented}"> |
| 68 | + <then> |
| 69 | + <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo> |
| 70 | + <!-- It only instruments class files, not any external libs --> |
| 71 | + <emma enabled="true"> |
| 72 | + <instr verbosity="${verbosity}" |
| 73 | + mode="overwrite" |
| 74 | + instrpath="${out.absolute.dir}/classes" |
| 75 | + outdir="${out.absolute.dir}/classes"> |
| 76 | + </instr> |
| 77 | + <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from |
| 78 | + user defined file --> |
| 79 | + </emma> |
| 80 | + </then> |
| 81 | + </if> |
| 82 | + </do-only-if-manifest-hasCode> |
| 83 | + </target> |
| 84 | + |
| 85 | + <target name="-post-compile-scala" depends="-compile-scala" |
| 86 | + description="Shrink project class files and Scala library into one .jar file"> |
| 87 | + <condition property="debug.mode" value="" else="#DEBUG#"> |
| 88 | + <equals arg1="${build.target}" arg2="debug" /> |
| 89 | + </condition> |
| 90 | + <condition property="release.mode" value="" else="#RELEASE#"> |
| 91 | + <equals arg1="${build.target}" arg2="release" /> |
| 92 | + </condition> |
| 93 | + <!-- priority is given to local ProGuard configuration if present --> |
| 94 | + <condition property="template.cfg" value="${basedir}/local-proguard-template.cfg"> |
| 95 | + <available file="${basedir}/local-proguard-template.cfg" /> |
| 96 | + </condition> |
| 97 | + <condition property="template.cfg" value="${basedir}/proguard-template.cfg"> |
| 98 | + <available file="${basedir}/proguard-template.cfg" /> |
| 99 | + </condition> |
| 100 | + <fail message="Template file '${template.cfg}' not found"> |
| 101 | + <condition><not><available file="${template.cfg}" /></not></condition> |
| 102 | + </fail> |
| 103 | + <property name="proguard.cfg" value="${out.absolute.dir}${file.separator}proguard.cfg" /> |
| 104 | + <delete file="${proguard.cfg}" /> |
| 105 | + <echo message="Generating configuration file ${proguard.cfg}" /> |
| 106 | + <generate-header property="header" /> |
| 107 | + <if condition="${build.mode.release}"><then> |
| 108 | + <!-- needed for obfuscate task --> |
| 109 | + <path id="project.libraries.jars"> |
| 110 | + <pathelement location="${scala-library.jar}" /> |
| 111 | + </path> |
| 112 | + <!-- we use properties defined in main_rules.xml --> |
| 113 | + <property name="injars" value="" /> |
| 114 | + <property name="outjars" value="" /> |
| 115 | + <property name="libraryjars" value="" /> |
| 116 | + </then><else> |
| 117 | + <property name="shrinked.jar" location="${out.absolute.dir}/shrinked.jar" /> |
| 118 | + <!-- Secondary dx input (jar files) is empty since all the jar |
| 119 | + files will be in the shrinked jar (see tools/ant/build.xml) --> |
| 120 | + <path id="out.dex.jar.input.ref" /> |
| 121 | + <condition property="shrink.required"><not> |
| 122 | + <uptodate targetfile="${shrinked.jar}"> |
| 123 | + <srcfiles dir="${source.absolute.dir}" includes="**/*.scala" /> |
| 124 | + </uptodate> |
| 125 | + </not></condition> |
| 126 | + <!-- input for dex will be proguard's output --> |
| 127 | + <property name="out.dex.input.absolute.dir" value="${shrinked.jar}" /> |
| 128 | + <!-- set the compiled project files and Scala library into a single property. --> |
| 129 | + <if condition="${uses.ramdisk}"><then> |
| 130 | + <pathconvert property="project.injars"> |
| 131 | + <path location="${out.classes.absolute.dir}" /> |
| 132 | + <path refid="project.libraries.jars" /> |
| 133 | + </pathconvert> |
| 134 | + </then><else> |
| 135 | + <pathconvert property="project.injars"> |
| 136 | + <path location="${out.classes.absolute.dir}" /> |
| 137 | + <fileset dir="${jar.libs.dir}" includes="*.jar" /> |
| 138 | + <path refid="project.libraries.jars" /> |
| 139 | + <path location="${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)" /> |
| 140 | + </pathconvert> |
| 141 | + </else></if> |
| 142 | + <split-path property="injars" prefix="-injars" path="${project.injars}" /> |
| 143 | + <split-path property="outjars" prefix="-outjars" path="${shrinked.jar}" /> |
| 144 | + <!-- set the android classpath object into a single property. --> |
| 145 | + <if condition="${uses.ramdisk}"><then> |
| 146 | + <pathconvert property="project.libraryjars"> |
| 147 | + <path location="${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)" /> |
| 148 | + <path refid="android.target.classpath" /> |
| 149 | + </pathconvert> |
| 150 | + </then><else> |
| 151 | + <pathconvert property="project.libraryjars"> |
| 152 | + <path refid="android.target.classpath" /> |
| 153 | + </pathconvert> |
| 154 | + </else></if> |
| 155 | + <split-path property="libraryjars" prefix="-libraryjars" path="${project.libraryjars}" /> |
| 156 | + </else></if> |
| 157 | + <!-- Name of the application package extracted from manifest file --> |
| 158 | + <xpath input="AndroidManifest.xml" expression="/manifest/@package" |
| 159 | + output="manifest.package" /> |
| 160 | + <copy file="${template.cfg}" tofile="${proguard.cfg}"> |
| 161 | + <filterchain> |
| 162 | + <replacetokens> |
| 163 | + <token key="HEADER" value="${header}" /> |
| 164 | + <token key="INJARS" value="${injars}" /> |
| 165 | + <token key="OUTJARS" value="${outjars}" /> |
| 166 | + <token key="LIBRARYJARS" value="${libraryjars}" /> |
| 167 | + <token key="PACKAGENAME" value="${manifest.package}" /> |
| 168 | + <token key="DEBUG" value="${debug.mode}" /> |
| 169 | + <token key="RELEASE" value="${release.mode}" /> |
| 170 | + </replacetokens> |
| 171 | + </filterchain> |
| 172 | + </copy> |
| 173 | + <if condition="${shrink.required}"><then> |
| 174 | + <proguard configuration="${proguard.cfg}" /> |
| 175 | + </then></if> |
| 176 | + </target> |
| 177 | + |
| 178 | + <!-- Macros --> |
| 179 | + |
| 180 | + <macrodef name="generate-header"> |
| 181 | + <attribute name="property" /> |
| 182 | + <sequential> |
| 183 | + <dirname property="parentdir" file="${basedir}" /> |
| 184 | + <pathconvert property="rel.template.cfg"> |
| 185 | + <map from="${parentdir}${file.separator}" to="" /> |
| 186 | + <path location="${template.cfg}" /> |
| 187 | + </pathconvert> |
| 188 | + <property name="@{property}" value="# This file is automatically generated from ${rel.template.cfg}" /> |
| 189 | + </sequential> |
| 190 | + </macrodef> |
| 191 | + |
| 192 | + <!-- split 'path' into several lines starting with 'prefix' and save result in 'property' --> |
| 193 | + <macrodef name="split-path"> |
| 194 | + <attribute name="property" /> |
| 195 | + <attribute name="prefix" /> |
| 196 | + <attribute name="path" /> |
| 197 | + <sequential> |
| 198 | + <tempfile property="temp.file" destdir="${out.dir}" deleteonexit="true" /> |
| 199 | + <echo message="@{path}" file="${temp.file}" /> |
| 200 | + <loadfile srcfile="${temp.file}" property="@{property}.list"> |
| 201 | + <filterchain> |
| 202 | + <replacestring from="${path.separator}" to="${line.separator}"/> |
| 203 | + <replaceregex pattern="(.*)" replace="@{prefix} \1" /> |
| 204 | + </filterchain> |
| 205 | + </loadfile> |
| 206 | + <property name="@{property}" value="${@{property}.list}" /> |
| 207 | + </sequential> |
| 208 | + </macrodef> |
| 209 | + |
| 210 | +</project> |
0 commit comments