buildframework/helium/tools/logging/logging.ant.xml
changeset 217 0f5e3a7fb6af
child 628 7c4a911dc066
equal deleted inserted replaced
181:59bb7c4d6172 217:0f5e3a7fb6af
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!-- 
       
     3 ============================================================================ 
       
     4 Name        : logging.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 framework -->
       
    24 <project name="logging" xmlns:hlm="http://www.nokia.com/helium">
       
    25     <description>
       
    26         Targets related to log parsing, rendaring, upload to diamonds etc.
       
    27     </description>
       
    28     
       
    29     
       
    30     <!-- This is where the preparation build logs are stored.
       
    31     @type string
       
    32     @scope private
       
    33     -->
       
    34     <property name="prep.log.dir" location="${build.log.dir}/prep"/>
       
    35     <!-- This is where the compile logs are stored.
       
    36     @type string
       
    37     @scope private
       
    38     -->
       
    39     <property name="compile.log.dir" location="${build.log.dir}/compile"/>
       
    40     <!-- This is where the ats test logs are stored.
       
    41     @type string
       
    42     @scope private
       
    43     -->
       
    44     <property name="test.log.dir" location="${build.log.dir}/test"/>
       
    45     <!-- This is where the archive logs are stored.
       
    46     @type string
       
    47     @scope private
       
    48     -->
       
    49     <property name="archive.log.dir" location="${build.log.dir}/archive"/>
       
    50     <!-- This is where the roms logs are stored.
       
    51     @type string
       
    52     @scope private
       
    53     -->
       
    54     <property name="roms.log.dir" location="${build.log.dir}/roms"/>       
       
    55     <!-- This is where the post build logs are stored.
       
    56     @type string
       
    57     @scope private
       
    58     -->
       
    59     <property name="post.log.dir" location="${build.log.dir}/post"/>
       
    60     <!-- This is where the localisation logs are stored.
       
    61     @type string
       
    62     @scope private
       
    63     -->
       
    64     <property name="localisation.log.dir" location="${build.log.dir}/localisation"/>    
       
    65     
       
    66     
       
    67     <!-- Macro to record content to a separate log file without recording in the main log. -->
       
    68     <macrodef name="recordStartMacro" uri="http://www.nokia.com/helium">
       
    69         <attribute name="name"/>
       
    70         <attribute name="emacsmode" default="false"/>
       
    71         <sequential>
       
    72             <if>
       
    73                 <available file="${build.log.dir}" type="dir"/>
       
    74                 <then>
       
    75                     <hlm:record name="${build.log.dir}/@{name}" action="start" append="true" emacsmode="@{emacsmode}" loglevel="${ant.loglevel}"/>
       
    76                 </then>
       
    77             </if>
       
    78         </sequential>
       
    79     </macrodef>
       
    80 
       
    81 
       
    82     <!-- Macro to stop recording content to a separate log file without recording in the main log. -->
       
    83     <macrodef name="recordStopMacro" uri="http://www.nokia.com/helium">
       
    84         <attribute name="name"/>
       
    85         <sequential>
       
    86             <if>
       
    87                 <available file="${build.log.dir}/@{name}"/>
       
    88                 <then>
       
    89                     <hlm:record name="${build.log.dir}/@{name}" action="stop" append="true"/>
       
    90                 </then>
       
    91             </if>
       
    92         </sequential>
       
    93     </macrodef>
       
    94 
       
    95     
       
    96     <!--Macro to stop recording to the main log file (if present) and record to
       
    97         a separate log file that is filtered after logging is stopped. -->
       
    98     <macrodef name="filterRecordStartMacro" uri="http://www.nokia.com/helium">
       
    99         <attribute name="pattern" default=""/>
       
   100         <attribute name="category" default=""/>
       
   101         <sequential>
       
   102             <hlm:record name="${build.cache.log.dir}/temp_ant_build.log" action="start" loglevel="${ant.loglevel}">
       
   103                 <hlm:recordfilter category="@{category}" regexp="@{pattern}" />
       
   104             </hlm:record>
       
   105         </sequential>
       
   106     </macrodef>
       
   107     
       
   108 
       
   109     <!--Macro to stop recording the seperate filtered log file, filter the passwords
       
   110     and start recording in main log file -->
       
   111     <macrodef name="filterRecordStopMacro" uri="http://www.nokia.com/helium">
       
   112         <attribute name="log" default="${build.log}"/>
       
   113         <attribute name="append" default="true"/>
       
   114         <sequential>
       
   115             <hlm:record name="${build.cache.log.dir}/temp_ant_build.log" action="stop"/>                    
       
   116             <concat destfile="@{log}" append="@{append}">
       
   117                 <filelist dir="${build.cache.log.dir}" files="temp_ant_build.log"/>                        
       
   118             </concat>
       
   119             <delete file="${build.cache.log.dir}/temp_ant_build.log" failonerror="false"/>
       
   120             <echo>End of filtering @{log} for passwords</echo>
       
   121         </sequential>
       
   122     </macrodef>
       
   123     
       
   124     
       
   125     <!-- Extract logs from text file and process error/warnings/components name etc
       
   126     into xml file.
       
   127     @deprecated Please consider using the metadata framework.
       
   128     -->
       
   129     <scriptdef name="logextract" language="jython"  uri="http://www.nokia.com/helium">
       
   130         <attribute name="file" />
       
   131         <attribute name="outputfile" />
       
   132         <element name="fileset" type="fileset"/>
       
   133         <element name="logfilterset" classname="com.nokia.ant.types.LogFilterSet"/>
       
   134         <![CDATA[
       
   135 import os.path
       
   136 import log2xml
       
   137 import java.io
       
   138 
       
   139 def convertFile(inputfile, outputfile, config):
       
   140     if (outputfile != None):
       
   141         print "output file not none"
       
   142         print "output file: %s" % outputfile
       
   143         targetfile = str(outputfile)
       
   144     else:
       
   145         #print "output file: %s" % outputfile
       
   146         targetfile = "%s.xml" % inputfile
       
   147         #print "targetFile %s" % targetfile
       
   148     if not os.path.exists(targetfile) or \
       
   149        (os.path.exists(targetfile) and os.path.getmtime(inputfile) > os.path.getmtime(targetfile)):
       
   150         self.getProject().log("Converting %s..." % inputfile)
       
   151         log2xml.convert(inputfile, targetfile, False, config)
       
   152     else:
       
   153         self.getProject().log("Extracted log is uptodate: %s" % inputfile)
       
   154         
       
   155 config = log2xml.DEFAULT_CONFIGURATION
       
   156 logfilterset = elements.get("logfilterset")
       
   157 if logfilterset != None and logfilterset.size() > 0:
       
   158     # if any logfilterset are dfined then
       
   159     # it override the default configuration
       
   160     config = {}
       
   161     for filtersetid in range(logfilterset.size()):
       
   162         filterset = logfilterset.get(filtersetid)
       
   163         if filterset.isReference():
       
   164             filterset = filterset.getRefid().getReferencedObject(project)
       
   165         filters = filterset.getFilters()
       
   166         for filterid in range(filters.size()):
       
   167             if not filters.get(filterid).getCategory() in config:
       
   168                 config[filters.get(filterid).getCategory()] = []
       
   169             config[filters.get(filterid).getCategory()].append(str(filters.get(filterid).getRegex()))
       
   170 
       
   171 fileset = elements.get("fileset")
       
   172 outputfile = attributes.get("outputfile")
       
   173 if fileset != None and fileset.size() > 0:
       
   174     for filesetid in range(fileset.size()):
       
   175         dirscanner = fileset.get(filesetid).getDirectoryScanner(project)
       
   176         for filename in dirscanner.getIncludedFiles():
       
   177             inputfile = str(java.io.File(dirscanner.getBasedir(), str(filename)).getAbsolutePath())
       
   178             convertFile(inputfile, outputfile, config)
       
   179 elif attributes.get("file") != None:
       
   180     inputfile = str(java.io.File(str(attributes.get("file"))).getAbsolutePath())
       
   181     convertFile(inputfile, outputfile, config)
       
   182 else:
       
   183     self.log("No input specified.")
       
   184         ]]>
       
   185     </scriptdef>
       
   186     
       
   187     
       
   188     <!--Macro to stop recording to the main log file (if present) and record to
       
   189         a separate log file into a temporary location (doesn't need the build aread to work). -->
       
   190     <macrodef name="tempRecordStartMacro" uri="http://www.nokia.com/helium">
       
   191         <attribute name="name"/>
       
   192         <sequential>
       
   193             <mkdir dir="${build.cache.log.dir}"/>
       
   194             <hlm:record name="${build.cache.log.dir}/@{name}" action="start" loglevel="${ant.loglevel}"/>
       
   195         </sequential>
       
   196     </macrodef>
       
   197 
       
   198 
       
   199     <!--Macro to restart  the main log file (if present) and stop recording to
       
   200         a separate log file into a temporary location the file is next xml summarized 
       
   201         and potentially copied to the build area (if exists). Else those files will get copied during the 
       
   202         build area preparation. -->
       
   203     <macrodef name="tempRecordStopMacro" uri="http://www.nokia.com/helium">
       
   204         <attribute name="name"/>
       
   205         <attribute name="phase" default=""/>
       
   206         <attribute name="database" default="${metadata.dbfile}"/>
       
   207         <attribute name="filterref" default="filterset.temprecord"/>
       
   208         <sequential>
       
   209             <mkdir dir="${build.cache.log.dir}"/>
       
   210             <mkdir dir="${build.log.dir}"/>
       
   211             <mkdir dir="${build.cache.log.dir}/signals"/>
       
   212             <hlm:record name="${build.cache.log.dir}/@{name}" action="stop" loglevel="${ant.loglevel}"/>
       
   213             <!--Temporary solution, the logextract in general 
       
   214                 needs to be handled in a better way (not all logs needs to be processed,
       
   215                 logextract / counting errors could be merged and logextract should be
       
   216                 executed on a need basis and not to process for all stopmacro.-->
       
   217             <!-- Todo: metadata: replace logextract -->
       
   218             <hlm:metadatarecord database="@{database}">
       
   219                 <hlm:antmetadatainput>
       
   220                     <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   221                     <metadatafilterset refid="@{filterref}" />
       
   222                 </hlm:antmetadatainput>
       
   223             </hlm:metadatarecord>
       
   224             <hlm:generateBuildStatus dbfile="@{database}" output-dir="${build.cache.log.dir}/signals" file="@{name}" />
       
   225             <if>
       
   226                 <isset property="@{phase}.log.dir" />
       
   227                 <then>
       
   228                     <mkdir dir="${@{phase}.log.dir}"/>
       
   229                     <copy todir="${@{phase}.log.dir}" failonerror="false">
       
   230                         <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   231                     </copy>
       
   232                 </then>
       
   233                 <else>
       
   234                     <copy todir="${build.log.dir}" failonerror="false">
       
   235                         <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   236                     </copy>
       
   237                 </else>
       
   238             </if>            
       
   239             <copy todir="${build.signal.status.dir}" failonerror="false">
       
   240                 <fileset casesensitive="false" dir="${build.cache.log.dir}/signals" />
       
   241             </copy>
       
   242         </sequential>
       
   243     </macrodef>
       
   244     
       
   245     
       
   246     <!-- Macro to start logging to a separate log file.
       
   247     
       
   248     This will stop logging to the main ant_build log file until stopSpecificLogMacro
       
   249     is called. -->
       
   250     <macrodef name="startSpecificLogMacro" uri="http://www.nokia.com/helium">
       
   251         <attribute name="name"/>
       
   252         <attribute name="regexp" default=""/>
       
   253         <attribute name="backup" default="false"/>
       
   254         <attribute name="phase" default=""/>
       
   255         
       
   256         <sequential>
       
   257             <if>
       
   258                 <isset property="@{phase}.log.dir" />
       
   259                 <then>
       
   260                     <mkdir dir="${@{phase}.log.dir}"/>
       
   261                 </then>
       
   262             </if> 
       
   263             <mkdir dir="@{name}/.."/>
       
   264             <hlm:record name="@{name}" action="start" loglevel="verbose" backup="@{backup}" backupProperty="backup.file.name">
       
   265                 <hlm:recordfilter category="@{phase}" regexp="@{regexp}" />
       
   266             </hlm:record>
       
   267         </sequential>
       
   268     </macrodef>
       
   269 
       
   270 
       
   271     <!--Macro to restart  the main log file (if present) and stop recording to
       
   272         a separate log file. -->
       
   273     <macrodef name="stopSpecificLogMacro" uri="http://www.nokia.com/helium">
       
   274         <attribute name="name"/>
       
   275         <attribute name="phase" default=""/>
       
   276         <sequential>
       
   277             <hlm:record name="@{name}" action="stop" loglevel="verbose"/>
       
   278         </sequential>
       
   279     </macrodef>
       
   280 
       
   281     <!-- Temp BMD macro -->
       
   282     <macrodef name="bmdLogExtractMacro" uri="http://www.nokia.com/helium">
       
   283         <attribute name="log"/>
       
   284         <attribute name="metadatafilterset" default="common"/>
       
   285         <sequential>
       
   286             <hlm:metadatarecord database="${metadata.dbfile}">
       
   287                 <hlm:textmetadatainput>
       
   288                     <fileset casesensitive="false" file="@{log}"/>
       
   289                     <metadatafilterset refid="@{metadatafilterset}" />
       
   290                 </hlm:textmetadatainput>
       
   291             </hlm:metadatarecord>
       
   292             <!-- todo: check to add for usage and add genbuildstatus macro -->
       
   293             <basename property="log.name" file="@{log}"/>
       
   294             <fmpp sourceFile="${helium.dir}/tools/common/templates/db2xml.xml.ftl"
       
   295                          outputfile="@{log}.xml">
       
   296                 <data expandProperties="yes">
       
   297                     dbPath: ${metadata.dbfile}
       
   298                     log: ${log.name}
       
   299                     ant: antProperties()
       
   300                 </data>
       
   301             </fmpp>
       
   302         </sequential>
       
   303     </macrodef>
       
   304     
       
   305     
       
   306     <!-- Merges all XML log files ending in ".log2.xml" in the build log directory
       
   307     into a single summary log file. -->
       
   308     <target name="log-merge"  unless="metadata.enable">
       
   309         <mkdir dir="${build.log.dir}"/>
       
   310         <dependset>
       
   311             <srcfileset dir="${build.log.dir}" includes="**/${build.id}*.log.xml"/>
       
   312             <targetfileset file="${build.summary.file}"/>
       
   313         </dependset>
       
   314         <if>
       
   315             <not>
       
   316                 <available file="${build.summary.file}"/>
       
   317             </not>
       
   318             <then>
       
   319                 <echo>Merging all *.log.xml files</echo>        
       
   320                 <mkdir dir="${build.log.dir}/summary"/>
       
   321                 <xmltask  dest="${build.summary.file}">
       
   322                     <insert path="/"  >
       
   323                     <![CDATA[
       
   324                     <logSummary/>
       
   325                     ]]>
       
   326                     </insert>
       
   327                 </xmltask>
       
   328                 <for param="file">
       
   329                     <path>
       
   330                         <fileset dir="${build.log.dir}">
       
   331                             <include name="**/${build.id}*.log.xml"/>
       
   332                         </fileset>
       
   333                         <fileset dir="${temp.build.dir}">
       
   334                             <include name="**/${build.id}*.log.xml"/>
       
   335                         </fileset>
       
   336                     </path>
       
   337                     <sequential>
       
   338                         <echo>Inserting @{file} into summary.</echo>
       
   339                         <!--<xmltask source="${build.summary.file}"
       
   340                                  dest="${build.summary.file}">
       
   341                            <insert path="/logSummary" file="@{file}" />
       
   342                         </xmltask>-->
       
   343                         <hlm:assertPropertySet property="build.summary.file" message="Property build.summary.file is not defined." />
       
   344                         <script language="jython" setbeans="false">
       
   345 # Temporary solution
       
   346 import log2xml
       
   347 log2xml.append_summary(project.getProperty('build.summary.file'), r'@{file}')
       
   348                         </script>                        
       
   349                     </sequential>
       
   350                 </for>
       
   351             </then>
       
   352             <else>
       
   353                 <echo>Summary XML log file does not need updating.</echo>
       
   354             </else>
       
   355         </if>
       
   356     </target>
       
   357     
       
   358     
       
   359     <!-- Outputs an HTML readable version of the summary log. -->
       
   360     <target name="render-log-summary">
       
   361         <if>
       
   362             <and>
       
   363                 <available file="${build.log.dir}/${build.id}_info.log.xml"/>
       
   364                 <available file="${metadata.dbfile}"/>
       
   365             </and>
       
   366             <then>
       
   367                 <fmpp sourceFile="${helium.dir}/tools/common/templates/log/summary_metadata_orm.html.ftl"
       
   368                              outputfile="${build.log.dir}/${build.id}_summary.html">
       
   369                     <freemarkerLinks expandProperties="yes">
       
   370                         macro: ${helium.dir}/tools/common/templates/macro
       
   371                     </freemarkerLinks>
       
   372                     <data expandProperties="yes">
       
   373                         dbPath: ${metadata.dbfile}
       
   374                         loginfo: xml(${build.log.dir}/${build.id}_info.log.xml)
       
   375                         ant: antProperties()
       
   376                     </data>
       
   377                 </fmpp>
       
   378                 <if>
       
   379                     <not>
       
   380                         <available file="${build.log.dir}/${build.id}_summary.html"/>
       
   381                     </not>
       
   382                     <then>
       
   383                         <echo message="Error: failed to generate Summary file" />
       
   384                     </then>
       
   385                 </if>
       
   386             </then>
       
   387         </if>
       
   388     </target>
       
   389     
       
   390     <!-- Prepare email for build summary -->
       
   391     <target name="logger-email" depends="log-merge">
       
   392         <fmpp sourceRoot="${helium.dir}/tools/common/templates/log" includes="email.html.ftl" outputRoot="${build.log.dir}/summary"
       
   393               replaceExtension="html.ftl, html">
       
   394             <data expandProperties="yes">
       
   395                 doc: xml(${build.summary.file})
       
   396                 ant: antProperties()
       
   397             </data>
       
   398         </fmpp>        
       
   399     </target>
       
   400     
       
   401 
       
   402     <!-- Test target to show how Diamond metadata could be rendered. -->
       
   403     <target name="render-diamonds-data" depends="log-merge">
       
   404         <mkdir dir="${build.log.dir}/summary/diamonds"/>
       
   405         <fmpp sourceRoot="${helium.dir}/tools/common/templates/diamonds"
       
   406               outputRoot="${build.log.dir}/summary/diamonds" includes="diamonds.xml.ftl"
       
   407               replaceExtension="xml.ftl, xml">
       
   408             <data expandProperties="yes">
       
   409                 doc: xml(${build.summary.file})
       
   410                 ant: antProperties()
       
   411             </data>
       
   412         </fmpp>
       
   413     </target>
       
   414 
       
   415     
       
   416     <!-- Render the CC dashboad summary. -->
       
   417     <target name="render-cc-summary" depends="log-merge">
       
   418         <mkdir dir="${build.log.dir}/summary"/>
       
   419         <fmpp sourceFile="${helium.dir}/tools/common/templates/log/cc_summary_metadata_orm.html.ftl"
       
   420                      outputfile="${build.log.dir}/summary/${build.id}_cc_summary.html">
       
   421             <data expandProperties="yes">
       
   422                 dbPath: ${metadata.dbfile}
       
   423                 ant: antProperties()
       
   424             </data>
       
   425         </fmpp>
       
   426     </target>
       
   427 
       
   428     
       
   429     <!-- Creates a full summary log from all the build logs. -->
       
   430     <target name="build-log-summary" depends="render-log-summary"/>
       
   431     
       
   432     <!-- Test target to check signal. -->
       
   433     <target name="check-signal" />
       
   434     
       
   435     <!-- Starting the main ant_build log -->
       
   436     <target name="start-ant-log" >
       
   437         <hlm:triggerlogger/>
       
   438     </target>
       
   439     
       
   440     
       
   441     
       
   442     
       
   443 </project>