buildframework/helium/tools/compile/compile.ant.xml
changeset 1 be27ed110b50
child 179 d8ac696cc51f
equal deleted inserted replaced
0:044383f39525 1:be27ed110b50
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!--
       
     3 ============================================================================
       
     4 Name        : compile.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 <project name="compile" xmlns:hlm="http://www.nokia.com/helium">
       
    24     <description>
       
    25         Targets related to compile stage. It includes cmaker,
       
    26         ec, ebs, sbs, sbs-ec build system.
       
    27     </description>
       
    28 
       
    29     <!-- Property declaration -->
       
    30     <property name="genxml.output.file.suffix" value="genxml" />
       
    31     <property name="compile.sysdef.dtd.stub" location="${helium.dir}/tools/common/dtd/sysdef_dtd_1_4_0.xml" />
       
    32     <property name="compile.signal.input" value="compileSignalInput" />
       
    33     <property name="diamonds.compile.summary" location="${build.log.dir}/${build.id}_compile_diamonds.xml" />
       
    34 
       
    35 
       
    36     <!-- including common compilation macros -->
       
    37     <hlm:typedef file="${helium.dir}/tools/compile/compile.antlib.xml" uri="http://www.nokia.com/helium"/>
       
    38     <import file="cmaker.ant.xml" />
       
    39     <import file="ec/ec.ant.xml" />
       
    40     <import file="ebs/ebs.ant.xml" />
       
    41     <import file="sbs/sbs.ant.xml" />
       
    42     <import file="sis.ant.xml" />
       
    43     <import file="qt/qt.ant.xml" />
       
    44 
       
    45     <!-- A few basic steps (directory creation) that are needed before starting compilation. -->
       
    46     <target name="prebuild">
       
    47         <!-- Needed for the emulator to work. -->
       
    48         <mkdir dir="${build.drive}/epoc32/winscw/d"/>
       
    49         <!-- Build from source workaround as Symbian release is not completely unzipped. -->
       
    50         <mkdir dir="${build.drive}/epoc32/release/winscw/udeb/z/resource/fonts"/>
       
    51         <mkdir dir="${build.drive}/epoc32/release/winscw/urel/z/resource/fonts"/>
       
    52         <mkdir dir="${build.drive}/epoc32/include/osextensions"/>
       
    53     </target>
       
    54 
       
    55     <!-- Does all the necessary steps before starting the component build -->
       
    56     <target name="precompile" depends="record-compile-start-time,create-canonical-sysdef-file,precompile-ec"/>
       
    57 
       
    58     <!-- post operation for EC builds, submits the compile time and lists all the built components-->
       
    59     <target name="postcompile" depends="postcompile-ec,render-build-duplicates" unless="env.HLM_SUBCON">
       
    60         <antcall target="submit-compile-time"/>
       
    61     </target>
       
    62     
       
    63     <!-- Pre-processes all System Definition input files.
       
    64 
       
    65     Any Ant properties used in the files will be replaced by their values.
       
    66     Also the Symbian System Definition files needs to have \src inserted
       
    67     in front of the paths of the units.
       
    68     -->
       
    69     <target name="preprocess-sysdef-files">
       
    70         <mkdir dir="${build.output.dir}/build/input"/>
       
    71         <delete verbose="true">
       
    72             <fileset dir="${build.output.dir}/build/input/" includes="**"/>
       
    73         </delete>
       
    74 
       
    75         <fail message="No sysdef files found">
       
    76             <condition>
       
    77                 <resourcecount refid="system.definition.files" when="equal" count="0" />
       
    78             </condition>
       
    79         </fail>
       
    80 
       
    81         <for param="file">
       
    82             <resources refid="system.definition.files"/>
       
    83             <sequential>
       
    84                 <copy todir="${build.output.dir}/build/input"  verbose="true">
       
    85                     <fileset file="@{file}"/>
       
    86                     <filterchain>
       
    87                         <replaceregex pattern="bldFile=&quot;common" replace="bldFile=&quot;src\\\\common" flags="gi"/>
       
    88                         <replaceregex pattern="mrp=&quot;common" replace="mrp=&quot;src\\\\common" flags="gi"/>
       
    89                         <replaceregex pattern="bldFile=&quot;cedar" replace="bldFile=&quot;src\\\\cedar" flags="gi"/>
       
    90                         <replaceregex pattern="mrp=&quot;cedar" replace="mrp=&quot;src\\\\cedar" flags="gi"/>
       
    91                         <expandproperties/>
       
    92                     </filterchain>
       
    93                     <mapper>
       
    94                         <scriptmapper language="beanshell">
       
    95 <![CDATA[
       
    96 import java.io.File;
       
    97 String counter = project.getProperty(".unique.counter");
       
    98 int count;
       
    99 if (counter == null){
       
   100     count = 0;
       
   101 }else{
       
   102     count = Integer.valueOf(counter) + 1;
       
   103 }
       
   104 project.setProperty(".unique.counter", ""+count);
       
   105 targetname = (String.format("%016d",count) + "_"+new File(source).getName());
       
   106 self.addMappedName(targetname);
       
   107 ]]>
       
   108                         </scriptmapper>
       
   109                     </mapper>
       
   110                 </copy>
       
   111             </sequential>
       
   112         </for>
       
   113     </target>
       
   114 
       
   115 
       
   116     <!-- Merges all preprocessed System Definition files into one combined file. -->
       
   117     <target name="create-canonical-sysdef-file" depends="preprocess-sysdef-files">
       
   118         <pathconvert pathsep=" " property="system.definition.files.list">
       
   119             <fileset dir="${build.output.dir}/build/input/" includes="*"/>
       
   120             <chainedmapper>
       
   121                 <globmapper from="*" to="-x *" casesensitive="no"/>
       
   122             </chainedmapper>
       
   123         </pathconvert>
       
   124         <hlm:compileGenxmlMergeMacro input="-x ${compile.sysdef.dtd.stub} ${system.definition.files.list}"
       
   125                                     output="${canonical.sysdef.file}"/>
       
   126     </target>
       
   127 
       
   128     <!--
       
   129       Supports a cleaning of binaries before starting compilation, based on a SysDef configuration.
       
   130       <deprecated>Please consider using ido-prep-clean target.</deprecated>
       
   131     -->
       
   132     <target name="compile-clean" depends="create-canonical-sysdef-file"
       
   133       if="sysdef.clean.configuration">
       
   134         <antcall target="compile-configuration" inheritRefs="true">
       
   135             <param name="sysdef.configuration" value="${sysdef.clean.configuration}"/>
       
   136             <param name="compile.signal.input" value="compileCleanSignalInput"/>
       
   137             <param name="compile.discard.result" value="true"/>
       
   138         </antcall>
       
   139     </target>
       
   140 
       
   141 
       
   142     <!-- Creates a input file for EBS using Symbian genxml tool. -->
       
   143     <target name="genxml">
       
   144         <if>
       
   145             <or>
       
   146                 <isset property="build.system.ebs"/>
       
   147                 <isset property="build.system.ebs-ant"/>
       
   148             </or>
       
   149             <then>
       
   150                 <hlm:compileGenxmlMacro input="-x ${canonical.sysdef.file}"
       
   151                                         configuration="${sysdef.configuration}"
       
   152                                         output="${genxml.output.file}"
       
   153                                         log="${build.log.dir}/${build.id}.${sysdef.configuration}_${genxml.output.file.suffix}.log" />
       
   154             </then>
       
   155         </if>
       
   156     </target>
       
   157 
       
   158 
       
   159     <!-- Postprocess genxml generated file by prefixing all commands with echos.
       
   160 
       
   161     Reads in the genxml generated command file (ready to be fed to EBS) and
       
   162     replaces all the command strings in the Execute statements with strings
       
   163     prefixed with echos.  For example, this target changes the following
       
   164     Execute statement:
       
   165     <pre>
       
   166       '<Execute ID="123" CommandLine="bldmake bldfiles -k"/>
       
   167 
       
   168     to:
       
   169 
       
   170       '<Execute ID="123" CommandLine="echo bldmake bldfiles -k"/>
       
   171     </pre>
       
   172     Properties:
       
   173 
       
   174       ebs.dry-run         When set, echo will be added to commands.
       
   175       genxml.output.file  The XML file with commands to be executed (by EBS).
       
   176 
       
   177     -->
       
   178     <target name="postprocess-genxml" if="ebs.dry-run">
       
   179       <!-- The 'echo' prefix will be added to the command even though it might
       
   180     already exist there. This is due to a problem with a regular expression;
       
   181     for some reason negative lookbehind assertion did not work due to syntax
       
   182     not being correct (python expression with less-than character within a
       
   183     python string within XML data; sounds messy and it was). -->
       
   184         <hlm:python>
       
   185 import fileinput
       
   186 import re
       
   187 
       
   188 COMMANDLINE_RE = r'CommandLine="(.*?)"'
       
   189 ECHO_REPLACEMENT = r'CommandLine="echo \1"'
       
   190 
       
   191 for line in fileinput.input(["${genxml.output.file}"], inplace=True):
       
   192     print re.sub(COMMANDLINE_RE, ECHO_REPLACEMENT, line).rstrip()
       
   193         </hlm:python>
       
   194     </target>
       
   195 
       
   196 
       
   197     <!-- Takes a specific timestamp at the start of the compilation stage.
       
   198 
       
   199     This is used at the end of compilation to log the compile time to the GTI
       
   200     database.
       
   201     -->
       
   202     <target name="record-compile-start-time">
       
   203         <preset.exec executable="perl" outputproperty="build.main.start.time">
       
   204             <arg value="-e"/>
       
   205             <arg value="print time"/>
       
   206         </preset.exec>
       
   207     </target>
       
   208 
       
   209   <!-- Runs the Symbian scanlog and HTMLscanlog tools, as well as a Helium tool, for
       
   210   scanning the compilation log. -->
       
   211     <target name="compile-scanlog">
       
   212         <if>
       
   213             <!-- Only run is SBS is in use and sbs.hlm.scanlog is defined -->
       
   214             <or>
       
   215                 <isset property="build.system.sbs"/>
       
   216                 <isset property="build.system.sbs-ec"/>
       
   217             </or>
       
   218             <then>
       
   219                 <if>
       
   220                     <not>
       
   221                         <isfalse value="${compile.discard.result}"/>
       
   222                     </not>
       
   223                     <then>
       
   224                         <delete file="${build.log.dir}/${build.id}.${sysdef.configuration}_compile.log.xml" failonerror="false"/>
       
   225                     </then>
       
   226                 </if>
       
   227             </then>
       
   228             <else>
       
   229                 <exec executable="perl" dir="${build.drive}/" output="${build.log.dir}/${build.id}.${sysdef.configuration}_scan1.log" failonerror="${failonerror}">
       
   230                     <arg value="${epocroot}epoc32/tools/scanlog.pl"/>
       
   231                     <arg file="${build.log.dir}/${build.id}.${sysdef.configuration}_compile.log"/>
       
   232                 </exec>
       
   233                 <exec executable="perl" dir="${build.drive}/" failonerror="${failonerror}">
       
   234                     <arg value="${epocroot}epoc32/tools/htmlscanlog.pl"/>
       
   235                     <arg value="-v"/>
       
   236                     <arg value="-v"/>
       
   237                     <arg value="-l"/>
       
   238                     <arg file="${build.log.dir}/${build.id}.${sysdef.configuration}_compile.log"/>
       
   239                     <arg value="-o"/>
       
   240                     <arg file="${build.log.dir}/${build.id}.${sysdef.configuration}_scan2.html"/>
       
   241                 </exec>
       
   242                 <hlm:assertFileExists file="${build.log.dir}/${build.id}.${sysdef.configuration}_scan2.html"/>
       
   243                 <if>
       
   244                     <!--
       
   245                       Only generate the log.xml if we want the results to be included in the final results
       
   246                       or get them used by the signaling mechanism.
       
   247                     -->
       
   248                     <isfalse value="${compile.discard.result}"/>
       
   249                     <then>
       
   250                         <hlm:metadatarecord database="${metadata.dbfile}">
       
   251                             <hlm:abldmetadatainput>
       
   252                                 <fileset casesensitive="false" file="${build.log.dir}/${build.id}.${sysdef.configuration}_compile.log" />
       
   253                                 <metadatafilterset refid="filterset.compile" />
       
   254                             </hlm:abldmetadatainput>
       
   255                         </hlm:metadatarecord>
       
   256                         <hlm:compileLogSignalMacro compile.summary.file="${build.id}.${sysdef.configuration}_compile.log" 
       
   257                             error.limit="${build.errors.limit}" />
       
   258                         <!-- Todo: metadata: insert assertions for metadata parsing here -->
       
   259                     </then>
       
   260                 </if>
       
   261             </else>
       
   262         </if>
       
   263     </target>
       
   264 
       
   265   <!-- Compiles one System Definition configuration.
       
   266 
       
   267   Certain properties must be defined to call this. It is intended to be called using
       
   268   an antcall from within a loop.
       
   269   -->
       
   270     <target name="compile-configuration" depends="run-qmake,genxml,postprocess-genxml,compile-ebs,compile-genxml-ec,
       
   271                         compile-ec-helium,compile-ebs-ant,compile-sbs,compile-scanlog"/>
       
   272 
       
   273   <!-- Executes each of the System Definition configurations in turn. -->
       
   274     <target name="do-compile-main">
       
   275         <propertyregex property="sysdef.configurations.list" input="${sysdef.configurations.list}"
       
   276                        regexp="\s*(\S+?)\s*,\s*(\S+?)\s*" replace="\1,\2" global="true" casesensitive="false"
       
   277                        override="true" defaultValue="${sysdef.configurations.list}"/>
       
   278 
       
   279         <for list="${sysdef.configurations.list}" delimiter="," param="sysdef.config">
       
   280             <sequential>
       
   281                 <antcall target="compile-configuration" inheritRefs="true">
       
   282                     <param name="sysdef.configuration" value="@{sysdef.config}"/>
       
   283                     <param name="genxml.output.file" location="${temp.build.dir}/${build.id}.@{sysdef.config}_${genxml.output.file.suffix}.xml" />
       
   284                 </antcall>
       
   285             </sequential>
       
   286         </for>
       
   287     </target>
       
   288     <var name="build.errors.total" value="" unset="true"/>
       
   289 
       
   290     <!-- Starts the actual compilation  phase of a build -->
       
   291     <target name="compile-main" depends="precompile,do-compile-main,postcompile"/>
       
   292 
       
   293     <!-- Macro to preprocess build information -->
       
   294     <scriptdef name="diamondsSummaryMacro" language="jython" uri="http://www.nokia.com/helium">
       
   295         <attribute name="output"/>
       
   296     <![CDATA[
       
   297 from xml.sax.handler import ContentHandler
       
   298 from xml.sax import make_parser
       
   299 from xml.sax.saxutils import quoteattr
       
   300 
       
   301 class DiamondsSummary(ContentHandler):
       
   302     def __init__(self):
       
   303         ContentHandler.__init__(self)
       
   304         self.scanLog = False
       
   305         self.components = {}
       
   306         self.component = None
       
   307         self.level = 0
       
   308         self.total = {'error':0, 'critical':0, 'warning':0}
       
   309 
       
   310     def startElement(self, name, attrs):
       
   311         if name == 'log' and attrs.get('filename', None) != None and attrs.get('filename', '').endswith('_compile.log'):
       
   312             self.scanLog = True
       
   313         elif self.scanLog and name == "task":
       
   314             self.level += 1
       
   315 
       
   316         if self.scanLog and name == "task" and self.level == 2 and attrs.get('name', None) != None:
       
   317             self.component = attrs.get('name', None)
       
   318             if self.component not in self.components:
       
   319                 self.components[self.component] = {'error':0, 'critical':0, 'warning':0}
       
   320 
       
   321         if self.scanLog and name == "message" and attrs.get('priority', None) != None:
       
   322             if attrs.get('priority') in self.total:
       
   323                 self.total[attrs.get('priority')] += 1
       
   324 
       
   325         if self.scanLog and name == "message" and self.level > 1 and self.component != None and attrs.get('priority', None) != None:
       
   326             if attrs.get('priority') in self.components[self.component]:
       
   327                 self.components[self.component][attrs.get('priority')] += 1
       
   328 
       
   329     def endElement(self, name):
       
   330         if name == 'log':
       
   331             self.scanLog = False
       
   332             self.level = 0
       
   333             self.component = None
       
   334         elif name == 'task':
       
   335             self.level = self.level - 1
       
   336 
       
   337 
       
   338 parser = make_parser()
       
   339 diamondsSummary = DiamondsSummary()
       
   340 parser.setContentHandler(diamondsSummary)
       
   341 parser.parse(open(str(project.getProperty('build.summary.file'))))
       
   342 
       
   343 output = '<?xml version="1.0"?>\n<compile>\n'
       
   344 output += '<components>\n'
       
   345 for name in diamondsSummary.components:
       
   346     xname = quoteattr(name)
       
   347     output += '<component name=%s error="%d" critical="%d" warning="%d" />\n' % (xname, diamondsSummary.components[name]['error'], diamondsSummary.components[name]['critical'], diamondsSummary.components[name]['warning'])
       
   348     #print name + " ==> %d" % diamondsSummary.components[name]['error']
       
   349 output += '</components>\n'
       
   350 output += '<total error="%d" critical="%d" warning="%d" />\n' % (diamondsSummary.total['error'], diamondsSummary.total['critical'], diamondsSummary.total['warning'])
       
   351 output += '</compile>\n'
       
   352 self.log(str("Writing %s" % str(attributes.get('output'))))
       
   353 f = open(str(attributes.get('output')), 'w+')
       
   354 f.write(output)
       
   355     ]]></scriptdef>
       
   356 
       
   357     <!-- Creates a .csv log of the sizes of all the binaries created in the build. -->
       
   358     <target name="binary-sizes-log" if="binary.sizes.output">
       
   359         <hlm:startSpecificLogMacro name="${build.log.dir}/${build.id}_binary_sizes.log"/>
       
   360         <property name="binary.sizes.output.file" location="${build.log.dir}/${build.id}_flash_image_size_data.csv"/>
       
   361         <pathconvert pathsep=";" property="build.logs.list">
       
   362             <fileset dir="${build.log.dir}" includes="*_build.log" excludes="*ant_build.log;*_zipup_build.log"/>
       
   363         </pathconvert>
       
   364         <pathconvert pathsep=";" property="binary.sizes.rom.logs.list">
       
   365             <fileset refid="binary.sizes.rom.logs"/>
       
   366         </pathconvert>
       
   367         <hlm:python>
       
   368 import logging
       
   369 
       
   370 import build.io
       
   371 import sysdef.api
       
   372 import sysdef.io
       
   373 
       
   374 #logging.basicConfig(level=logging.DEBUG)
       
   375 logging.basicConfig(level=logging.INFO)
       
   376 
       
   377 logging.info('Reading the System Sefinition information')
       
   378 sysDef = sysdef.api.SystemDefinition(r'${canonical.sysdef.file}')
       
   379 
       
   380 # Read in the output binaries of each unit
       
   381 logging.info('Reading the output binaries created by each unit.')
       
   382 build_logs = r'${build.logs.list}'.split(';')
       
   383 if len(build_logs) == 0:
       
   384     raise Exception('List of build logs is empty!')
       
   385 logging.info("The list of log files:\n")
       
   386 logging.info("\n".join(build_logs))
       
   387 for logpath in build_logs:
       
   388     binaries_reader = build.io.AbldLogWhatReader(logpath)
       
   389     sysDef.merge_binaries(binaries_reader)
       
   390 
       
   391 # Read in the binary sizes listed in the ROM output logs
       
   392 logging.info('Reading the binary sizes of each binary from ROM logs.')
       
   393 rom_logs = r'${binary.sizes.rom.logs.list}'.split(';')
       
   394 if len(rom_logs) == 0:
       
   395     raise Exception('List of ROM logs is empty!')
       
   396 logging.info("The list of log files:\n")
       
   397 logging.info("\n".join(rom_logs))
       
   398 for log in rom_logs:
       
   399     binary_sizes_reader = build.io.RombuildLogBinarySizeReader(log)
       
   400     sysDef.merge_binary_sizes(binary_sizes_reader)
       
   401 
       
   402 # Write out a .csv file containing
       
   403 size_writer = sysdef.io.FlashImageSizeWriter(r'${binary.sizes.output.file}')
       
   404 size_writer.write(sysDef, r'${sysdef.configurations.list}'.split(','))
       
   405 size_writer.close()
       
   406         </hlm:python>
       
   407         <hlm:assertFileExists file="${binary.sizes.output.file}"/>
       
   408         <hlm:stopSpecificLogMacro name="${build.log.dir}/${build.id}_binary_sizes.log"/>
       
   409     </target>
       
   410 
       
   411 
       
   412     <!-- Run codescanner to perform analysis on source code.
       
   413     Logs will be created under ${build.log.dir}/codescanner/
       
   414     Property ${codescanner.path} needs to be set to indicate what code to analyse.
       
   415     -->
       
   416     <target name="codescanner">
       
   417         <mkdir dir="${build.log.dir}"/>
       
   418         <mkdir dir="${build.log.dir}/codescanner"/>
       
   419         <hlm:codescanner dest="${build.log.dir}/codescanner" format="${codescanner.format}" configuration="${codescanner.config}" auto="${codescanner.log.unique}" >
       
   420             <path refid="codescanner.path"/>
       
   421         </hlm:codescanner>
       
   422         <move todir="${build.log.dir}/codescanner" includeemptydirs="false">
       
   423             <fileset dir="${build.log.dir}/codescanner" includes="*.*"/>
       
   424             <mapper type="glob" from="*" to="${build.id}_*"/>
       
   425         </move>
       
   426     </target>
       
   427 
       
   428 
       
   429     <!-- Updates the UAProf header.
       
   430 
       
   431     TODO: Is this still needed? -->
       
   432     <target name="update-uaprof-header">
       
   433         <property name="uaprof.cenrep.file" value="${build.drive}/epoc32/data/Z/private/10202be9/101F8731.txt"/>
       
   434         <copy file="${uaprof.cenrep.file}" tofile="${uaprof.cenrep.file}.original"/>
       
   435         <replace file="${uaprof.cenrep.file}" token="@version@" value="${build.version}" encoding="UTF-16LE" summary="true"/>
       
   436     </target>
       
   437 
       
   438 
       
   439   <!-- Runs a number of postbuild steps that must be run after compilation is complete,
       
   440   but before ROM images and zipping are started. -->
       
   441     <target name="postbuild" depends="update-uaprof-header,sisfiles" unless="env.HLM_SUBCON">
       
   442         <antcall target="security-checker"/>
       
   443         <antcall target="dump-swicertstore"/>
       
   444         <antcall target="check-stub-sis"/>
       
   445     </target>
       
   446 </project>