common/build.xml
author Simon Howkins <simonh@symbian.org>
Tue, 18 Aug 2009 14:40:13 +0100
changeset 361 023e28d6bf31
parent 360 38e924ed959d
child 365 95e054b2bec1
permissions -rw-r--r--
Moved all targets specific to the postbuild phase of the build into the postbuild ant file.

<?xml version="1.0" encoding="UTF-8"?>
<project name="SF-COMMON-CONFIG" xmlns:hlm="http://www.nokia.com/helium">

    <property environment="env"/> <!-- make environment variables available via env -->
    
    <dirname property="sf.common.config.dir" file="${ant.file.SF-COMMON-CONFIG}"/>
    
    <!-- Import common properties -->
    <import file="${sf.common.config.dir}/common_props.ant.xml" />
    
    <!-- setup Helium internal properties from their equivalent in the project spec -->
    <property name="build.name" value="${sf.spec.job.name}"/>
    <property name="core.build.version" value="${sf.spec.job.codeline}"/>
    <property name="build.number" value="${sf.spec.job.number}"/>
    <property name="build.drive" value="${sf.spec.job.drive}"/>
    <property name="build.family" value="${sf.project.type}"/>
    <property name="email.from" value="${sf.spec.email.from}"/>
    <property name="local.free.space" value="${sf.spec.job.freespace}"/>
    <property name="network.free.space" value="${sf.spec.publish.network.freespace}"/>
    <property name="network.drive" value="${sf.spec.publish.networkdrive}"/>
    <property name="prep.root.dir" value="${sf.spec.job.rootdir}"/>
    <property name="publish" value="${sf.spec.publish.enable}"/>
    <property name="publish.root.dir" value="${sf.spec.publish.rootdir}"/>
    <property name="diamonds.host" value="${sf.spec.publish.diamonds.server}"/>
    <property name="diamonds.port" value="${sf.spec.publish.diamonds.port}"/>
    <property name="diamonds.path" value="${sf.spec.publish.diamonds.path}"/>
    <property name="build.system" value="${sf.spec.build.system}"/>
    <property name="base_release.path" value="${sf.spec.baseline.location}"/>
    <property name="base_release.getenv_options" value="${sf.spec.baseline.getenv_options}"/>
    
    <!-- SF-specific Helium properties not meant to be exposed in the project spec -->
    <property name="diamonds.listener.configuration.file" location="${sf.common.config.dir}/diamonds/config.xml.ftl"/>
    
    <!-- Import all core HELIUM targets -->
    <import file="${helium.dir}/helium.ant.xml" />
    
    <!-- Import common references -->
    <import file="${sf.common.config.dir}/common_refs.ant.xml" />
             
    <!-- Import functionality distributed into other file(s) -->
    <import file="${sf.common.config.dir}/build.postbuild.xml"/>
             
    <!-- setup conditional Helium internal properties -->
    <if><istrue value="${sf.spec.sourcesync.usecache}"/>
        <then>
            <property name="sf.spec.sourcesync.sourcespecdir" value="${sf.common.config.dir}/generated"/>
        </then>
        <else>
            <property name="sf.spec.sourcesync.sourcespecdir" value="${sf.project.location}"/>
        </else>
    </if>

    <!-- conditional import of generated source spec if available -->
    <if><available  file="${sf.common.config.dir}/generated/source-spec.ant.xml" />
        <then>
            <echo message="Generated source spec found, importing..." />
            <import file="${sf.common.config.dir}/generated/source-spec.ant.xml"/>
        </then>
    </if>
     
    
    <target name="sf-prep" depends="prep-drive,init-build-area,sf-generate-source-spec,check-tool-dependencies,create-bom,log-build-env">
        <echo>[SF-PREP]</echo>
        <tempfile property="prep.dynamic.config" suffix="ant.xml" destdir="${temp.build.dir}"/>
		<echo message="Checking build Environment"/>
          <exec executable="perl" dir="${sf.common.config.dir}/tools" failonerror="true">
            <arg value="CheckBuildEnv.pl"/>
            <arg value="--xml=BuildEnv.xml"/>
            <arg value="--dbg=${build.log.dir}/BuildEnvironmentCheck.log"/>
			<arg value="--sbs='${sf.spec.sbs.config}'"/>
			<arg value="--tools='${sf.spec.sbs.tools.config}'"/>
			<arg value="Common"/>
          </exec>
    </target>
        
    <target name="sf-build-all" depends="sf-prebuild,sf-build-noprep,sf-postbuild">
        <echo>[SF-BUILD-ALL]</echo>
    </target>
    
    <target name="sf-build-and-pack" depends="sf-build-noprep,sf-postbuild">
        <echo>[SF-BUILD-AND-PACK]</echo>
    </target>

    <target name="sf-build" depends="sf-prep,sf-prebuild,sf-build-noprep,sf-postbuild">
        <echo>[SF-BUILD]</echo>
    </target>
    
    <target name="sf-parse-project-config">
    <!-- TODO: Parse the project config and generate properties and csv file to be
    used by the builds. -->
        <echo message="Parse the project configuration" />
    </target>
    
    <target name="sf-generate-source-spec" depends="sf-parse-project-config">

        <!-- Generate the sources.csv if hg cache is activated -->
        <if><istrue value="${sf.spec.sourcesync.usecache}"/>
            <then>
                <echo message="Generating Hg local cache..." />
                <mkdir dir="${sf.common.config.dir}/generated"/>
                <exec executable="perl" dir="${build.log.dir}" failonerror="true" output="${build.log.dir}/${build.id}_hgcache.log">
                    <arg value="${sf.common.config.dir}/tools/cachefiles.pl"/>
                    <arg value="${sf.spec.sourcesync.cachelocation}"/>
                    <arg value="${sf.project.location}/${sf.spec.sourcesync.sourcespecfile}"/>
                    <arg value="${sf.common.config.dir}/generated/${sf.spec.sourcesync.sourcespecfile}"/>
                </exec>
            </then>
        </if>

        <!-- TODO: 1. Same file name souce-spec.ant.xml is used for all packages
        for multiple package builds, this needs to be linked with package name. -->
        <!-- TODO: 2. Change fmpp data to be a full property rather than relative path -->
        <delete file="${sf.common.config.dir}/generated/source-spec.ant.xml"/>
        
        <fmpp sourceFile="${sf.common.config.dir}/templates/source-spec.ant.xml.ftl"
              outputFile="${sf.common.config.dir}/generated/source-spec.ant.xml">
              <data expandProperties="yes">
                    ant: antProperties()
                    data: csv(${sf.spec.sourcesync.sourcespecdir}/${sf.spec.sourcesync.sourcespecfile}, {separator:','})
              </data>
        </fmpp>
    </target>
    
    <target name="generate-layers">
       <echo message="canno-file:${canonical.sysdef.file}"/>
       <echo message="raptor-filters:raptor_${sysdef.configuration}"/>

       <!-- All we want is a sysdef with the config name appended, so just copy it -->
       <echo message="INFO: Skip GenXML and copy sysdef to sysdef+config name"/>
       <copy file="${canonical.sysdef.file}" tofile="${build.drive}/output/build/canonical_system_definition_${sysdef.configuration}_temp.xml"/>

        <copy file="${build.drive}/output/build/canonical_system_definition_${sysdef.configuration}_temp.xml" tofile="${build.drive}/output/build/canonical_system_definition_${sysdef.configuration}.xml">
        <filterchain>
            <linecontainsregexp negate="true">
                <regexp pattern="^\s*$"/>
            </linecontainsregexp>
        </filterchain>
        </copy>
        <copy file="${build.drive}/output/build/canonical_system_definition_${sysdef.configuration}.xml" todir="${build.log.dir}/BOM/"/>
        <delete file="${build.drive}/output/build/canonical_system_definition_${sysdef.configuration}_temp.xml"/>
    </target>

    <target name="sf-prebuild">
        <echo>[SF-PREBUILD]</echo>
        
        <if>
            <istrue value="${sf.spec.publish.enable}"/>
            <then>
                <runtarget target="diamonds"/>
                <runtarget target="sf-tag-build"/>
            </then>
        </if>
        
        <!-- create BOM dir -->
        <mkdir dir="${build.drive}/output/logs/BOM"/>
        
        <!-- record project and config information in BOM files -->
        <delete file="${build.drive}/output/logs/BOM/config.csv" quiet="true"/>
        <exec executable="hg" dir="${sf.config.dir}" outputproperty="sf.job.bom.config.repo">
            <arg value="showconfig"/>
            <arg value="paths.default"/>
        </exec>
        <exec executable="hg" dir="${sf.config.dir}" outputproperty="sf.job.bom.config.rev">
            <arg value="identify"/>
            <arg value="-n"/>
        </exec>
        <exec executable="hg" dir="${sf.config.dir}" outputproperty="sf.job.bom.config.checksum">
            <arg value="identify"/>
            <arg value="-i"/>
        </exec>
        <echo message="dir ${sf.config.dir} : revision ${sf.job.bom.config.rev}:${sf.job.bom.config.checksum}"/>
        <exec executable="cmd" output="${build.drive}/output/logs/BOM/config.csv" append="true">
            <arg value="/c"/>
            <arg value="echo"/>
            <arg value="${sf.job.bom.config.repo},sf-config,${sf.job.bom.config.rev}:${sf.job.bom.config.checksum}"/>
        </exec>
        <delete file="${build.drive}/output/logs/BOM/project.csv" quiet="true"/>
        <exec executable="hg" dir="${sf.project.location}" outputproperty="sf.job.bom.project.repo">
            <arg value="showconfig"/>
            <arg value="paths.default"/>
        </exec>
        <exec executable="hg" dir="${sf.project.location}" outputproperty="sf.job.bom.project.rev">
            <arg value="identify"/>
            <arg value="-n"/>
        </exec>
        <exec executable="hg" dir="${sf.project.location}" outputproperty="sf.job.bom.project.checksum">
            <arg value="identify"/>
            <arg value="-i"/>
        </exec>
        <echo message="dir ${sf.project.location} : revision ${sf.job.bom.project.rev}:${sf.job.bom.project.checksum}"/>
        <exec executable="cmd" output="${build.drive}/output/logs/BOM/project.csv" append="true">
            <arg value="/c"/>
            <arg value="echo"/>
            <arg value="${sf.job.bom.project.repo},build/config,${sf.job.bom.project.rev}:${sf.job.bom.project.checksum}"/>
        </exec>

        <!-- tools baseline must come before epoc baseline to allow clean listing -->
        <if>
            <istrue value="${sf.spec.toolsbaseline.enable}" />
            <then>

                <!-- record toolsbaseline information in BOM file -->
                <delete file="${build.drive}/output/logs/BOM/toolsbaseline.txt" quiet="true"/>
                <exec executable="cmd" output="${build.drive}/output/logs/BOM/toolsbaseline.txt">
                    <arg value="/c"/>
                    <arg value="echo"/>
                    <arg value="${sf.spec.toolsbaseline.location}"/>
                </exec>

                <!-- wrapper around preparation-getenv but with diff params -->
                <runtarget target="sf-getenv-tools"/>
                
                <echo message="INFO Getting tools environment listing"/>
                <exec executable="perl" dir="${build.log.dir}/" failonerror="true" output="${build.log.dir}/listdir_${build.id}_toolsbaseline.log">
                    <arg value="${sf.common.config.dir}/tools/listdir.pl"/>
                    <arg value="${build.drive}/epoc32"/>
                </exec>
            </then>
            <else>
                <!-- record fact that no tools baseline used. required by diamondize-bom  -->
                <touch file="${build.drive}/output/logs/BOM/toolsbaseline.txt"/>
            </else>
        </if>        
        <if>
            <istrue value="${sf.spec.baseline.enable}" />
            <then>
            
                <!-- record baseline information in BOM file -->
                <delete file="${build.drive}/output/logs/BOM/baseline.txt" quiet="true"/>
                <exec executable="cmd" output="${build.drive}/output/logs/BOM/baseline.txt">
                    <arg value="/c"/>
                    <arg value="echo"/>
                    <arg value="${sf.spec.baseline.location}"/>
                </exec>
                
                <!-- run internal target preparation-getenv -->
                <runtarget target="preparation-getenv"/>
                
            </then>
            <else>
                <!-- record fact that no baseline used. required by diamondize-bom  -->
                <touch file="${build.drive}/output/logs/BOM/baseline.txt"/>
            </else>
        </if>

        <if>
            <istrue value="${sf.spec.sourcesync.enable}" />
            <then>
                <runtarget target="sf-get-source"/>                
                <runtarget target="sf-package-source"/>                
                <runtarget target="sf-unpack-rnd"/>
            </then>
            <else>
                <!-- record fact that no sources.csv used. required by diamondize-bom  -->
                <touch file="${build.log.dir}/BOM/sources.csv"/> 
            </else>
        </if>        
      <if>
        <istrue value="${sf.spec.publish.enable}"/>
        <then>
          <runtarget target="sf-diamondize-bom"/>
        </then>
      </if>
    </target>
    
    <target name="sf-tag-build">
      <echo>[SF-TAG-BUILD]</echo>
      <fmpp sourceFile="${sf.common.config.dir}/diamonds/sf-tag-build.xml.ftl" outputFile="${build.drive}/output/logs/sf-tag-build.xml">
        <data expandProperties="yes">
          ant: antProperties()
        </data>
      </fmpp>
    </target>
    
    <target name="sf-getenv-tools">
        <antcall target="preparation-getenv" inheritAll="false">
            <param name="base_release.path"           value="${sf.spec.toolsbaseline.location}"/>
            <param name="base_release.getenv_options" value="${sf.spec.toolsbaseline.getenv_options}"/>
        </antcall>
    </target>

    <!-- generate dir list using passed location and name 
    if a baseline list is available then generate deltas too -->

    <target name="sf-list-dir">
        <property name="sf.currentlist.name"   value="${sf.list.name}"/> 
        <property name="sf.dir.location" value="${build.drive}/epoc32"/> 
        <property name="sf.dir.exclude" value="${build.drive}/epoc32/build"/> 
    
        <if>
            <istrue value="${sf.spec.dirlist.enable}"/>
            <then>
                <echo message="Dirlist name: ${sf.currentlist.name} requested for ${sf.dir.location} excluding ${sf.dir.exclude}"/>
                <exec executable="python" dir="${build.log.dir}/" failonerror="true" output="${build.log.dir}/listdir_${build.id}_${sf.currentlist.name}.log">
                    <arg value="${sf.common.config.dir}/tools/listdir.py"/>
                    <arg value="${sf.dir.location}"/>
                    <arg value="${sf.dir.exclude}"/>
                </exec>
            </then>
        </if>
    </target>
    
    <target name="sf-delta-dir">
        <property name="sf.currentlist_a.name"   value="${sf.list_a.name}"/> 
        <property name="sf.currentlist_b.name"   value="${sf.list_b.name}"/>
        <property name="sf.dir.location" value="${build.drive}/epoc32"/> 
        
        <if>
            <istrue value="${sf.spec.dirdelta.enable}"/>
            <then>
                <echo message="Delta requested for ${sf.currentlist_a.name} vs ${sf.currentlist_b.name} "/>
                <exec executable="perl" dir="${build.log.dir}/" failonerror="true" output="${build.log.dir}/listdir_${build.id}_${sf.currentlist_b.name}_delta.log">
                    <arg value="${sf.common.config.dir}/tools/difflist.pl"/>
                    <arg value="${build.log.dir}/listdir_${build.id}_${sf.currentlist_a.name}.log"/>
                    <arg value="${build.log.dir}/listdir_${build.id}_${sf.currentlist_b.name}.log"/>
                </exec>
            </then>
        </if>
    </target>
  
    <target name="sf-intersect-dir">
        <property name="sf.currentlist_a.name"   value="${sf.list_a.name}"/> 
        <property name="sf.currentlist_b.name"   value="${sf.list_b.name}"/>
        <property name="sf.dir.location" value="${build.drive}/epoc32"/> 
    
        <if>
            <istrue value="${sf.spec.dirdelta.enable}"/>
            <then>
                <echo message="Inersection requested for ${sf.currentlist_a.name} vs ${sf.currentlist_b.name} "/>
                <exec executable="perl" dir="${build.log.dir}/" failonerror="true" output="${build.log.dir}/listdir_${build.id}_${sf.currentlist_b.name}_intersect.log">
                    <arg value="${sf.common.config.dir}/tools/difflist.pl"/>
                    <arg value="${build.log.dir}/listdir_${build.id}_${sf.currentlist_a.name}.log"/>
                    <arg value="${build.log.dir}/listdir_${build.id}_${sf.currentlist_b.name}.log"/>
                    <arg value="-I"/> <!-- run difflist in intersect mode -->
                </exec>
            </then>
        </if>
    </target>

    <target name="sf-build-noprep" depends="sf-truclean,sf-model-from-project,sf-compile,sf-postbuild">
        <echo>[SF-BUILD-NOPREP]</echo>
    </target>
    
    <target name="create-canonical-sysdef-file">
      <copy file="${build.drive}/${sf.spec.systemdefinition.location}" tofile="${canonical.sysdef.file}" failonerror="true" verbose="true"/>
    </target>
    
  <target name="sf-truclean">
    <if>
      <istrue value="${sf.spec.build.clean.enable}"/>
      <then>
        <echo message="Executing truclean step."/>
        <fmpp sourceFile="${sf.common.config.dir}/templates/truclean.ant.xml.ftl"
            outputFile="${sf.common.config.dir}/generated/truclean.ant.xml">
          <data expandProperties="yes">
              ant: antProperties()
              data: csv(${sf.spec.sourcesync.sourcespecdir}/${sf.spec.sourcesync.sourcespecfile}, {separator:','})
          </data>
        </fmpp>
        <ant antfile="${sf.common.config.dir}/generated/truclean.ant.xml"/>
      </then>
      <else>
        <echo message="Skipping truclean step."/>
      </else>
    </if>
  </target>
  
  <target name="sf-model-from-project">
    <if>
      <isset property="sf.spec.systemdefinition.source"/>
      <then>
        <echo message="Using ${sf.spec.systemdefinition.source} as model file"/>
        <echo message="Copying to ${build.drive}/definition.xml"/>
        <copy file="${sf.project.location}/${sf.spec.systemdefinition.source}" tofile="${build.drive}${sf.spec.systemdefinition.location}"/>
      </then>
      <else>
        <!-- Collate the system definition from the packages listed in sources.csv -->
        <echo message="Building system model from ${sf.spec.sourcesync.sourcespecdir}/${sf.spec.sourcesync.sourcespecfile}"/>
        <exec executable="perl" dir="${build.drive}/" output="${build.drive}${sf.spec.systemdefinition.location}" logError="true" failonerror="true">
          <arg value="${sf.common.config.dir}/tools/csvToSysDef.pl"/>
          <arg value="${sf.spec.sourcesync.sourcespecdir}/${sf.spec.sourcesync.sourcespecfile}"/>
          <arg value="${sf.config.dir}/../build/config/3k"/>
        </exec>
      </else>
    </if>
  </target>
    
    <target name="sf-get-source" depends="sf-generate-source-spec">
        <ant antfile="${sf.common.config.dir}/generated/source-spec.ant.xml" />
    </target>
    
    <target name="sf-diamondize-bom">
        <fmpp sourceFile="${sf.common.config.dir}/templates/build-info.xml.ftl"
              outputFile="${build.drive}/output/logs/sf-diamondize-bom.xml">
            <data expandProperties="yes">
                ant: antProperties()
                config: csv(${build.drive}/output/logs/BOM/config.csv,{separator:',',headers:[loc,dst,rev]})
                project: csv(${build.drive}/output/logs/BOM/project.csv,{separator:',',headers:[loc,dst,rev]})
                baseline: slicedText(${build.drive}/output/logs/BOM/baseline.txt,{trim})
                toolsbaseline: slicedText(${build.drive}/output/logs/BOM/toolsbaseline.txt,{trim})
                sources: csv(${build.drive}/output/logs/BOM/sources.csv,{separator:',',headers:[loc,dst,type,rev,sysdef]})              
            </data>
        </fmpp>
        <!-- Make a copy in BOM dir -->
        <copy file="${build.drive}/output/logs/sf-diamondize-bom.xml" tofile="${build.log.dir}/BOM/build-info.xml"/>
    </target>

    <target name="sf-preprocess-package-config">
        <mkdir dir="${sf.common.config.dir}/generated"/>
            <if><istrue value="${sf.spec.package.src.enable}"/>
            <then>
                <echo message="INFO Packaging Source Repos"/>
                <property name="sf-preprocess-package-config.arg" value=""/>
            </then>
            <else>
                <echo message="INFO Packaging: Ignoring Source Repos"/>
                <property name="sf-preprocess-package-config.arg" value="--nosource"/>
            </else>
            </if>

        <exec executable="perl" dir="${build.drive}/" failonerror="false" output="${build.log.dir}/zipconfig.log">
            <arg value="${sf.common.config.dir}/tools/populateziptemplate.pl"/>
            <arg value="${sf.spec.sourcesync.sourcespecdir}/${sf.spec.sourcesync.sourcespecfile}"/>
            <arg value="${sf.common.config.dir}/templates/zip.cfg.xml.ftl.template"/>
            <arg value="${sf.common.config.dir}/generated/zip.cfg.xml.ftl"/>
            <arg value="${build.log.dir}/rnd_excludefile.txt"/>
            <arg value="${sf-preprocess-package-config.arg}"/>
        </exec>
    </target>
    
    <target name="sf-zip-content" depends="preprocess-zip-config">
        <property name="zip.${zip.target.name}.log.file" location="${build.log.dir}/${build.id}_${zip.target.name}_zip.log" />
        <property name="zips.${zip.target.name}.spec.name" value="${zip.target.name}" />
        <hlm:zipContentMacro type="${zip.target.name}" file="${zip.config.file}" />
    </target>
    
    <target name="sf-package-source" depends="sf-preprocess-package-config">
        <!-- Firstly zip up src & rnd by package -->
        <antcall target="sf-zip-content">
            <param name="zip.config.file" value="${sf.common.config.dir}/generated/zip.cfg.xml.ftl"/>
            <param name="zip.target.name" value="src" />
        </antcall>
        <!-- Then zip up src zips by layer -->
        <antcall target="sf-zip-content">
            <param name="zip.config.file" value="${sf.common.config.dir}/generated/zip.cfg.xml.ftl"/>
            <param name="zip.target.name" value="src-by-layer" />
        </antcall>
    </target>
    
    <!-- unpack rnd zips if available -->
    <target name="sf-unpack-rnd">
        <echo message="Unpacking any available RnD binaries"/>
        <exec executable="7za" dir="${build.drive}" output="${build.log.dir}/unzip_${build.id}_binaries_rnd.log">
        <arg value="x"/>
        <arg value="-y"/> <!-- Need to unpack in overwrite mode, due to TEF -->
        <arg value="${build.drive}/output/zips/bin*.zip"/>
        </exec>
    </target>

    <target name="sf-find-ATS-worker-root">
      <exec executable="perl" dir="${sf.common.config.dir}/tools/ats/devices" failonerror="false" outputproperty="sf.spec.test.workerroot">
        <arg value="-pe"/>
        <arg value="&quot;m/TEMPDIR=(\S+)/;print $1;s/.*\n//g&quot;"/>
        <arg value="${env.COMPUTERNAME}\EMULATOR_GENERIC_${env.COMPUTERNAME}.properties" /> 
      </exec>
      <echo message="ATS Worker Root = ${sf.spec.test.workerroot}"/> 
    </target>
    
    <target name ="sf-make-junction" depends="sf-find-ATS-worker-root">
        
        <mkdir dir="${sf.spec.test.workerroot}/${sf.spec.test.epocroot}"/>

        <exec executable="perl" dir="${sf.common.config.dir}/tools/ats" failonerror="false" output="${build.log.dir}/ATS_${build.id}_make_junction.log">
        <arg value="make_junction.pl"/>
        <arg value="--link=${sf.spec.test.workerroot}/${sf.spec.test.epocroot}/epoc32"/>
        <arg value="--target=${build.drive}/epoc32"/>
        <arg value="--force"/>
      </exec>
    </target>

    <target name ="sf-delete-junction" depends="sf-find-ATS-worker-root">
        <exec executable="junction.exe" dir="${sf.spec.test.workerroot}/${sf.spec.test.epocroot}" failonerror="false" output="${build.log.dir}/ATS_${build.id}_delete_junction.log">
        <arg value="-d"/>
        <arg value="epoc32"/>
      </exec>
    </target>  
        
</project>