buildframework/helium/tools/compile/coverity.ant.xml
changeset 217 0f5e3a7fb6af
child 587 85df38eb4012
equal deleted inserted replaced
181:59bb7c4d6172 217:0f5e3a7fb6af
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!-- 
       
     3 ============================================================================ 
       
     4 Name        : coverity.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.coverity" xmlns:hlm="http://www.nokia.com/helium">
       
    24     <description>
       
    25         code-coverity measure.
       
    26     </description>
       
    27     
       
    28     <!-- Coverity property declaration and types defination-->
       
    29     <!-- coverity output directory location
       
    30     @type string
       
    31     @scope private
       
    32     -->
       
    33     <property name="coverity.output.dir" location="${build.output.dir}/coverity"/>
       
    34     <!-- coverity log directory location
       
    35     @type string
       
    36     @scope private
       
    37     -->
       
    38     <property name="coverity.log.dir" location="${build.log.dir}/coverity"/>
       
    39     <!-- coverity link directory location
       
    40     @type string
       
    41     @scope private
       
    42     -->
       
    43     <property name="coverity.link.dir" value="${coverity.output.dir}/coveritylink"/>
       
    44     <!-- coverity config directory location
       
    45     @type string
       
    46     @scope private
       
    47     -->
       
    48     <property name="coverity.config.dir" value="${coverity.output.dir}/config"/>
       
    49     <!-- coverity analyze directory location
       
    50     @type string
       
    51     @scope private
       
    52     -->
       
    53     <property name="coverity.analyze.dir" value="${coverity.link.dir}/analyze"/>
       
    54     <!-- coverity intermidiate directory location
       
    55     @type string
       
    56     @scope private
       
    57     -->
       
    58     <property name="coverity.inter.dir" value="${coverity.output.dir}/intermidiate"/>
       
    59     <!-- coverity report directory location
       
    60     @type string
       
    61     @scope private
       
    62     -->
       
    63     <property name="coverity.report.dir" value="${coverity.output.dir}/coverity_report_${build.id}"/>
       
    64     <!-- coverity report file name
       
    65     @type string
       
    66     @scope private
       
    67     -->
       
    68     <property name="coverity.report.file" value="${build.id}_coverity_build_report.html"/>
       
    69     <!-- coverity summary XML file name
       
    70     @type string
       
    71     @scope private
       
    72     -->
       
    73     <property name="coverity.summary.xml.file" value="${temp.build.dir}/${build.id}_coverity_build_summary.xml"/>
       
    74     <!-- coverity checkers XML file name
       
    75     @type string
       
    76     @scope private
       
    77     -->
       
    78     <property name="coverity.checkers.xml.file" value="${temp.build.dir}/${build.id}_coverity_build_checkers.xml"/>
       
    79     <!-- diamonds coverity report file name
       
    80     @type string
       
    81     @scope private
       
    82     -->
       
    83     <property name="diamonds.coverity.report.file" value="${temp.build.dir}/${build.id}_coverity_build_report.xml"/>
       
    84     
       
    85     <if>
       
    86         <isset property="env.NUMBER_OF_PROCESSORS"/>
       
    87         <then>
       
    88             <math result="coverity.no.thread" operand1="${env.NUMBER_OF_PROCESSORS}" operation="*" operand2="2" datatype="int"/>
       
    89         </then>
       
    90         <else>
       
    91             <!-- Number of parallel coverity emit threads can run.
       
    92             @type string
       
    93             @scope private
       
    94             -->
       
    95             <property name="coverity.no.thread" value="2"/>
       
    96         </else>
       
    97     </if>
       
    98     
       
    99     <!-- set property if coverity is enabled -->
       
   100     <condition property="run.coverity">
       
   101         <istrue value="${enabled.coverity}" />
       
   102     </condition>
       
   103     
       
   104     <!-- cov-build command options -->
       
   105     <hlm:coverityoptions id="coverity.build.options">
       
   106         <arg name="--config" value="${coverity.config.dir}/coverity_config.xml"/>
       
   107         <arg name="--dir" value="${coverity.inter.dir}"/>
       
   108         <arg name="--auto-diff" value=""/>
       
   109         <arg name="--preprocess-first" value=""/>
       
   110         <arg name="--record-only" value=""/>
       
   111     </hlm:coverityoptions>
       
   112     
       
   113     <!-- cov-build emit command options -->
       
   114     <hlm:coverityoptions id="coverity.emit.options">
       
   115         <arg name="--config" value="${coverity.config.dir}/coverity_config.xml"/>
       
   116         <arg name="--dir" value="${coverity.inter.dir}"/>
       
   117         <arg name="--replay" value=""/>
       
   118         <arg name="--replay-processes" value="${coverity.no.thread}"/>
       
   119     </hlm:coverityoptions>
       
   120     
       
   121     <!-- cov-config command options -->
       
   122     <hlm:coverityoptions id="coverity.config.options">
       
   123         <hlm:arg name="--config" value="${coverity.config.dir}/coverity_config.xml"/>
       
   124         <hlm:arg name="--template" value=""/>
       
   125         <hlm:arg name="--comptype" value="armcc"/>
       
   126         <hlm:arg name="--compiler" value="armcc.exe"/>
       
   127     </hlm:coverityoptions>
       
   128     
       
   129     <!-- cov-analyze command options -->
       
   130     <hlm:coverityoptions id="coverity.analyze.options">
       
   131         <hlm:arg name="--dir" value="${coverity.analyze.dir}"/>
       
   132         <hlm:arg name="--all" value=""/>
       
   133         <hlm:arg name="--symbian" value=""/>
       
   134         <hlm:arg name="--append" value=""/>
       
   135         <hlm:arg name="--enable-callgraph-metrics" value=""/>
       
   136     </hlm:coverityoptions>
       
   137 
       
   138     <!-- To run post coverity steps -->
       
   139     <target name="post-coverity" if="run.coverity">
       
   140         
       
   141         <!-- To emit the file into defect database -->
       
   142         <antcall target="run-coverity-emit"/>
       
   143         
       
   144         <!-- To analyze the sources file -->
       
   145         <antcall target="run-coverity-analyze"/>
       
   146         
       
   147         <!-- To generate the HTML error pages -->
       
   148         <antcall target="gen-coverity-report"/>
       
   149     
       
   150     </target>
       
   151     
       
   152     <!-- Run coverity configure if the enabled.coverity is set to true -->
       
   153     <target name="run-coverity-configure" if="run.coverity">
       
   154     
       
   155         <hlm:coverity command="cov-configure" dir="${build.drive}/">
       
   156             <hlm:coverityoptions refid="coverity.config.options"/>
       
   157         </hlm:coverity >
       
   158         
       
   159     </target>
       
   160     
       
   161     <!-- Run coverity build with emit options if the enabled.coverity is set to true 
       
   162      re-running the cov-build with replay option will reduce the build time by ~ 20% 
       
   163     -->
       
   164     <target name="run-coverity-emit" >
       
   165         
       
   166         <hlm:coverity command="cov-build" dir="${build.drive}/">
       
   167             <hlm:coverityoptions refid="coverity.emit.options"/>
       
   168         </hlm:coverity >
       
   169         
       
   170     </target>
       
   171     
       
   172     <!-- Run coverity-analyze if the enabled.coverity is set to true 
       
   173      Sometimes the same file is compiled several times with different command-line options. 
       
   174      Due to the inherent difficulty of tracking linkage information, the cov-analyze command cannot automatically determine which files are linked together. 
       
   175      To avoid errors in function call resolution (especially in C code, which doesn't have any name mangling), use the cov-link command to get this information. 
       
   176      
       
   177      and also
       
   178      
       
   179      working with link files is faster than collecting data from the intermediate directory multiple times
       
   180      
       
   181      So run the cov-link commands and analyze the database using cov-analyze command.
       
   182     
       
   183     -->
       
   184     <target name="run-coverity-analyze" >
       
   185         
       
   186         <mkdir dir="${coverity.link.dir}"/>
       
   187         
       
   188         <hlm:coverity command="cov-link" dir="${build.drive}/">
       
   189             <hlm:arg name="--dir" value="${coverity.inter.dir}"/>
       
   190             <hlm:arg name="--collect" value=""/>
       
   191             <hlm:arg name="-of" value="${coverity.link.dir}/all.link"/>
       
   192         </hlm:coverity >
       
   193                 
       
   194         <hlm:coverity command="cov-link" dir="${build.drive}/">
       
   195             <hlm:arg name="--dir" value="${coverity.inter.dir}"/>
       
   196             <hlm:arg name="--compile-arg" value="armv5"/>
       
   197             <hlm:arg name="-of" value="${coverity.link.dir}/armv5.link"/>
       
   198             <hlm:arg name="${coverity.link.dir}/all.link" value=""/>
       
   199         </hlm:coverity >
       
   200              
       
   201         <hlm:coverity command="cov-link" dir="${build.drive}/">
       
   202             <hlm:arg name="--dir" value="${coverity.inter.dir}"/>
       
   203             <hlm:arg name="--output-dir" value="${coverity.analyze.dir}"/>
       
   204             <hlm:arg name="${coverity.link.dir}/armv5.link" value=""/>
       
   205         </hlm:coverity >
       
   206                 
       
   207         <hlm:coverity command="cov-analyze" dir="${build.drive}/">
       
   208             <hlm:coverityoptions refid="coverity.analyze.options"/>
       
   209         </hlm:coverity >
       
   210         
       
   211     </target>
       
   212     
       
   213     
       
   214     <!-- Generate coverity report -->
       
   215     <target name="gen-coverity-report">
       
   216         
       
   217         <!-- Read the summary file generated by cov-analyze and generate html file -->
       
   218         <fmpp sourceFile="${helium.dir}/tools/common/templates/coverity/coverity.summary.html.ftl"
       
   219               outputFile="${temp.build.dir}/${build.id}_coverity_build_summary.html">
       
   220             <data   expandProperties="yes">
       
   221                     ant: antProperties()
       
   222                     covsummary: slicedText (${coverity.analyze.dir}/c/output/summary.txt)
       
   223             </data>
       
   224         </fmpp>
       
   225         
       
   226         <!-- To generate summary file for diamonds -->
       
   227         <fmpp sourceFile="${helium.dir}/tools/common/templates/coverity/coverity.summary.xml.ftl"
       
   228               outputFile="${coverity.summary.xml.file}">
       
   229             <data   expandProperties="yes">
       
   230                     ant: antProperties()
       
   231                     covsummary: slicedText (${coverity.analyze.dir}/c/output/summary.txt)
       
   232             </data>
       
   233         </fmpp>
       
   234         
       
   235         <!-- Run this to get the static html pages -->
       
   236         <hlm:coverity command="cov-format-errors" dir="${build.drive}/">
       
   237             <hlm:arg name="--dir" value="${coverity.analyze.dir}"/>
       
   238             <hlm:arg name="--filesort" value=""/>
       
   239             <hlm:arg name="--functionsort" value=""/>
       
   240         </hlm:coverity >
       
   241         
       
   242         <!-- Copy the summary file to resolve the xml load error -->
       
   243         <copy file="${coverity.analyze.dir}/c/output/errors/summary.xml" tofile="${coverity.checkers.xml.file}" overwrite="true" failonerror="false">
       
   244             <filterchain>
       
   245                 <linecontains negate="true">
       
   246                     <contains value="config.dtd"/>
       
   247                 </linecontains>
       
   248             </filterchain>
       
   249         </copy>
       
   250         
       
   251         <!-- Insert summary tags into checkers file -->
       
   252         <xmltask source="${coverity.checkers.xml.file}"  dest="${diamonds.coverity.report.file}" report="false">
       
   253             <insert path="/coverity" file="${coverity.summary.xml.file}"/> 
       
   254         </xmltask>
       
   255         
       
   256         <!-- collect all the html files into folder -->        
       
   257         <copy todir="${coverity.report.dir}" overwrite="true" failonerror="false">
       
   258             <fileset dir="${coverity.analyze.dir}/c/output/errors">
       
   259                 <exclude name="index.html"/>
       
   260                 <exclude name="**/*.xml"/>
       
   261                 <exclude name="summary.html"/>
       
   262             </fileset>
       
   263         </copy>
       
   264         
       
   265         <!-- Concatinate all the html pages to get the final error report page -->
       
   266         <concat destfile="${coverity.report.dir}/${coverity.report.file}">
       
   267             <fileset dir="${temp.build.dir}" includes="${build.id}_coverity_build_summary.html"/>
       
   268             <fileset dir="${coverity.analyze.dir}/c/output/errors" includes="index.html"/>
       
   269         </concat>
       
   270         
       
   271     </target>
       
   272     
       
   273     
       
   274     <!-- To get the SBS variable value -->
       
   275     <macrodef name="getSBSVariableValue" uri="http://www.nokia.com/helium">
       
   276         <attribute name="variablename"/>
       
   277         <attribute name="outputvar"/>
       
   278         <attribute name="sbsinput"/>
       
   279         <sequential>
       
   280             <var name="output.var" unset="true"/>
       
   281             <hlm:getVariableValue name="@{variablename}" property="output.var">
       
   282                 <hlm:sbsinput refid="@{sbsinput}" />
       
   283             </hlm:getVariableValue>
       
   284             <if>
       
   285                 <and>
       
   286                     <isset property="output.var"/>
       
   287                     <matches string="${output.var}" pattern="arm.*"/>
       
   288                 </and>
       
   289                 <then>
       
   290                     <antcall target="set-arm-version"/>
       
   291                 </then>
       
   292             </if>
       
   293             <script language="beanshell"> <![CDATA[
       
   294                 curVal=project.getProperty("output.var"); 
       
   295                 project.setProperty("@{outputvar}",curVal);
       
   296                 ]]>
       
   297             </script> 
       
   298         </sequential>
       
   299     </macrodef>
       
   300     
       
   301 
       
   302 </project>