自动化每日构建(一)用Ant来完成Delphi工程的每日构建

原创 2004年07月12日 16:49:00

Delphi的IDE在一般工程的编译、部署是非常方便的,但是当工程的规模比较庞大时,使用IDE来进行工程的构建就比较费劲了。这时我们可以使用shell脚本来完成这个任务。但是脚本受限制于操作系统平台,管理起来不方便。如果能把所有的项目的构建统一在Ant和NAnt环境下,那么项目的管理效率就可以大大提升,成本就可以大大下降。

每日构建的实际内容应该包括:代码更新、编译、单元测试、打包、冒烟测试等基本内容。下面的构建文件并不包括所有这些内容。

本系列包括用Ant来进行Delphi、Java的每日构建,用NAnt进行.NET的每日构建。

Ant的构建文件Build.xml,使用时可以用实际的工程名替代*****。

 


<project default="usage" basedir=".">

    <!-- =================================================================== -->
    <!-- Initialization target                                               -->
    <!-- =================================================================== -->
    <target name="init">
        <tstamp/>
        <buildnumber/>
        <property environment="env" />
        <property file="build.number"/>
        <!-- You have to fill the ***** space with your project label.  -->
        <property name="Name" value="*****"/>
        <property name="name" value="*****"/>
        <property name="pname" value="*.dpr"/>
        <property name="infofile" value="compiledinfo.txt"/>
        <property name="buildname" value="*****build"/>
        <property name="packname" value="*****"/>
        <property name="dbpackname" value="*****DB"/>
        <property name="year" value="2004"/>


        <echo message="----------- ${Name} Build ${build.number}[${year}] ------------"/>

        <property name="build.compiler" value="modern"/>
        <property name="debug" value="on"/>
        <property name="optimize" value="on"/>
        <property name="deprecation" value="on"/>

        <property name="s.home" value=".."/>
        <property name="s.src" value="${s.home}/src"/>
        <property name="s.srcdelphi" value="${s.home}/src/delphi"/>
        <property name="s.gohome" value="../"/>
        <property name="s.lib" value="${s.home}/lib"/>
        <property name="s.res" value="${s.home}/res"/>
        <property name="s.build" value="${s.home}/build"/>
        <property name="s.run" value="${s.home}/run"/>

        <property name="s.build.assemble" value="${s.build}/assemble"/>
        <property name="s.build.dcu" value="${s.build.assemble}/dcu"/>
        <property name="s.build.bin" value="${s.build.assemble}/bin"/>
        <property name="s.build.gensrc" value="${s.build.assemble}/gen-src"/>
        <property name="s.build.delphidocs" value="${s.build}/apidocs"/>
        <property name="s.build.lib" value="${s.home}/res"/>
        <property name="s.build.release" value="${s.build}/release"/>
        <property name="s.build.web"   value="${s.build}/web"/>
        <property name="s.build.dist"  value="${s.build}/dist"/>
        <property name="s.main" value="com"/>

        <property file="${s.build}/build.properties" />

        <filter token="year" value="${year}"/>
        <filter token="version" value="${version}"/>
        <filter token="date" value="${TODAY}"/>
        <filter token="log" value="true"/>
        <filter token="verbose" value="true"/>

        <path id="s.classpath">
            <fileset dir="${s.lib}">
                <include name="**/*.jar"/>
                <include name="**/*.zip"/>
            </fileset>
        </path>

        <path id="buildtools.classpath">
            <fileset dir="${s.build.lib}">
                <include name="**/*.jar"/>
                <include name="**/*.zip"/>
            </fileset>
            <fileset dir="${s.lib}">
                <include name="**/*.jar"/>
                <include name="**/*.zip"/>
            </fileset>
        </path>

        <tstamp>
            <format property="TODAY" pattern="d-MM-yy"/>
        </tstamp>

    </target>

    <!-- =================================================================== -->
    <!-- Help on usage                                                       -->
    <!-- =================================================================== -->
    <target name="usage">
        <echo message=""/>
        <echo message=""/>
        <echo message="***** Build file"/>
        <echo message="-------------------------------------------------------------"/>
        <echo message=""/>
        <echo message=" available targets are:"/>
        <echo message=""/>
        <echo message="   package   --> generates the *****.zip file (default)"/>
        <echo message="   compile   --> compiles the source code"/>
        <echo message="   test      --> units test"/>
        <echo message="   release   --> build the installation package"/>
        <echo message="   clean     --> cleans up the directory"/>
        <echo message=""/>
        <echo message=" See the comments inside the build.xml file for more details."/>
        <echo message="-------------------------------------------------------------"/>
        <echo message=""/>
        <echo message=""/>
    </target>

 

    <!-- =================================================================== -->
    <!-- Compiles the source directory                                       -->
    <!-- =================================================================== -->
    <target name="compile" depends="init">
        <mkdir dir="${s.build.dcu}"/>
        <mkdir dir="${s.build.bin}"/>
        <echo message=""/>
        <echo message="Compiling application main source..."/>

        <!-- You may change the compile tasks here.  -->
        
        <exec dir="${s.srcdelphi}" executable="dcc32.exe" os="Windows 2000"
              output="${infofile}">
             <arg line=" -B ${pname} 
                 -N${s.gohome}${s.build.dcu} -E${s.gohome}${s.build.bin}
                 -U${s.gohome}${s.build.lib}"/>
        </exec>

  <loadfile property="compiled-info"
            srcFile="${infofile}"/>
       
  <condition property="compile-success">
      <and>
       <contains string="${compiled-info}" substring="seconds"/>
      </and>
    </condition>

  <fail unless="compile-success"
        message="${compiled-info}"/>

    </target>


    <!-- =================================================================== -->
    <!-- Creates the zip package                                             -->
    <!-- =================================================================== -->
    <target name="zip" depends="compile">

        <!-- You may change the package tasks here.  -->

        <mkdir dir="${s.build.assemble}/zip/${buildname}${DSTAMP}/${packname}"/>
        <mkdir dir="${s.build.assemble}/zip/${buildname}${DSTAMP}/${dbpackname}"/>
       
        <copy todir="${s.build.assemble}/zip/${buildname}${DSTAMP}/${packname}">
           <fileset file="${s.build.bin}/*.*"/>
           <fileset dir="${s.lib}" />
        </copy>
       
        <copy todir="${s.build.assemble}/zip/${buildname}${DSTAMP}/${dbpackname}">
           <fileset file="${s.src}/database/*.*"/>
           <fileset file="${s.src}/sql/*.*"/>
        </copy>

        <zip destfile="${s.build.assemble}/zip/${buildname}${DSTAMP}.zip"
             basedir="${s.build.assemble}/zip/${buildname}${DSTAMP}"
             update="true"
        />

    </target>


    <!-- =================================================================== -->
    <!-- Creates the test                                                    -->
    <!-- =================================================================== -->
    <target name="test" depends="compile">

  <!-- You may fill the tasks here.  -->

    </target>


    <!-- =================================================================== -->
    <!-- Creates the deploy                                                  -->
    <!-- =================================================================== -->
    <target name="deploy" depends="">

  <!-- You may fill the tasks here.  -->

    </target>

 

    <!-- =================================================================== -->
    <!-- Build the installation packge                                       -->
    <!-- =================================================================== -->
    <target name="release" depends="clean">

  <!-- You may fill the tasks here.  -->

    </target>

 

    <!-- =================================================================== -->
    <!-- Clean targets                                                       -->
    <!-- =================================================================== -->
    <target name="clean" depends="init">
        <delete dir="${s.build.assemble}"/>
        <delete dir="${s.build.release}"/>
        <delete >
           <fileset dir="." includes="**/compile*.txt"/>
        </delete>
  <!-- You may fill the tasks here.  -->
    </target>


</project>

<!-- End of file -->

 

下面是过去写的一个建立Delphi工程自动化每日构建的帮助文档,内容是英文的。

 

Start a new Delphi project by using Ant

 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

This document has 5 sections:

Brief

System requirement

Directories and files

The Build file

Run Ant

 

 

Brief

Start a new Delphi project by using Ant, so we can make Daily Building. All have to do list below:

1.Install Delphi SDK1.4 and new version Ant, and make Ant works.

2.Copy Directories and files from dproject(d for Delphi) template library.

3.Make project files stay in the right directory.

4.Edit the Build.xml file. Let it fit the project.

5.Run Ant.

 

 

System requirement

Delphi SDK1.4 or higher

Ant 1.6 or higher

Delphi 6.0 or higher

 

Directories and files

You can make directories yourself, or copy from template. But make sure the directory tree like this:

Every directory is made for a certain kind of files. Directory names and what kind of files should be put in list below:

Directory        Files should be put in

            Build                building files

            Data                 project’s data files

            Doc                  project‘s documents for installation and deploying

            Lib                   libraries project depending on

            Res                  resources project using

                        Install               resources for installation

            Src                   project’ source files

                        Config              project’s configuration files

                        Database          project’s database files

                        Delphi              project’s Delphi source code files

                        Docs                project’s documents for manager, developer, tester

                        Scripts              project’s script files

                        Sql                   project’s script files for database

           

Now put the Delphi files into the /src/Delphi directory.

 

The Build file

            The build file is /build/build.xml. In the template we already have a default build file. Because every project has different name and different configuration, so we must edit the build file to suit project. We must edit the project name and path in the build file.

 

Run Ant

            After doing that, now start a command-line prompt, change path to ./build, and type ant. We can see a function list like this:

Now Ant runs. We can EDIT the build file to add new features: unit testing, packing, deploying, etc, as you like.

 

每日构建与持续集成联系与区别

每日构建与持续集成联系与区别 1)持续集成(Continuous Integration)贵在速度,强调一个快速反馈。      比如我一签入代码,就立刻集成,给我一个反馈,我要知道我的代码是否破坏...
  • xifeijian
  • xifeijian
  • 2013年07月18日 00:04
  • 7066

每日构建系列(1):入门篇

关键词:Daily Build、CI、CCNet、CCTray、VSS、SVN、MSBuild、NAnt、NUnit、Email、FxCop、NCover、NCoverExplorer、RSS、SCM...
  • u013948187
  • u013948187
  • 2015年12月13日 22:56
  • 279

一年多推行每日构建的经验总结

作者:朱金灿来源:http://blog.csdn.net/clever101         早在主持开发产品新版本之初,我就有一个略显激进的想法:新产品的测试版本发布频率至少在一周之内。开发人员倾...
  • clever101
  • clever101
  • 2014年08月31日 21:52
  • 3088

每日构建 Daily build

一个好的办法是每日构建(daily builds)。 每日构建意味着自动地,每天,完整地构建整个代码树、(译者按:“代码树”,原文为source tree,意思是将整个项目源代码的目录,子目录,文件的...
  • u013890660
  • u013890660
  • 2014年03月17日 10:49
  • 966

Visual Studio及TFS进行单元测试、负载测试、代码覆盖率、每日构建配置

这是以前在VS2010上让同事做的相关工作的备案,现在VS2012都出来了,2010都快过期,帖出来共享一下。 一、单元测试 微软官方给出的指导和示例在这里。一步一步按照说明下来就可以完成。(不截...
  • luminji
  • luminji
  • 2013年11月27日 14:03
  • 724

Ant构建Java项目

Ant构建Java项目 我们创建HelloWorld项目,将源文件.java发到src中,编译后字节码.class放到bin中,对应的jar包放到exe目录中。 首先使用命令行来构建项目: ...
  • u010852801
  • u010852801
  • 2015年06月21日 15:15
  • 1610

【Jenkins】——定时构建

一触即发
  • wangjinlong_
  • wangjinlong_
  • 2017年03月12日 15:14
  • 3258

初识持续集成(Continuous Integration)

随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成为开发过程中不可回避的问题。尤其是近些年来,敏捷(Agile) 在软件工程领域越来越红火,如何能再不断变化的...
  • BonJean
  • BonJean
  • 2016年05月22日 11:06
  • 1051

Ant—使用Ant构建简单Java项目(一)

Apache Ant主要用于Java项目的构建。为什么要使用Apache Ant来构建项目呢:        1)项目构建不是简单的编译,各种资源需要合理构建,例如有的类需要压缩成jar文件,有的文件...
  • wangshuxuncom
  • wangshuxuncom
  • 2014年10月16日 11:00
  • 9167

一个基于Maven项目Ant的构建模板

一般的我创建的项目都是基于Maven的,但是很多人也喜欢用Ant打包jar,或者war.我一般都会在项目中既包含Maven的pom.xml,也会有ant的build.xml 只要在控制台执行: ...
  • xiaole0313
  • xiaole0313
  • 2015年08月03日 13:00
  • 1631
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:自动化每日构建(一)用Ant来完成Delphi工程的每日构建
举报原因:
原因补充:

(最多只允许输入30个字)