buildframework/helium/tools/publish/publish.ant.xml
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!-- 
       
     3 ============================================================================ 
       
     4 Name        : publish.ant.xml 
       
     5 Part of     : Helium 
       
     6 
       
     7 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 All rights reserved.
       
     9 This component and the accompanying materials are made available
       
    10 under the terms of the License "Eclipse Public License v1.0"
       
    11 which accompanies this distribution, and is available
       
    12 at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 
       
    14 Initial Contributors:
       
    15 Nokia Corporation - initial contribution.
       
    16 
       
    17 Contributors:
       
    18 
       
    19 Description:
       
    20 
       
    21 ============================================================================
       
    22 -->
       
    23 <!--* @package publishing -->
       
    24 <project name="publish" xmlns:hlm="http://www.nokia.com/helium">
       
    25     <description>
       
    26     Zipping, delta zipping and copying targets
       
    27     </description>
       
    28     
       
    29     <!--* @property delta.zip.file.size
       
    30     Define the file size of the zipped up released file, this is then used by delta zipping code to determine if a delta zip is required or a full zip should be created. The delta zip will only be published if it is less than 1/2 the size of this property
       
    31     @type string
       
    32     @editable required
       
    33     @scope public
       
    34     -->
       
    35 
       
    36     <!--* @property file-comparison.left_side
       
    37     The fileset id used on the left side of comparison.
       
    38     @type string
       
    39     @editable required
       
    40     @scope public
       
    41     -->
       
    42 
       
    43     <!--* @property file-comparison.right_side
       
    44     The fileset id used on the right side of comparison.
       
    45     @type string
       
    46     @editable required
       
    47     @scope public
       
    48     -->
       
    49 
       
    50     <import file="internal-api/internal-api.ant.xml" />
       
    51     <import file="nwiki.ant.xml" />
       
    52     <import file="synergy.ant.xml" />
       
    53     <import file="test/test2_publishing_to_diamonds.ant.xml" />
       
    54 
       
    55     <!-- Set the maximum number of threads running for archiving (for a parallel job).
       
    56     @type integer
       
    57     -->
       
    58     <property name="archive.max.number.of.threads" value="8" />
       
    59     
       
    60     <fileset id="publish.files" dir="${build.output.dir}">
       
    61         <include name="logs/**/*" />
       
    62         <exclude name="logs/**/*_ant_build.log" />
       
    63         <include name="development_flash_images/**/*" />
       
    64         <include name="release_flash_images/**/*" />
       
    65         <include name="sisfiles/**/*" />
       
    66         <include name="build_area/**/*" />
       
    67         <include name="relnotes/**/*" />
       
    68         <include name="test_results/**/*" />
       
    69         <include name="utilities/**/*" />
       
    70         <include name="images/**/*" />
       
    71         <include name="variant_images/**/*" />
       
    72         <include name="BaseForNightlyBuild.txt" />
       
    73     </fileset>
       
    74 
       
    75     <!-- above fileset divided into following 4 filesets-->
       
    76     <fileset id="publish.files1" dir="${build.output.dir}">
       
    77         <include name="logs/**/*" />
       
    78         <exclude name="logs/**/*_ant_build.log" />
       
    79     </fileset>
       
    80     <fileset id="publish.files2" dir="${build.output.dir}">
       
    81         <include name="development_flash_images/**/*" />
       
    82     </fileset>
       
    83     <fileset id="publish.files3" dir="${build.output.dir}">
       
    84         <include name="sisfiles/**/*" />
       
    85         <include name="build_area/**/*" />
       
    86         <include name="relnotes/**/*" />
       
    87         <include name="test_results/**/*" />
       
    88         <include name="utilities/**/*" />
       
    89         <include name="variant_images/**/*" />
       
    90         <include name="images/**/*" />
       
    91         <include name="BaseForNightlyBuild.txt" />
       
    92     </fileset>
       
    93     <fileset id="publish.files4" dir="${build.output.dir}">
       
    94         <include name="release_flash_images/**/*" />
       
    95     </fileset>
       
    96 
       
    97     <!-- list of filesets -->
       
    98     <!-- The fileset id which will be upload
       
    99     @type string
       
   100     -->
       
   101     <property name="publish.fileset.ids" value="publish.files1,publish.files2,publish.files3,publish.files4" />
       
   102 
       
   103     <fileset id="helium.files" dir="${helium.dir}">
       
   104         <include name="*.bat" />
       
   105         <include name="**/*.ant.xml" />
       
   106         <include name="tools/common/**/*" />
       
   107         <include name="tools/release/**/*" />
       
   108     </fileset>
       
   109 
       
   110     <!-- 
       
   111         If publish property is set, copy the publish.files fileset to the publish.dir directory using 
       
   112         number.of.threads parallel threads
       
   113     -->
       
   114     <macrodef name="publishMacro" uri="http://www.nokia.com/helium">
       
   115         <sequential>
       
   116             <if>
       
   117                 <isset property="publish" />
       
   118                 <then>
       
   119                     <for list="${publish.fileset.ids}" param="fileset.id" parallel="true" threadCount='${number.of.threads}'>
       
   120                         <sequential>
       
   121                             <copy todir="${publish.dir}" preservelastmodified="true" failonerror="false">
       
   122                                 <fileset refid="@{fileset.id}" />
       
   123                             </copy>
       
   124                         </sequential>
       
   125                     </for>
       
   126                 </then>
       
   127             </if>
       
   128         </sequential>
       
   129     </macrodef>
       
   130 
       
   131 
       
   132     <!-- Creates the publish directory. Directory location is defined by property: ${publish.dir} -->
       
   133     <target name="prep-publish" if="publish">
       
   134         <mkdir dir="${publish.dir}" />
       
   135     </target>
       
   136 
       
   137 
       
   138     <!-- Parses the zip configuration file. Expands all the ant properties. -->
       
   139     <target name="preprocess-zip-config">
       
   140         <!-- Path to the parsed file of zip specification file
       
   141         @type string
       
   142         @scope private
       
   143         -->
       
   144         <property name="zip.config.file.parsed" location="${temp.build.dir}/zip.cfg.xml.parsed" />
       
   145         <copy file="${zip.config.file}" tofile="${zip.config.file.parsed}" overwrite="true">
       
   146             <filterchain>
       
   147                 <expandproperties />
       
   148             </filterchain>
       
   149         </copy>
       
   150     </target>
       
   151 
       
   152 
       
   153     <!-- This macro merges all the generated metadata files together.
       
   154    
       
   155     It uses the archiving configuration to find the output archive directory.
       
   156     The it merges all the <config.name>.metadata.xml files together.
       
   157     e.g:
       
   158     <pre>
       
   159     <hlm:mergeMetadataMacro file="${zip.config.file.parsed}" config="${zips.@{type}.spec.name}"/>
       
   160     </pre>
       
   161     -->
       
   162     <macrodef name="mergeMetadataMacro" uri="http://www.nokia.com/helium">
       
   163         <attribute name="file" />
       
   164         <attribute name="config" />
       
   165         <sequential>
       
   166             <hlm:python>
       
   167                 <![CDATA[
       
   168 import configuration
       
   169 import symrec
       
   170 import os
       
   171 import sys
       
   172 import logging
       
   173 import ant
       
   174 
       
   175 LOGGER = logging.getLogger("metadatamerger")
       
   176 LOGGER.setLevel(level=logging.INFO)
       
   177 logging.basicConfig(level=logging.INFO)
       
   178 
       
   179 def merge_filelist(merger, filelist):
       
   180     for filename in filelist:
       
   181         try:
       
   182             LOGGER.info("Merging %s" % filename)
       
   183             merger.merge(filename)
       
   184             os.unlink(filename)
       
   185         except Exception, exc:
       
   186             LOGGER.warning("Warning: %s" % exc)
       
   187 
       
   188 try:
       
   189     builder = configuration.NestedConfigurationBuilder(open(ant.get_property(r'@{file}')), 'r')
       
   190     configSet = builder.getConfiguration()
       
   191     configs = configSet.getConfigurations(ant.get_property(r'@{config}'))
       
   192     
       
   193     if len(configs) > 0:
       
   194         filelist = []
       
   195         for config in configs:
       
   196             if config.get_boolean("grace.metadata", False):
       
   197                 metadata = os.path.join(config['archives.dir'], config['name']+ ".metadata.xml")
       
   198                 if os.path.exists(metadata):
       
   199                     LOGGER.info("Found %s" % metadata)
       
   200                     filelist.append(metadata)
       
   201         
       
   202         merger = None
       
   203         metadata_main = os.path.join(configs[0]['archives.dir'], "release_metadata.xml")
       
   204         if os.path.exists(metadata_main):
       
   205             merger = symrec.MetadataMerger(metadata_main)
       
   206             merge_filelist(merger, filelist)
       
   207             LOGGER.info(str("Writing %s" % metadata_main))
       
   208             merger.save()
       
   209         elif len(filelist) > 0:
       
   210             input = filelist.pop(0)
       
   211             merger = symrec.MetadataMerger(input)
       
   212             merge_filelist(merger, filelist)
       
   213             LOGGER.info(str("Writing %s" % metadata_main))
       
   214             merger.save(metadata_main)
       
   215             os.unlink(input)
       
   216 except Exception, e:
       
   217     LOGGER.error('ERROR: %s' % e)
       
   218     sys.exit(-1)
       
   219 ]]> 
       
   220             </hlm:python>
       
   221         </sequential>
       
   222     </macrodef>
       
   223 
       
   224     <!-- This macro allows you to add or update one archive definition inside the release metadata files.
       
   225     e.g.:
       
   226     <pre>
       
   227         <hlm:updateMetadataMacro file="<path>/release_metadata.xml" archive="<path>/archive.zip" />
       
   228     </pre>
       
   229      -->
       
   230     <macrodef name="updateMetadataMacro" uri="http://www.nokia.com/helium">
       
   231         <attribute name="file" />
       
   232         <attribute name="archive" />
       
   233         <attribute name="filters" default=""/>
       
   234         <sequential>
       
   235             <hlm:python>
       
   236         <![CDATA[
       
   237 import symrec
       
   238 import os
       
   239 import traceback
       
   240 import fileutils
       
   241 import ant
       
   242 import sys
       
   243 import logging
       
   244 
       
   245 LOGGER = logging.getLogger("metadataupdater")
       
   246 LOGGER.setLevel(level=logging.INFO)
       
   247 logging.basicConfig(level=logging.INFO)
       
   248 
       
   249 if ant.get_property(r'@{file}') is None:
       
   250     raise Exception('file attribute is not defined.')
       
   251 if ant.get_property(r'@{archive}') is None:
       
   252     raise Exception('archive attribute is not defined.')
       
   253 filters = None
       
   254 if ant.get_property(r'@{filters}') is not None:
       
   255     filters = ant.get_property(r'@{filters}').split(r',')
       
   256 
       
   257 try:
       
   258     filename = ant.get_property(r'@{file}')
       
   259     archive = ant.get_property(r'@{archive}')
       
   260     if not os.path.exists(filename):
       
   261         raise Exception("Could not find file: %s" % filename)
       
   262     if not os.path.exists(archive):
       
   263         raise Exception("Could not find file: %s" % archive)
       
   264 
       
   265     LOGGER.info(str("Opening %s" % filename))
       
   266     md = symrec.ReleaseMetadata(filename)
       
   267     if os.path.basename(archive) not in md.keys():
       
   268         LOGGER.info(str("Adding %s to metadata" % os.path.basename(archive)))
       
   269         md.add_package(os.path.basename(archive), md5checksum=fileutils.getmd5(archive), size=os.path.getsize(archive), filters=filters)
       
   270     else:
       
   271         LOGGER.info(str("Updating %s to metadata" % os.path.basename(archive)))
       
   272         result = md[os.path.basename(archive)]
       
   273         result['md5checksum'] = unicode(fileutils.getmd5(archive))
       
   274         result['size'] = unicode(os.path.getsize(archive))
       
   275         if filters is not None:
       
   276             result['filters'] = filters
       
   277         md[os.path.basename(archive)] = result
       
   278     md.save()
       
   279 except Exception, e:
       
   280     LOGGER.error('ERROR: %s' % e)
       
   281     sys.exit(-1)
       
   282 ]]> 
       
   283             </hlm:python>
       
   284         </sequential>
       
   285     </macrodef>
       
   286     
       
   287     <!-- This macro update the metadata file generated by the config provided by file.
       
   288     e.g:
       
   289     <pre>
       
   290     <hlm:updateMD5Macro file="${zip.config.file.parsed}" config="${zips.@{type}.spec.name}"/>
       
   291     </pre>
       
   292     -->
       
   293     <macrodef name="updateMD5Macro" uri="http://www.nokia.com/helium">
       
   294         <attribute name="file" />
       
   295         <attribute name="config" />
       
   296         <sequential>
       
   297             <hlm:python>
       
   298         <![CDATA[
       
   299 import configuration
       
   300 import archive
       
   301 import os
       
   302 import symrec
       
   303 import ant
       
   304 import logging
       
   305 import sys
       
   306 
       
   307 LOGGER = logging.getLogger("metadataMD5updater")
       
   308 LOGGER.setLevel(level=logging.INFO)
       
   309 logging.basicConfig(level=logging.INFO)
       
   310           
       
   311 # Reading the config from Ant
       
   312 try:
       
   313     config_filename = ant.get_property(r'@{file}')
       
   314     spec_name = ant.get_property(r'@{config}')
       
   315     # Loading the config file.                        
       
   316     builder = configuration.NestedConfigurationBuilder(open(config_filename, 'r'))
       
   317     configSet = builder.getConfiguration()
       
   318     configs = configSet.getConfigurations(spec_name)
       
   319 
       
   320     if len(configs) > 0:
       
   321         if os.path.exists(os.path.join(configs[0]['archives.dir'], "release_metadata.xml")):
       
   322             md5update = symrec.MD5Updater(os.path.join(configs[0]['archives.dir'], "release_metadata.xml"))
       
   323             md5update.update()
       
   324             md5update.save()
       
   325         else:
       
   326             LOGGER.warning(str('WARNING: Could not find %s.' % os.path.join(configs[0]['archives.dir'], "release_metadata.xml")))
       
   327     else:
       
   328         LOGGER.warning('WARNING: No config.')
       
   329 except Exception, e:
       
   330     LOGGER.error('ERROR: %s' % e)
       
   331     sys.exit(-1)
       
   332 ]]> 
       
   333         </hlm:python>
       
   334         </sequential>
       
   335     </macrodef>
       
   336 
       
   337     <condition property="archive.using.ec">
       
   338         <or>
       
   339             <equals arg1="${build.system}" arg2="ec-helium" />
       
   340             <equals arg1="${build.system}" arg2="sbs-ec" />
       
   341         </or>
       
   342     </condition>
       
   343     
       
   344     <!-- Zips files using a type and zip config file as args -->
       
   345     <macrodef name="zipContentMacro" uri="http://www.nokia.com/helium">
       
   346         <attribute name="type" />
       
   347         <attribute name="file" />
       
   348         <attribute name="ec" default="${archive.using.ec}"/>
       
   349         <attribute name="failonemptyconfig" default="true"/>
       
   350         <attribute name="phase" default="archive"/>
       
   351         <sequential>
       
   352             <if>
       
   353                 <not>
       
   354                     <isset property="zip.@{type}.log.file" />
       
   355                 </not>
       
   356                 <then>
       
   357                     <property name="zip.@{type}.log.file" location="${@{phase}.log.dir}/${build.id}_@{type}_zip.log" />
       
   358                 </then>
       
   359             </if>
       
   360             <mkdir dir="${@{phase}.log.dir}"/>
       
   361             <mkdir dir="${post.log.dir}"/>
       
   362             <property name="zip.@{type}.nopolicy.log.file" location="${@{phase}.log.dir}/${build.id}_@{type}_archive.nopolicy.log" />
       
   363             <property name="zip.@{type}.policy.log.file" location="${@{phase}.log.dir}/${build.id}_@{type}_archive.policy.log" />
       
   364             <trycatch property="exception" reference="exception">
       
   365                 <try>
       
   366                     <!-- Don't print 'compressing' on console -->
       
   367                     <hlm:logtoconsole action="stop" />
       
   368                     <!-- Stops writing on ...ant_build.log file-->
       
   369                     <hlm:startSpecificLogMacro name="${zip.@{type}.log.file}" phase="@{phase}"/>
       
   370             
       
   371                     <!-- Path to the parsed file of zip specification file
       
   372                     @type string
       
   373                     @scope private
       
   374                     -->
       
   375                     <property name="zip.config.file.parsed" location="${temp.build.dir}/zip.cfg.xml.parsed" />
       
   376                     <copy file="@{file}" tofile="${zip.config.file.parsed}" overwrite="true">
       
   377                         <filterchain>
       
   378                             <expandproperties />
       
   379                         </filterchain>
       
   380                     </copy>
       
   381                     <hlm:updateArchiveConfig configtype="${zips.@{type}.spec.name}" configfileparsed="${zip.config.file.parsed}" usingec="@{ec}" failonemptyconfig="@{failonemptyconfig}"/>
       
   382                     <if>
       
   383                         <istrue value="@{ec}" />
       
   384                         <then>
       
   385                             <echo>emake.root.to.append=${emake.root.to.append}</echo>
       
   386                             <hlm:emakeMacro name="archive-full-@{type}" makefile="${build.drive}/ZIP_${zips.@{type}.spec.name}.make" target="all" dir="${build.drive}/" annodetail="basic,history,file,waiting" root="${emake.root.to.append}" failonerror="false" phase="archive"/>
       
   387                         </then>
       
   388                         <else>
       
   389                             <if>
       
   390                                 <isgreaterthan arg1="${number.of.threads}" arg2="${archive.max.number.of.threads}"/>
       
   391                                 <then>
       
   392                                     <ant antfile="${build.drive}/ZIP_${zips.@{type}.spec.name}.xml">
       
   393                                         <!-- how many parallel threads can run
       
   394                                         @type string
       
   395                                         -->
       
   396                                         <property name="number.of.threads" value="${archive.max.number.of.threads}"/>
       
   397                                     </ant>
       
   398                                 </then>
       
   399                                 <else>
       
   400                                     <ant antfile="${build.drive}/ZIP_${zips.@{type}.spec.name}.xml" />
       
   401                                 </else>
       
   402                             </if>
       
   403                         </else>
       
   404                     </if>
       
   405                     <hlm:python>
       
   406 import archive
       
   407 import configuration
       
   408 
       
   409 builder = configuration.NestedConfigurationBuilder(open(r'${zip.config.file.parsed}', 'r'))
       
   410 configSet = builder.getConfiguration()
       
   411 configs = configSet.getConfigurations(r'${zips.@{type}.spec.name}')
       
   412 prebuilder = archive.ArchivePreBuilder(configuration.ConfigurationSet(configs), r'${zips.@{type}.spec.name}')
       
   413 prebuilder.cleanupSubstDrives()
       
   414                     </hlm:python>
       
   415                     <hlm:mergeMetadataMacro file="${zip.config.file.parsed}" config="${zips.@{type}.spec.name}" />
       
   416                     <hlm:updateMD5Macro file="${zip.config.file.parsed}" config="${zips.@{type}.spec.name}" />
       
   417                 </try>
       
   418                 <catch>
       
   419                     <!-- Printing and propagating the error -->
       
   420                     <echo>ERROR: ${exception}</echo>
       
   421                     <throw refid="exception"/>
       
   422                 </catch>
       
   423                 <finally>
       
   424                     <!-- Todo: metadata: Convert to metadata structure -->
       
   425                     <!-- Stops log back to main log. -->
       
   426                     <hlm:stopSpecificLogMacro name="${zip.@{type}.log.file}" phase="@{phase}"/>
       
   427                     <hlm:logtoconsole action="resume" />
       
   428                 </finally>
       
   429             </trycatch>
       
   430             <hlm:assertFileExists file="${zip.@{type}.log.file}" />
       
   431             <copy file="${zip.@{type}.log.file}" tofile="${zip.@{type}.nopolicy.log.file}" verbose="true">
       
   432                 <filterchain>
       
   433                     <linecontainsregexp negate="true">
       
   434                         <regexp pattern="POLICY_(ERROR|WARNING|INFO)" />
       
   435                     </linecontainsregexp>
       
   436                 </filterchain>
       
   437             </copy>
       
   438             <hlm:metadatarecord database="${metadata.dbfile}">
       
   439                 <hlm:textmetadatainput>
       
   440                     <fileset casesensitive="false" file="${zip.@{type}.nopolicy.log.file}" />
       
   441                     <metadatafilterset refid="filterset.archive.nopolicy" />
       
   442                 </hlm:textmetadatainput>
       
   443             </hlm:metadatarecord>
       
   444             <hlm:signalMacro logfile="${zip.@{type}.nopolicy.log.file}" 
       
   445                 signal.input="archiveErrorSignalInput" />
       
   446 
       
   447             <!-- Extracting policy errors from archiving. -->
       
   448             <copy file="${zip.@{type}.log.file}" tofile="${zip.@{type}.policy.log.file}" verbose="true">
       
   449                 <filterchain>
       
   450                     <linecontainsregexp>
       
   451                         <regexp pattern="POLICY_(ERROR|WARNING|INFO)" />
       
   452                     </linecontainsregexp>
       
   453                     <tokenfilter>
       
   454                         <replaceregex pattern=".*(POLICY_(?:ERROR|WARNING|INFO))" replace="\1" flags="gi" />
       
   455                     </tokenfilter>
       
   456                 </filterchain>
       
   457             </copy>
       
   458             <hlm:assertFileExists file="${zip.@{type}.policy.log.file}" />
       
   459             <hlm:metadatarecord database="${metadata.dbfile}">
       
   460                 <hlm:textmetadatainput>
       
   461                     <fileset casesensitive="false" file="${zip.@{type}.policy.log.file}" />
       
   462                     <metadatafilterset refid="filterset.archive.policy" />
       
   463                 </hlm:textmetadatainput>
       
   464             </hlm:metadatarecord>
       
   465             <hlm:signalMacro logfile="${zip.@{type}.policy.log.file}" 
       
   466                 signal.input="archivePolicyErrorSignalInput" />
       
   467         </sequential>
       
   468     </macrodef>
       
   469     
       
   470     <!--
       
   471     1. To update the archive configuration file with substituted drives information for UNC paths (if any).
       
   472     2. To create the .make file to zip the sources using EC.    
       
   473     -->
       
   474     <scriptdef name="updateArchiveConfig" language="jython" uri="http://www.nokia.com/helium">
       
   475         <attribute name="configtype" />
       
   476         <attribute name="configfileparsed" />
       
   477         <attribute name="usingec" />
       
   478         <attribute name="failonemptyconfig" />
       
   479         <![CDATA[
       
   480 import archive
       
   481 import configuration
       
   482 import logging
       
   483 import os
       
   484 
       
   485 failonemptyconfig = True      
       
   486 if attributes.get('failonemptyconfig'):
       
   487     failonemptyconfig = str(attributes.get('failonemptyconfig')).lower() == "true"
       
   488 config_parsed_filename = str(attributes.get('configfileparsed'))
       
   489 config_type = str(attributes.get('configtype'))
       
   490 is_it_ec = str(attributes.get('usingec'))
       
   491                         
       
   492 builder = configuration.NestedConfigurationBuilder(open(config_parsed_filename, 'r'))
       
   493 configSet = builder.getConfiguration()
       
   494 configs = configSet.getConfigurations(config_type)
       
   495 
       
   496 outputtype = 'ant'
       
   497 outputext = '.xml'
       
   498 if is_it_ec == "true":
       
   499     outputtype = 'make'
       
   500     outputext = '.make'
       
   501 
       
   502 if len(configs) > 0 or not failonemptyconfig:
       
   503     prebuilder = archive.ArchivePreBuilder(configuration.ConfigurationSet(configs), config_type, outputtype)
       
   504     if os.sep == '\\':
       
   505         toAppendEmakeRoot = prebuilder.checkRootDirValue(builder, config_parsed_filename, project.getProperty('build.drive'), config_type)
       
   506         if toAppendEmakeRoot is not None:
       
   507             project.setProperty("emake.root.to.append", str(toAppendEmakeRoot))
       
   508     prebuilder.writeTopLevel(os.path.join(project.getProperty('build.drive') + os.sep, 'ZIP_' + config_type + outputext), project.getProperty('temp.build.dir'), config_parsed_filename)       
       
   509 else:
       
   510     raise Exception('There are no archive configs to build. Looked for %s' % config_type)
       
   511 ]]>
       
   512     </scriptdef>
       
   513     
       
   514 
       
   515     <!-- Zips the Engineering English content. -->
       
   516     <target name="zip-ee" unless="skip-zips">
       
   517         <hlm:zipContentMacro type="ee" file="${zip.config.file}" />
       
   518     </target>
       
   519 
       
   520     <!-- Zips the subcon content. -->
       
   521     <target name="zip-subcon" unless="skip-zips">
       
   522         <hlm:zipContentMacro type="subcon" file="${zip.config.file}" />
       
   523     </target>
       
   524 
       
   525 
       
   526     <!-- Zips the subcon rom content. -->
       
   527     <target name="zip-subcon-roms" unless="skip-zips">
       
   528         <hlm:zipContentMacro type="subcon_roms" file="${zip.config.file}" />
       
   529     </target>
       
   530 
       
   531 
       
   532     <!-- Zips the localised content. -->
       
   533     <target name="zip-localised" unless="skip-zips">
       
   534         <hlm:zipContentMacro type="localised" file="${zip.config.file}" />
       
   535     </target>
       
   536 
       
   537 
       
   538     <!-- Zips the trace rom content -->
       
   539     <target name="zip-trace-roms" unless="skip-zips">
       
   540         <hlm:zipContentMacro type="trace_roms" file="${zip.config.file}" />
       
   541     </target>
       
   542 
       
   543     <!-- Publishes the content defined by the filesets at the top of this project.
       
   544     
       
   545     The files are split into 4 filesets to parallelize the publish operation:
       
   546     
       
   547     * publish.files1
       
   548     * publish.files2
       
   549     * publish.files3
       
   550     * publish.files4
       
   551     
       
   552     All content is copied to the location defined by publish.dir. Also verify the source and target content after publish.
       
   553     -->
       
   554     <target name="publish" depends="prep-publish" if="publish">
       
   555         <hlm:publishMacro />
       
   556         <resourcecount property="total.changes.in.fileset">
       
   557             <fileset id="publish.files.location" dir="${build.output.dir}">
       
   558                 <exclude name="logs/**/*_ant_build.log" />
       
   559                 <exclude name="*" />
       
   560                 <exclude name="build/**/*" />
       
   561                 <exclude name="ec/**/*" />
       
   562                 <exclude name="temp_build_files/**/*" />
       
   563                 <exclude name="uda/**/*" />
       
   564                 <different targetdir="${publish.dir}" ignoreFileTimes="true" ignoreContents="yes" />
       
   565             </fileset>
       
   566         </resourcecount>
       
   567         <if>
       
   568             <not>
       
   569                 <equals arg1="${total.changes.in.fileset}" arg2="0" />
       
   570             </not>
       
   571             <then>
       
   572                 <echo message="ERROR: There are ${total.changes.in.fileset} changes in the publish directory. Uploading the changes again..." />
       
   573                 <hlm:publishMacro />
       
   574             </then>
       
   575         </if>
       
   576     </target>
       
   577 
       
   578 
       
   579     <!-- Basic publish target that publishes all important content. -->
       
   580     <target name="publish-generic" depends="prep-publish,publish-tools" if="publish">
       
   581         <hlm:publishMacro />
       
   582     </target>
       
   583 
       
   584 
       
   585     <!-- Publishes tools needed to run commands from a published build area. -->
       
   586     <target name="publish-tools" depends="prep-publish" if="publish">
       
   587         <echoproperties destfile="${publish.dir}/build_properties.txt">
       
   588             <propertyset>
       
   589                 <propertyref name="publish.dir" />
       
   590                 <propertyref name="publish.release.dir" />
       
   591             </propertyset>
       
   592         </echoproperties>
       
   593         <copy todir="${publish.dir}" preservelastmodified="true" failonerror="false">
       
   594             <fileset refid="helium.files" />
       
   595         </copy>
       
   596         <copy todir="${publish.dir}" preservelastmodified="true" failonerror="false">
       
   597             <fileset dir="${helium.dir}/tools/publish/publish_dir_files" includes="*" />
       
   598         </copy>
       
   599     </target>
       
   600 
       
   601 
       
   602     <!-- The same as a basic publish. -->
       
   603     <target name="publish-variants" depends="prep-publish" if="publish">
       
   604         <hlm:publishMacro />
       
   605     </target>
       
   606 
       
   607 
       
   608     <!-- Notifies the lxr indexing engine that the build area is ready to be indexed. -->
       
   609     <target name="lxr">
       
   610         <copy todir="${lxr.publish.dir}" preservelastmodified="true" failonerror="false" flatten="true">
       
   611             <fileset refid="publish.files" />
       
   612         </copy>
       
   613         <echo file="${lxr.publish.dir}\${build.id}_ready.txt" />
       
   614     </target>
       
   615 
       
   616 
       
   617     <!-- Mails the Diamonds XML data to the Diamonds server account. -->
       
   618     <target name="mail-log-to-diamonds">
       
   619         <runtarget target="lookup-email" />
       
   620         <echo message="Sending XML log through email." />
       
   621         <!--Ant mail task can not include xml as msg body. so do it in python-->
       
   622         <!-- TODO - would this work by using a <message> subelement? -->
       
   623         <hlm:python>
       
   624 import sys, smtplib, string
       
   625             
       
   626 fromaddr = r'${email.from}'
       
   627 toaddrs  = r'${diamonds.mail}'
       
   628 smtpserver  = r'${email.smtp.server}'
       
   629 subject  = "[DIAMONDS_DATA] ${build.id}>>>${diamonds.host}>>>${diamonds.path}"
       
   630 file = open(r'${diamonds.log.file}', 'r')
       
   631 msg = file.read()
       
   632 body = string.join(("From: %s" %fromaddr, "To: %s" %toaddrs, "Subject: %s" %subject, "", msg), "\r\n")
       
   633 try:
       
   634     server = smtplib.SMTP(smtpserver)
       
   635     server.sendmail(fromaddr, toaddrs, body)
       
   636     server.quit()
       
   637     print "Mail sent to " , toaddrs
       
   638 except Exception:
       
   639     print "SMTP server " + smtpserver + " unavailable!! Unable to send log to " , toaddrs
       
   640     
       
   641         </hlm:python>
       
   642     </target>
       
   643 
       
   644     <!-- Reports on the status of the build, through other targets. -->
       
   645     <target name="report" depends="binary-sizes-log"/>
       
   646 
       
   647     <!-- Delta zips -->
       
   648 
       
   649     <!-- Output location
       
   650     @type string
       
   651     @scope private
       
   652     -->
       
   653     <property name="delta.zip.location" value="${build.output.dir}/build_area/delta_zip" />
       
   654     <!-- Temp location
       
   655     @type string
       
   656     @scope private
       
   657     -->
       
   658     <property name="delta.zip.temp.location" value="${temp.build.dir}/delta_zip" />
       
   659     <!-- The zip file
       
   660     @type string
       
   661     @scope private
       
   662     -->
       
   663     <property name="delta.zip.file" value="${delta.zip.location}/${build.id}_delta_zip.zip" />
       
   664     <!-- Define the file size of the zipped up released file, this is then used by delta zipping code to determine if a delta zip is required or a full zip should be created. The delta zip will only be published if it is less than 1/2 the size of this property
       
   665     @type string
       
   666     -->
       
   667     <property name="delta.zip.file.size" value="11000000" />
       
   668     <!--default value of approx 11GB-->
       
   669 
       
   670     <!-- Special Instructions file for SymDEC
       
   671     @type string
       
   672     @scope private
       
   673     -->
       
   674     <property name="delta.zip.delete.file" value="${delta.zip.location}/specialInstructions.xml" />
       
   675     <!-- Temp file
       
   676     @type string
       
   677     @scope private
       
   678     -->
       
   679     <property name="delta.ant.file" value="${delta.zip.temp.location}/delta_zip.ant.xml" />
       
   680     <!-- Output location of md5 file
       
   681     @type string
       
   682     @scope private
       
   683     -->
       
   684     <property name="md5.signature.file" value="${delta.zip.location}/${build.id}.md5" />
       
   685     <!-- Number of partial md5 files to use during creation
       
   686     @type string
       
   687     @scope private
       
   688     -->
       
   689     <property name="md5.split" value="100" />
       
   690     <!-- old.md5.file needs to be specified by the user -->
       
   691 
       
   692 
       
   693     <!-- Patch evalid tool. @scope private-->
       
   694     <target name="patch-evalid">
       
   695         <patch patchfile="${helium.dir}/tools/publish/evalidmd5.patch" originalfile="${build.drive}/epoc32/tools/evalidmd5.pm" />
       
   696     </target>
       
   697 
       
   698 
       
   699     <!-- Revert evalid patch. @scope private-->
       
   700     <target name="unpatch-evalid">
       
   701         <patch reverse="true" patchfile="${helium.dir}/tools/publish/evalidmd5.patch" originalfile="${build.drive}/epoc32/tools/evalidmd5.pm" />
       
   702     </target>
       
   703 
       
   704 
       
   705     <!-- Copy extra tool for evalid. @scope private-->
       
   706     <target name="pre-build-md5" depends="patch-evalid">
       
   707         <copy todir="${build.drive}\epoc32\tools" file="${helium.dir}/tools/publish/evalid_multiple.pl" />
       
   708     </target>
       
   709 
       
   710 
       
   711     <!-- Revert patches. @scope private-->
       
   712     <target name="post-build-md5" depends="unpatch-evalid" />
       
   713 
       
   714 
       
   715     <!-- Generate a list of checksums for all files in the build area using EBS system. @scope private-->
       
   716     <target name="build-md5-ebs" depends="pre-build-md5">
       
   717         <mkdir dir="${delta.zip.location}" />
       
   718         <hlm:python failonerror="true">
       
   719 import os
       
   720 import delta_zip
       
   721 builder = delta_zip.MD5SignatureBuilderEBS("${build.drive}", r"${md5.split}", r"${delta.zip.temp.location}", r"${delta.exclude.commasep}", r"${delta.zip.temp.location}\list_files.txt")
       
   722 builder.build(r"${md5.signature.file}")       
       
   723         </hlm:python>
       
   724 
       
   725         <antcall target="post-build-md5" />
       
   726     </target>
       
   727 
       
   728     <!-- Generate a list of checksums for all files in the build area using EC system. @scope private-->
       
   729     <target name="build-md5-ec" depends="pre-build-md5">
       
   730         <mkdir dir="${delta.zip.location}" />
       
   731         <echo>delta.zip.temp.location: ${delta.zip.temp.location}</echo>
       
   732         <hlm:python failonerror="true">
       
   733 import os
       
   734 import delta_zip
       
   735 builder = delta_zip.MD5SignatureBuilderEC("${build.drive}", r"${md5.split}", r"${delta.zip.temp.location}", r"${delta.exclude.commasep}", "${ec.cluster.manager}", "${ec.build.class}", r"${delta.zip.temp.location}\list_files.txt")
       
   736 builder.build("${md5.signature.file}")       
       
   737         </hlm:python>
       
   738 
       
   739         <antcall target="post-build-md5" />
       
   740     </target>
       
   741 
       
   742 
       
   743     <!-- Generate a list of checksums for all files in the build area -->
       
   744     <target name="build-md5">
       
   745         <!-- Comma seperated excluded directories from the zip
       
   746         @type string
       
   747         @scope public
       
   748         -->
       
   749         <property name="delta.exclude.commasep" value="epoc32_save.zip,output/**/*,delta_zips/**/*,temp/**/*,epoc32/**/*.sym,epoc32/BUILD/**/*" />
       
   750         <echo>build MD5 started</echo>
       
   751         <if>
       
   752             <isset property="build.system.ec-helium" />
       
   753             <then>
       
   754                 <echo>build EC MD5</echo>
       
   755                 <antcall target="build-md5-ec" />
       
   756             </then>
       
   757             <else>
       
   758                 <echo>build EBS MD5</echo>
       
   759                 <antcall target="build-md5-ebs" />
       
   760             </else>
       
   761         </if>
       
   762     </target>
       
   763 
       
   764 
       
   765     <!-- Compare builds using md5 files and generate zips -->
       
   766     <target name="generate-delta" if="old.md5.file.present">
       
   767         <hlm:python>
       
   768 import delta_zip
       
   769 
       
   770 delta = delta_zip.DeltaZipBuilder(r'${build.drive}', r'${delta.zip.temp.location}', r'${old.md5.file}', r'${md5.signature.file}')
       
   771 delta.create_delta_zip(r'${delta.zip.file}', r'${delta.zip.delete.file}', r'${number.of.threads}', r'${delta.ant.file}')
       
   772         </hlm:python>
       
   773 
       
   774         <ant antfile="${delta.ant.file}" />
       
   775 
       
   776         <hlm:python outputproperty="old.release.label">
       
   777 import ant
       
   778 import os
       
   779 md5file = os.path.basename(ant.get_property(r'${old.md5.file}'))
       
   780 print md5file.replace('.md5', '')
       
   781         </hlm:python>
       
   782 
       
   783         <move file="${delta.zip.delete.file}" todir="${delta.zip.temp.location}" />
       
   784         <move file="${md5.signature.file}" todir="${delta.zip.temp.location}" />
       
   785 
       
   786         <exec executable="C:\APPS\symrec\symrec" failonerror="${failonerror}">
       
   787             <arg value="create" />
       
   788             <arg value="-ser" />
       
   789             <arg value="${release.grace.service}" />
       
   790             <arg value="-pro" />
       
   791             <arg value="${release.grace.product}" />
       
   792             <arg value="-rel" />
       
   793             <arg value="${release.label}" />
       
   794             <arg value="-relroot" />
       
   795             <arg value="${delta.zip.location}" />
       
   796             <arg value="-dep" />
       
   797             <arg value="${release.grace.service}/${release.grace.product}/${old.release.label}" />
       
   798         </exec>
       
   799 
       
   800         <move file="${delta.zip.temp.location}/specialInstructions.xml" tofile="${delta.zip.delete.file}" />
       
   801         <move file="${delta.zip.temp.location}/${build.id}.md5" tofile="${md5.signature.file}" />
       
   802 
       
   803     </target>
       
   804 
       
   805 
       
   806     <!-- Set prop old.md5.file to md5 file from last build in publish dir -->
       
   807     <target name="delta-use-last-build">
       
   808         <!-- Location of current build md5 file
       
   809         @type string
       
   810         @scope private
       
   811         -->
       
   812         <property name="md5.current.build" value="${publish.dir}/build_area/delta_zip/${build.id}.md5" />
       
   813         <hlm:python outputproperty="old.md5.file">
       
   814 import re
       
   815 import ant
       
   816 import os
       
   817 
       
   818 previousbuildnumber = 1
       
   819 buildnum = r"${build.number}"
       
   820 
       
   821 while(previousbuildnumber > 0 and previousbuildnumber != ''):
       
   822     previousbuildnumber = ant.get_previous_build_number(buildnum)
       
   823     
       
   824     try:
       
   825         md5lastbuild = re.sub(r'\.(${build.number})([\/_.])', r'.' + previousbuildnumber + r'\2', r'${md5.current.build}')
       
   826         if os.path.exists(md5lastbuild):
       
   827             print md5lastbuild
       
   828             break
       
   829     except ValueError:
       
   830         print "Old MD5 cannot be found"
       
   831     
       
   832     buildnum = previousbuildnumber
       
   833 if not os.path.exists(md5lastbuild):
       
   834     print "Old MD5 cannot be found"
       
   835         </hlm:python>
       
   836         <echo>old.md5.file: ${old.md5.file}</echo>
       
   837         <available file="${old.md5.file}" property="old.md5.file.present" />
       
   838         <echo>${old.md5.file.present}</echo>
       
   839     </target>
       
   840 
       
   841 
       
   842     <!-- Creates a delta from the prevous build to the current one -->
       
   843     <target name="delta-zip" depends="delta-use-last-build,build-md5,generate-delta" description="Generate a delta between two build areas" />
       
   844 
       
   845 
       
   846     <!-- Upload the delta and config into Grace -->
       
   847     <target name="delta-zip-grace-upload">
       
   848         <fileset id="grace.delta.zips.id" dir="${delta.zip.location}">
       
   849             <include name="**/*.zip" />
       
   850             <include name="**/*.xml" />
       
   851         </fileset>
       
   852 
       
   853         <antcall target="grace-upload">
       
   854             <reference refid="grace.delta.zips.id" torefid="release.zips" />
       
   855         </antcall>
       
   856     </target>
       
   857 
       
   858     <!-- Publishes the Ant build log.
       
   859         
       
   860     First the logging should be stopped, before the file is copied. Hence this target should be called
       
   861     by the "final" target last.
       
   862     -->
       
   863     <target name="publish-build-log" depends="prep-publish" if="publish">
       
   864         <copy todir="${publish.dir}/logs" preservelastmodified="true" failonerror="false">
       
   865             <fileset dir="${build.log.dir}" includes="**/*.log" />
       
   866         </copy>
       
   867     </target>
       
   868 
       
   869     <!-- Copy the debug log to the build area if available-->
       
   870     <target name="copy-debug-logs">
       
   871         <echo message="log4j.dir:${log4j.cache.dir}" /> 
       
   872         <if>
       
   873             <available file="${log4j.cache.dir}" />
       
   874             <then>
       
   875                 <copy todir="${build.log.dir}/debug" failonerror="false">
       
   876                     <fileset dir="${log4j.cache.dir}" includes="hlm_*.log" />
       
   877                 </copy>
       
   878             </then>
       
   879         </if>
       
   880     </target>
       
   881 
       
   882     <!-- Target to simulate that the build is failed because of processing
       
   883     ant output
       
   884     -->
       
   885     <target name="raise-error">
       
   886         <echo message="ERROR: Build failed due to exceptions" />
       
   887     </target>
       
   888 
       
   889     <!-- Update the build status by processing the ant build output log -->
       
   890     <target name="build-status">
       
   891         <hlm:metadatarecord database="${metadata.dbfile}">
       
   892             <hlm:antmetadatainput>
       
   893                 <fileset casesensitive="false" file="${build.log}" />
       
   894                 <metadatafilterset refid="filterset.ant.output" />
       
   895             </hlm:antmetadatainput>
       
   896         </hlm:metadatarecord>
       
   897 
       
   898         <hlm:signalMacro logfile="${build.log}" 
       
   899             signal.input="exceptionSignalInput" />
       
   900     </target>
       
   901 
       
   902     <!-- Exception handler to process the ant output log -->
       
   903     <target name="hlm-exception-handler">
       
   904         <if>
       
   905             <available file="${build.log}"/>
       
   906             <then>
       
   907                 <runtarget target="do-exception-handler" />
       
   908             </then>
       
   909         </if>
       
   910     </target>
       
   911 
       
   912     <target name="do-exception-handler" depends="raise-error, build-status, build-log-summary, copy-debug-logs, publish-build-log" />
       
   913 
       
   914     <!-- Does any wrap-up at the end of the build. This should be the last target for every top-level target. -->
       
   915     <target name="final" depends="build-status, build-log-summary, copy-debug-logs, publish-build-log" />
       
   916     
       
   917     <!-- This target will zip the WA depending on the ado mapping file -->
       
   918     <target name="zip-wa" depends="ido-create-ado-mapping" if="zip.wa">
       
   919         <tempfile property="zipwa.dynamic.config" suffix=".xml" deleteonexit="false" destdir="${temp.build.dir}"/>
       
   920         <fmpp sourceFile="${helium.dir}/tools/common/templates/ido/zip-ant-wa-copy.xml.ftl" outputFile="${zipwa.dynamic.config}">
       
   921             <data expandProperties="yes">
       
   922                 inputfile: antProperty(ado.mapping.file)
       
   923                 ant: antProperties()
       
   924                 data: eval('
       
   925                     java.io.FileInputStream pin = new java.io.FileInputStream(filename);
       
   926                     java.util.Properties props = new java.util.Properties();
       
   927                     props.load(pin);
       
   928                     return props;
       
   929                     ', {filename:get(inputfile)})
       
   930                 </data>
       
   931         </fmpp>
       
   932         <ant antfile="${zipwa.dynamic.config}"/>
       
   933     </target>
       
   934 
       
   935 </project>