集成与构建指南(4)
2004-03-01 10:10
295 查看
1 构建基础知识
1.1 Ant构建脚本
自动化构建的核心是表达构件间依赖关系和构建步骤的脚本,Make工具使用makefile,而Ant使用了基于XML格式的缺省文件名为Build.Xml的配置文件。1.1.1 Ant项目配置文件
Ant配置文件描述了一个构建项目(project),它由一些属性定义(property)和一个目标树(target tree)组成;目标代表了一个期望的构建结果(例如生成一个链接好的可执行文件),并表述了其依赖的其它目标,常见的构建目标有初始化(Init)、编译(Compile)、单元测试(Test)、安装(Install)、清除(Clean)等;每个目标包含了实现它而将要执行的任务(task),Ant支持的任务种类非常丰富,例如源码编译、文件拷贝、执行命令行操作等。Ant还提供一种非常重要的任务就是执行其它的项目配置文件,使得多个构建项目的批处理成为可能。1.1.2 Ant配置文件示例
下面是一个Ant项目的配置文件示例:<?xml version="1.0"?> <project name="Improve-Install" default="InstallAll" basedir="."> <description > Build file for all Improve library project </description> <!-- task and type extension --> <taskdef resource="cpptasks.tasks"/> <typedef resource="cpptasks.types"/> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <!-- Properties --> <property environment="sys_env"/> <property name="proj.root" location="../."/> <target name="-Init"> <condition property="cc" value="${mswin32-compiler}"> <os family="windows"/> </condition> <condition property="cc" value="gcc"> <os family="unix"/> </condition> <echo message="${ant.project.name}: Init Complete"/> </target> <target name="Clean" depends="-Init" description="Clean the temporal building space"> <!-- Delete all files in temporal build space --> <delete includeEmptyDirs="true" > <fileset dir="${tgt.bin}" includes="objs/*, objs_d/*" defaultexcludes="false"/> </delete> <delete includeEmptyDirs="true" > <fileset dir="${tgt.lib}" includes="objs/*, objs_d" defaultexcludes="false"/> </delete> <echo message="${ant.project.name}: Clean buildspace Complete"/> </target> <target name="AutoBuild" depends="-Init, -Prep" description="AutoBuild all source to get bin out"> <mkdir dir="${tgt.lib}/objs_d"/> <mkdir dir="${tgt.lib}/objs"/> <if> <equals arg1="${cc}" arg2="msvc"/> <then> <cc name="${cc}" objdir="${tgt.lib}/objs_d" outfile="${tgt.lib}/improve_debug" outtype="static" exceptions="true" multithreaded="true" runtime="dynamic" debug="true"> <compiler extends="${cc}-compiler"> <includepath path="${tgt.interface}"/> <includepath path="${getenv.BOOST_ROOT}/include"/> <includepath path="${getenv.CPPUNIT_ROOT}/include"/> <defineset > <define name="WIN32"/> <define name="_WINDOWS"/> </defineset> <compilerarg value="/W3"/> <compilerarg value="/GR"/> <compilerarg value="/O2"/> </compiler> <linker extends="${cc}-linker"> <linkerarg value="/machine:I386"/> <!--fileset dir="${getenv.LIBS_ROOT}/lib" includes="3d_party.*"/--> </linker> <fileset dir="${tgt.src}"> <include name="**/*.cpp"/> <include name="**/*.c"/> <exclude name="exception_ex.*"/> </fileset> </cc> <echo message="${ant.project.name}: AutoBuild Complete"/> </target> <target name="Test" depends="-Init, TestBuild" description="Perform acception testing"> <exec executable="test_main_debug.exe" dir="${tgt.bin}" failonerror="true" vmlauncher="false" os="Windows 2000"> <env key="Path" path="${getenv.Path};${getenv.CPPUNIT_ROOT}/lib;${getenv.BOOST_ROOT}/lib"/> </exec> <echo message="test_main.exe Debug Version Testing Pass"/> <exec executable="test_main.exe" dir="${tgt.bin}" failonerror="true" vmlauncher="false" os="Windows 2000"> <env key="Path" path="${getenv.Path};${getenv.CPPUNIT_ROOT}/lib;${getenv.BOOST_ROOT}/lib"/> </exec> <echo message="test_main.exe Release Version Testing Pass"/> <echo message="${ant.project.name}: Testing Complete"/> </target> <target name="InstallAll" depends="CleanAll, AutoBuild, Install, Test" description="Make a clean (re)install and test"> <echo message="${ant.project.name}: Install/Reinstall Complete"/> </target> </project> |
本项目中各Ant配置文件的具体配置和使用,请参见Ant用户手册等参考资料,和阅读Ant配置文件本身内容。
1.1.3 Ant执行示例
Ant在命令行下执行的示例:![](http://blog.csdn.net/Develop/ArticleImages/25/25004/CSDN_Dev_Image_2004-2-291844260.png)
相关文章推荐
- 集成与构建指南-概述
- 集成与构建指南(2)
- 集成与构建指南
- 集成与构建指南(3)
- 集成与构建指南(5)
- 集成与构建指南(6)
- 集成与构建指南(7)
- 集成与构建指南(8)
- 集成与构建指南(9)
- 集成与构建指南(10)
- 用于构建集成式桌面应用程序的新指南和新工具(转载于MSDN)
- Vista新技术:WCF开发指南之构建服务
- Swarm和Mesos集成指南-原理剖析
- spring boot 1.5.4 集成Swagger2构建Restful API(十八)
- Weex iOS SDK 集成指南
- 可持续集成构建--CruiseControl
- 持续集成--测试三角形与分段构建策略原则
- 【Nutch2.2.1基础教程之2.2】集成Nutch/Hbase/Solr构建搜索引擎之二:内容分析
- 将AngularJS的单元测试和端到端测试集成到gradle构建脚本中
- 图解持续集成--纯命令行实现.Net项目每日构建(升级版本)