自动编译脚本编写指南

自动编译脚本编写指南

1. 目的

本文作为《自动编译调用接口文件要求.doc》文档的补充,收集了常见开发语言的编译脚本,目的是提供给配置管理员、项目经理以及需要实施自动编译的相关人员,进行参考和借鉴。

2. “简单编译”

对象:针对一些不需要调用编译语言进行编译的源码,例如:Php、Asp、Html等

编写思路:将这些源码文件进行打包压缩,放入output目录中。

Windows脚本样例

@echo off

setlocal

if "%zip.4.64%" == "" goto ERROR

set PATH=%zip.4.64%;%path%;

rem 利用7zip软件的命令行模式进行压缩

7z a -r test.zip test

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

rem 判断是否存在output目录,若存在则删除

IF EXIST "output" (RD /s /q "output")

md output

rem 将编译后的文件整理放入output文件夹

copy test.zip outputtest.zip

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

@echo on

echo Succeeded!

endlocal

exit 0

:ERROR

@echo on

echo Failed!

endlocal

exit 1

Linux脚本样例:

#!/bin/sh

#判断当前目录是否存在output文件夹,若存在则删除

[ -d "output" ]&& rm -rf output

#将test文件夹通过tar命令进行打包压缩

tar zcvf test.tar.gz test

#判断上一步操作是否正常完成

if [ $? -ne 0 ]; then exit 1 ; fi

#按照脚本要求,进行创建output文件夹

mkdir output

#将编译后的文件整理放入output文件夹

cp trade.tar.gz output

echo "copy complate"

3. “复杂编译”

对象:针对一些高级语言的源码,需要进行从源语言经过编译程序转化为目标语言,例如:Java、C/C++、.NET等

编写思路:按照《自动编译调用接口文件要求.doc》要求进行编写,将各种高级开发语言通过命令行格式调用编译程序进行编译操作,形成相应系统的脚本。

3.1. Java (利用ant进行编译)

Windows脚本样例:

@echo off

setlocal

rem 判断环境变量是否存在

if "%java.1.5.0%" == "" goto ERROR

if "%ant.1.7.0%" == "" goto ERROR

rem 调用环境变量,可根据实际环境需要进行设置

set JAVA_HOME=%java.1.5.0%

set ANT_HOME=%ant.1.7.0%

set PATH=%JAVA_HOME%bin;%ANT_HOMEbin;%PATH%

rem 利用ant调用相关xml文件实现编译

ant -f build.xml

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

@echo on

echo Succeeded!

endlocal

exit 0

:ERROR

@echo on

echo Failed!

endlocal

exit 1

Linux脚本样例:

#! /bin/sh

#判断环境变量是否存在

if [ "${java_1_5_0}" = "" ]; then exit 1 ; fi

if [ "${ant_1_7_0}" = "" ]; then exit 1 ; fi

#调用环境变量,可根据实际环境需要进行设置

JAVA_HOME="${jdk1_5_0}"

ANT_HOME="${ant_1_7_0}"

PATH="${ANT_HOME}/bin:${JAVA_HOME}/bin:${PATH}"

export JAVA_HOME ANT_HOME PATH

ant -f build.xml

if [ $? -ne 0 ]; then exit 1 ;fi

3.2. visual c 6 (利用msdev.com进行编译)

以下脚本是参考C:Program FilesMicrosoft Visual StudioVC98BinVCVARS32.BAT (安装目录为默认c盘时)文件修改而成

@echo off

setlocal

rem 如果该环境变量为空,则跳转执行ERROR

if "%MSDevDir%" == "" goto ERROR

if "%MSVCDir%" == "" goto ERROR

if "%VSCommonDir%" == "" goto ERROR

if "%OS%" == "" goto ERROR

if "%zip.4.64%" == "" goto ERROR

set VcOsDir=WIN95

if "%OS%" == "Windows_NT" set VcOsDir=WINNT

if "%OS%" == "Windows_NT"

set PATH=%MSDevDir%BIN;%MSVCDir%BIN;%VSCommonDir%TOOLS%VcOsDir%;%VSCommonDir%TOOLS;%zip.4.64 %;%PATH%

if "%OS%" == ""

set PATH="%MSDevDir%BIN";"%MSVCDir%BIN";"%VSCommonDir%TOOLS%VcOsDir%";"%VSCommonDir%TOOLS";"%windir%SYSTEM";"%PATH%"

set INCLUDE=%MSVCDir%ATLINCLUDE;%MSVCDir%INCLUDE;%MSVCDir%MFCINCLUDE;%INCLUDE%

rem 环境变量配置完成

set LIB=%MSVCDir%LIB;%MSVCDir%MFCLIB;%LIB%

echo building…

rem 开始编译

msdev.com DrawSys.dsw /make "DrawSys - Win32 Debug" /rebuild /USEENV

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

7z a -r test.zip .test

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

IF EXIST "output" (RD /s /q "output")

md output

copy test.zip outputtest.zip

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

@echo on

echo Succeeded!

endlocal

exit 0

:ERROR

@echo on

echo Failed!

endlocal

exit 1

3.3. .NET2003(利用Nant进行编译)

Ø .NET2003项目利用devenv.com在和cruisecontrol配合自动编译时可能出现异常停滞现象,利用nant编译无此问题。

Ø .NET2003的Web Application Projects在创建新项目时,必须指定location为URL,利用devenv.com编译时需要IIS支持,利用nant编译不需要IIS支持。

以下脚本的.net2003环境变量是参考C:Program FilesMicrosoft Visual Studio .NET 2003Common7Tools vsvars32.bat (安装目录为默认c盘时)文件修改而成。

通过Nant进行编译,需要建立一个“test.build”的文件,其xml格式如下:

<!-- encoding="gb2312"使得脚本文件可以支持中文-->

<?xml version="1.0" encoding="gb2312"?>

<!--name为项目名称, 此示例为test1-->

<!--default表示项目默认的target,此示例为test,可选-->

<!--basedir=“.”表示基准目录为当前目录-->

<project name="test1" default="test" basedir=".">

<target name="test">

<!--solutionfile为解决方案所在路径及名称, 此示例为test.sln-->

<!--configuration为生成方式, 此示例为Release-->

<solution solutionfile="test.sln" configuration="Release"/>

</target>

</project>

编译脚本示例如下:

@echo off

setlocal

rem 如果该环境变量为空,则跳转执行usage

@if "%VSINSTALLDIR%"=="" goto Usage

@if "%VCINSTALLDIR%"=="" set VCINSTALLDIR=%VSINSTALLDIR%

@if "%zip.4.64%"=="" goto ERROR

@if "FrameworkDir"=="" goto ERROR

@if "FrameworkVersion"=="" goto ERROR

@if "FrameworkSDKDir"=="" goto ERROR

@if "nant"=="" goto ERROR

@set DevEnvDir=%VSINSTALLDIR%

@rem

@rem Root of Visual C++ installed files.

@rem

@set MSVCDir=%VCINSTALLDIR%VC7

@rem

@echo Setting environment for using Microsoft Visual Studio .NET 2003 tools.

@echo (If you have another version of Visual Studio or Visual C++ installed and wish

@echo to use its tools from the command line, run vcvars32.bat for that version.)

@rem

@REM %VCINSTALLDIR%Common7Tools dir is added only for real setup.

@set PATH=%DevEnvDir%;%MSVCDir%BIN;%VCINSTALLDIR%Common7Tools;%VCINSTALLDIR%Common7Toolsbinprerelease;%VCINSTALLDIR%Common7Toolsbin;%FrameworkSDKDir%bin;%FrameworkDir%%FrameworkVersion%;%zip.4.64%;%PATH%;

@set INCLUDE=%MSVCDir%ATLMFCINCLUDE;%MSVCDir%INCLUDE;%MSVCDir%PlatformSDKincludeprerelease;%MSVCDir%PlatformSDKinclude;%FrameworkSDKDir%include;%INCLUDE%

@set LIB=%MSVCDir%ATLMFCLIB;%MSVCDir%LIB;%MSVCDir%PlatformSDKlibprerelease;%MSVCDir%PlatformSDKlib;%FrameworkSDKDir%lib;%LIB%

@goto end

:Usage

@echo. VSINSTALLDIR variable is not set.

@echo.

@echo SYNTAX: %0

@goto end

rem 环境变量配置完成

:end

rem 读取test.build文件,开始编译

nant -buildfile:test.build

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

rem 将编译结果进行打包压缩

7z a -r test.zip .test

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

IF EXIST "output" (RD /s /q "output")

md output

copy test.zip outputtest.zip

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

@echo on

echo Succeeded!

endlocal

exit 0

:ERROR

@echo on

echo Failed!

endlocal

exit 1

3.4. .NET2005 (利用devenv.com进行编译)

以下脚本是参考

C:Program FilesMicrosoft Visual Studio 8Common7ToolsVCVARS32.BAT (安装目录为默认c盘时)文件修改而成

@echo off

setlocal

@if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR

@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@if "%zip.4.64%"=="" goto ERROR

@if "%FrameworkDir%"=="" goto ERROR

@if "%FrameworkVersion%"=="" goto ERROR

@if "%FrameworkSDKDir%"=="" goto ERROR

@set DevEnvDir=%VSINSTALLDIR%Common7IDE

@set PATH=%VSINSTALLDIR%Common7IDE;%VSINSTALLDIR%VCBIN;%VSINSTALLDIR%Common7Tools;%VSINSTALLDIR%Common7Toolsbin;%VSINSTALLDIR%VCPlatformSDKbin;%FrameworkSDKDir%bin;%FrameworkDir%%FrameworkVersion%;%VSINSTALLDIR%VCVCPackages;%zip.4.64%;%PATH%

@set INCLUDE=%VSINSTALLDIR%VCATLMFCINCLUDE;%VSINSTALLDIR%VCINCLUDE;%VSINSTALLDIR%VCPlatformSDKinclude;%FrameworkSDKDir%include;%INCLUDE%

@set LIB=%VSINSTALLDIR%VCATLMFCLIB;%VSINSTALLDIR%VCLIB;%VSINSTALLDIR%VCPlatformSDKlib;%FrameworkSDKDir%lib;%LIB%

@set LIBPATH=%FrameworkDir%%FrameworkVersion%;%VSINSTALLDIR%VCATLMFCLIB

@goto end

:error_no_VSINSTALLDIR

@echo ERROR: VSINSTALLDIR variable is not set.

@goto end

:error_no_VCINSTALLDIR

@echo ERROR: VCINSTALLDIR variable is not set.

@goto end

rem 环境变量配置完成

:end

echo Building ...

rem 开始编译

devenv.com test.sln /rebuild "Debug|.NET" /useenv

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

7z a -r test.zip .test

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

IF EXIST "output" (RD /s /q "output")

md output

copy test.zip outputtest.zip

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

@echo on

echo Succeeded!

endlocal

exit 0

:ERROR

@echo on

echo Failed!

endlocal

exit 1

3.5. .NET2008 (利用devenv.com进行编译)

以下脚本是参考C:Program FilesMicrosoft Visual Studio 9.0Common7Toolsvsvars32.bat (安装目录为默认c盘时)文件修改而成

@echo off

setlocal

@if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR

@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@if "%zip.4.64%"=="" goto ERROR

@if "%FrameworkDir%"=="" goto ERROR

@if "%FrameworkVersion%"=="" goto ERROR

@if "%Framework35Version%"=="" goto ERROR

@call :GetWindowsSdkDir

@if not "%WindowsSdkDir%" == "" (

set "PATH=%WindowsSdkDir%bin;%PATH%"

set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"

set "LIB=%WindowsSdkDir%lib;%LIB%"

)

@set DevEnvDir=%VSINSTALLDIR%Common7IDE

@set PATH=%VSINSTALLDIR%Common7IDE;%VCINSTALLDIR%BIN;%VSINSTALLDIR%Common7Tools;%FrameworkDir%%Framework35Version%;%FrameworkDir%%FrameworkVersion%;%VCINSTALLDIR%VCPackages;%PATH%

@set INCLUDE=%VCINSTALLDIR%ATLMFCINCLUDE;%VCINSTALLDIR%INCLUDE;%INCLUDE%

@set LIB=%VCINSTALLDIR%ATLMFCLIB;%VCINSTALLDIR%LIB;%LIB%

@set LIBPATH=%FrameworkDir%%Framework35Version%;%FrameworkDir%%FrameworkVersion%;%VCINSTALLDIR%ATLMFCLIB;%VCINSTALLDIR%LIB;%LIBPATH%

@goto end

:GetWindowsSdkDir

@call :GetWindowsSdkDirHelper HKLM > nul 2>&1

@if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1

@if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%PlatformSDK

@exit /B 0

:GetWindowsSdkDirHelper

@for /F "tokens=1,2*" %%i in ('reg query "%1SOFTWAREMicrosoftMicrosoft SDKsWindows" /v "CurrentInstallFolder"') DO (

if "%%i"=="CurrentInstallFolder" (

SET "WindowsSdkDir=%%k"

)

)

@if "%WindowsSdkDir%"=="" exit /B 1

@exit /B 0

:error_no_VSINSTALLDIR

@echo ERROR: VSINSTALLDIR variable is not set.

@goto end

:error_no_VCINSTALLDIR

@echo ERROR: VCINSTALLDIR variable is not set.

@goto end

rem 环境变量配置完成

:end

echo Building...

rem 开始编译

devenv.com test.sln /rebuild "release|win32" /useenv

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

7z a -r test.zip .test

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

IF EXIST "output" (RD /s /q "output")

md output

copy test.zip outputtest.zip

IF %ERRORLEVEL% NEQ 0 GOTO ERROR

@echo on

echo Succeeded!

endlocal

exit 0

:ERROR

@echo on

echo Failed!

endlocal

exit 1

3.6. ios (利用xcodebuild进行编译)

#!/bin/bash 

v1=`pwd` 

echo "#####################" 
security unlock-keychain -p 123456 ${HOME}/Library/Keychains/login.keychain 
if [ $? -ne 0 ]; then exit 1 ;fi 

echo "#####################" 
cd $v1/Project/RemoteControl 
xcodebuild  -workspace RemoteControlWS.xcworkspace/ -scheme RemoteControl -configuration 'Release' CODE_SIGN_IDENTITY="iPhone Developer"  PROVISIONING_PROFILE="" 
if [ $? -ne 0 ]; then exit 1 ;fi 

echo "#####################" 
cd $v1/ 
xcrun -sdk iphoneos PackageApplication -v Project/RemoteControl/DerivedData/RemoteControlWS/Build/Products/Release-iphoneos/RemoteControl.app -o $v1/RemoteControl.ipa 
if [ $? -ne 0 ]; then exit 1 ;fi

(VDEJ8TQ$6Y28SPI(Z~KU}8

http://stblog.baidu-tech.com/?p=1295
http://www.infoq.com/cn/articles/build-ios-continuous-integration-platform-part1
http://www.infoq.com/cn/articles/build-ios-continuous-integration-platform-part2
http://www.infoq.com/cn/articles/build-ios-continuous-integration-platform-part3

http://vanlee820816.blog.163.com/blog/static/17981351201012333525108/

http://www.taobaotest.com/blogs/2334

http://blog.csdn.net/lanergaming/article/details/38785533

http://apple.stackexchange.com/questions/57059/how-do-i-transfer-my-ios-developer-profile-to-another-computer

https://developer.apple.com/library/ios/recipes/xcode_help-accounts_preferences/articles/obtain_certificates_and_provisioning_profiles.html#//apple_ref/doc/uid/TP40013306-CH19-SW1

security find-identity ${HOME}/Library/Keychains/login.keychain

ls ${HOME}/Library/MobileDevice/Provisioning\ Profiles/

 

3.7. MSYS

@echo off
set path=C:\MSYS\bin;C:\MSYS\mingw\bin;%path%
make

3.8. android

安装jdk,ant,andriod sdk

3.9. metro app

vs2012

devenv

makeappx

你可能感兴趣的:(自动编译脚本编写指南)