[Mono-dev] gendarme: nant build files

Christian Birkl christian.birkl at gmail.com
Mon Aug 28 16:47:32 EDT 2006


Hello all,

attached a NAnt build file for build and running gendarme. Two things bug me
currently which should be corrected by someone who has more experiences with
nant build files:

 - Mono.Cecil location must be specified as property (a dynamic lookup in
gac/pkg-config would be nice)
 - same with nunit.framework if you want to run the unit tests.

Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060828/995d8a8c/attachment.html 
-------------- next part --------------
<project name="gendarme" default="build" basedir=".">    
    
    <property name="debug" value="true" />
    <property name="version" value="0.0.0.0" />
    <property name="path-to-cecil" value="../Mono.Cecil.dll" />
    <property name="path-to-nunit" value="C:\Programme\NUnit 2.2.6\bin\nunit.framework.dll" />
    
    <property name="outputdir" value="../bin/Debug" if="${debug}" />
    <property name="outputdir" value="../bin/Delease" unless="${debug}" />
    
    <target name="clean">
    	<delete>
    		<fileset>
        	<include name="${outputdir}/*.exe" />
        	<include name="${outputdir}/*.dll" />
        	<include name="${outputdir}/*.pdb" />
    		</fileset>
    	</delete>
    </target>
    
    <target name="preprocess-in-file">    	
 			<!-- preprocess file.cs.in -->
      <script language="C#">
          <code>
            <![CDATA[
              public static void ScriptMain(Project project) {
              	string fileNameIn  = project.Properties["file-in"];
              	string fileNameOut = project.Properties["file-out"];
              	                  
								if (!File.Exists(fileNameIn))
									return;
									
								string content = string.Empty;
								using (StreamReader sr = new StreamReader(fileNameIn)) {
									content = sr.ReadToEnd();
								}
								
								content = content.Replace("@VERSION@", project.Properties["version"]);
								
								using (StreamWriter sw = new StreamWriter(fileNameOut)) {
									sw.Write(content);
								}
              }
            ]]>
          </code>
      </script>    
    </target>
    
    <target name="build">
    	<mkdir dir="${outputdir}" />

			<!-- Do some custom Makefile '.in' processing on AssemblyInfo.cs -->    
    	<property name="file-in" value="AssemblyInfo.cs.in" />
    	<property name="file-out" value="AssemblyInfo.cs" />
	  	<call target="preprocess-in-file" />

    	<call target="build-framework" />
    	<call target="build-console" />
    	<call target="build-rules" />
    </target>
        
    <target name="test" depends="build-rules">
    	<copy file="Test.config" todir="${outputdir}" />
    	
			<foreach item="File" property="test">							
			 	<in>
					<items>
						<include name="${outputdir}/Test.*.dll" />
					</items>
			  </in>
			  <do>			
					<nunit2>
						<formatter type="Plain" />
			    	<test appconfig="../bin/Debug/Test.config">
			    		<assemblies>
			    			<include name="${test}" />
			    		</assemblies>
			    	</test>
		    	</nunit2>		
		    </do>
			</foreach>
    </target>
		    
    <target name="build-rules">
			<foreach item="Folder" in="rules/" property="foldername">							
				<call target="build-rule" if="${string::starts-with(path::get-file-name(foldername), 'Gendarme.Rules.')}" />				
			</foreach>
			
			<copy file="rules/rules.xml" todir="${outputdir}" />
    </target>
    
    <target name="build-rule">
    	<property name="rulename" value="${path::get-file-name(foldername)}" />
    	
    	<!-- Do some custom Makefile '.in' processing on ${rulename}.xml -->    
    	<property name="file-in" value="${foldername}/${rulename}.xml.in" />
    	<property name="file-out" value="${outputdir}/${rulename}.xml" />
	  	<call target="preprocess-in-file" />
	  	
			<csc target="library" output="${outputdir}/${rulename}.dll" debug="${debug}">
				    <references>
				   		<include name="System.dll" />
				   		<include name="System.Xml.dll" />				      
				   		<include name="${path-to-cecil}" />
				      <include name="${outputdir}/Gendarme.Framework.dll" />
				    </references>        				    
           	<sources>
           			<include name="${foldername}/../../AssemblyInfo.cs" />
                <include name="${foldername}/**/*.cs" />
                <exclude name="${foldername}/**/test/*" /> 
            </sources>
        </csc>                
        
        <call target="build-rule-test" />
    </target>
    
    <target name="build-rule-test">
    	<property name="rulename" value="${path::get-file-name(foldername)}" />
    	<property name="testname" value="${string::replace(rulename, 'Gendarme.Rules.', '')}" />
    	
			<csc target="library" output="${outputdir}/Test.Rules.${testname}.dll" debug="${debug}">
				    <references>
				   		<include name="System.dll" />
				   		<include name="System.Xml.dll" />				      
				   		<include name="${path-to-cecil}" />
				      <include name="${path-to-nunit}" />
				      <include name="${outputdir}/Gendarme.Framework.dll" />
				      <include name="${outputdir}/${rulename}.dll" />				      
				    </references>        				    
           	<sources>           			                
                <include name="${foldername}/test/*.cs" /> 
            </sources>
        </csc>                
    </target>
    

    <target name="build-framework">    		
        <csc target="library" output="${outputdir}/Gendarme.Framework.dll" debug="${debug}">
				    <references>
				   		<include name="System.dll" />
				   		<include name="System.Xml.dll" />				      
				   		<include name="${path-to-cecil}" />
				    </references>        
           	<sources>
           		<include name="AssemblyInfo.cs" />
              <include name="framework/*.cs" />
            </sources>
        </csc>
    </target>    
    
    <target name="build-console">  
    	<copy file="${path-to-cecil}" todir="${outputdir}" />
      		
      <csc target="exe" output="${outputdir}/console.exe" debug="${debug}">
			    <references>
			   		<include name="System.dll" />
			   		<include name="System.Xml.dll" />
			      <include name="${path-to-cecil}" />				      
			      <include name="${outputdir}/Gendarme.Framework.dll" />
			    </references>        
         	<sources>
         		<include name="AssemblyInfo.cs" />
            <include name="console/*.cs" />
          </sources>
      </csc>
    </target>
</project>


More information about the Mono-devel-list mailing list