Skip to content

Commit

Permalink
ipa-build: add option to build workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchengfang committed Apr 26, 2013
1 parent 1f0be54 commit 3299268
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 72 deletions.
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,74 @@ Detail

----

####1.compile and package xcode project
##1.compile and package xcode project or workspace

You can do this by using "ipa-build" shell script.

**ipa-build**:This script is created to compile the xcode project and package the project to an ipa file.
This ipa-build script is created to compile the xcode project and package the project to an ipa file.

Usage:
####Usage:

***building xcode project***

ipa-build <project directory> [-c <project configuration>] [-o <ipa output directory>] [-t <target name>] [-n]

Options:
***building xcode workspace***

ipa-build <workspace directory> -w -s <schemeName> [-c <project configuration>] [-n]

####Options:

-c NAME the configuration of project used to compile.Default is Release
-o PATH output path for ipa file(must be a directory)
-t NAME the target which should be compiled
-w build xcode workspace
-s NAME the schemal to be used for compiling
-n clean the project before compling

Example:
If you have an iOS project in the path ~/iphone, and the ipa-build script is put in the path ~/xcode-shell.You want to build this project with 'Release' configuration.Just use script like this:
####Example:

***build project***

If you have an iOS project in the path ~/iphone, and the ipa-build script is put in the path ~/xcode-shell.You want to build this project with 'Release' configuration.Just using script like this:

cd ~/iphone
~/xcode-shell/ipa-build .

If the script runs successfully,you will found an ipa file in the directory ~/iphone/build/ipa-build.
If you want to assign specific configuration or target, you can add relevant options to the command.

***build workspace***

If ~/iphone is a xcode workspace and the scheme used for compile named 'test'.The ipa-build script is put in the path ~/xcode-shell.Using script like this:

cd ~/iphone
~/xcode-shell/ipa-build . -w -s test

You can also assign a specific configuration by using -c option.

If you want to assign configuration or target, you can add some options to the command.

Note:If script executed successfully,an ipa file is created in the path: <project path>/build/ipa-build.

##2.compile project used CocoaPods

[CocoaPods](https://github.com/CocoaPods/CocoaPods) is an Objective-C library manager.If you use it in your iOS project.You can also use 'ipa-build' script to build by assign workspace and scheme, or you can use the 'cocoapods-build' to build it more easily.

####Usage:

cocoapods-build <cococapods project path> [<build configuration>]

####Example:

cd ~/iphone
~/xcode-shell/cocoapods-build . Debug


####2.publish project
##3.publish project

**ipa-publish**: I will write it later.


####3.add @2x suffix to image files
##4.add @2x suffix to image files

When programming for retina device of iOS,the image file you used should add the suffix of @2x. Using the script "add2x" can help you do this automaticly.

Expand Down
58 changes: 16 additions & 42 deletions cocoapods-build
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

#--------------------------------------------
# 功能:为使用了CocoaPods的工程打ipa包
# 使用说明:第一个参数为工程根路径,第二个参数是编译配置(可选,默认为Release)
# 使用说明: cocoapods-build <cococapods project path> [<build configuration>]
# 作者:ccf
# E-mail:[email protected]
# 创建日期:2013/04/22
#--------------------------------------------


Expand All @@ -20,56 +19,31 @@ elif [ ! -d $1 ];then
exit
fi

build_config=Release

if [ $# = 2 ];then
build_config=$2
fi
#获取shell文件所在的绝对路径
current_path=$(pwd)
tmp_path=$(dirname $0)
cd $tmp_path
shell_path=$(pwd)
cd $current_path



#工程绝对路径
cd $1
project_path=$(pwd)
#build文件夹路径
build_path=${project_path}/build
#生成的app文件目录
appdirname=iphoneos
#编译后文件路径
compiled_path=${build_path}/${appdirname}
#获取工程默认scheme的名字(默认与工程文件名字相同)
scheme_name=$(echo $(basename ./*.xcodeproj) | awk -F. '{print $1}')


#编译工程
cd $project_path
#xcodebuild -configuration ${build_config} || exit
xcodebuild -workspace *.xcwork* -scheme ${scheme_name} -configuration ${build_config} CONFIGURATION_BUILD_DIR=${compiled_path} ONLY_ACTIVE_ARCH=NO || exit

#进入build路径
cd $build_path
build_cmd=${shell_path}'/ipa-build '${project_path}' -w -s '${scheme_name}

#创建ipa-build文件夹
if [ -d ./ipa-build ];then
rm -rf ipa-build
if [ $# = 2 ];then
build_cmd=${build_cmd}' -c '$2
fi
mkdir ipa-build


#app文件名称
appname=$(basename ./${appdirname}/*.app)
#通过app文件名获得工程target名字
target_name=$(echo $appname | awk -F. '{print $1}')
#app文件中Info.plist文件路径
app_infoplist_path=${build_path}/${appdirname}/${appname}/Info.plist
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${app_infoplist_path})
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${app_infoplist_path})

#IPA名称
ipa_name="${target_name}_${bundleShortVersion}_${build_config}${bundleVersion}_$(date +"%Y%m%d")"
echo $ipa_name

#xcrun打包
xcrun -sdk iphoneos PackageApplication -v ./${appdirname}/*.app -o ${build_path}/ipa-build/${ipa_name}.ipa


#编译工程
${build_cmd}


98 changes: 78 additions & 20 deletions ipa-build
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/bin/bash

#--------------------------------------------
# 功能:为xcode工程打ipa包
# 使用说明:ipa-build <project directory> [-c <project configuration>] [-o <ipa output directory>] [-t <target name>] [-n]
# 功能:编译xcode项目并打ipa包
# 使用说明:
# 编译project
# ipa-build <project directory> [-c <project configuration>] [-o <ipa output directory>] [-t <target name>] [-n]
# 编译workspace
# ipa-build <workspace directory> -w -s <schemeName> [-c <project configuration>] [-n]
#
# 参数说明:-c NAME 工程的configuration,默认为Release。
# -o PATH 生成的ipa文件输出的文件夹(必须为已存在的文件路径)默认为工程根路径下的”build/ipa-build“文件夹中
# -t NAME 需要编译的target的名称
# -w 编译workspace
# -s NAME 对应workspace下需要编译的scheme
# -n 编译前是否先clean工程
# 作者:ccf
# E-mail:[email protected]
Expand All @@ -19,6 +26,10 @@
# 修改人:ccf
# 修改内容:采用getopts来处理命令参数,并增加编译前清除选项
#--------------------------------------------
# 修改日期:2013/04/26
# 修改人:ccf
# 修改内容:增加编译workspace的功能
#--------------------------------------------



Expand All @@ -32,9 +43,14 @@ if [ ! -d $1 ];then
exit 2
fi

#工程绝对路径
cd $1
project_path=$(pwd)

#编译的configuration,默认为Release
build_config=Release

param_pattern=":nc:o:t:"
param_pattern=":nc:o:t:ws:"
OPTIND=2
while getopts $param_pattern optname
do
Expand Down Expand Up @@ -75,6 +91,33 @@ while getopts $param_pattern optname
exit 2
fi

;;
"w")
workspace_name='*.xcworkspace'
ls $project_path/$workspace_name &>/dev/null
rtnValue=$?
if [ $rtnValue = 0 ];then
build_workspace=$(echo $(basename $project_path/$workspace_name))
else
echo "Error!Current path is not a xcode workspace.Please check, or do not use -w option."
exit 2
fi

;;
"s")
tmp_optind=$OPTIND
tmp_optname=$optname
tmp_optarg=$OPTARG

OPTIND=$OPTIND-1
if getopts $param_pattern optname ;then
echo "Error argument value for option $tmp_optname"
exit 2
fi
OPTIND=$tmp_optind

build_scheme=$tmp_optarg

;;
"t")
tmp_optind=$OPTIND
Expand All @@ -90,9 +133,9 @@ while getopts $param_pattern optname

build_target=$tmp_optarg


;;


"?")
echo "Error! Unknown option $OPTARG"
exit 2
Expand All @@ -110,26 +153,47 @@ while getopts $param_pattern optname
done


#工程绝对路径
cd $1
project_path=$(pwd)
#build文件夹路径
build_path=${project_path}/build
#生成的app文件目录
appdirname=Release-iphoneos
if [ $build_config = Debug ];then
appdirname=Debug-iphoneos
fi
#编译后文件路径(仅当编译workspace时才会用到)
compiled_path=${build_path}/${appdirname}


if [ "$should_clean" = "y" ];then
#是否clean
if [ "$build_config" = "y" ];then
xcodebuild clean
fi

#编译工程
cd $project_path
build_cmd='xcodebuild -configuration '${build_config}

if [ "$build_target" != "" ];then
build_cmd=$build_cmd' -target '$build_target
#组合编译命令
build_cmd='xcodebuild'

if [ "$build_workspace" != "" ];then
#编译workspace
if ["$build_scheme" = ""];then
echo "Error! Must provide a scheme by -s option together when using -w option to compile a workspace."
exit 2
fi

build_cmd=${build_cmd}' -workspace '${build_workspace}' -scheme '${build_scheme}' -configuration '${build_config}' CONFIGURATION_BUILD_DIR='${compiled_path}' ONLY_ACTIVE_ARCH=NO'

else
#编译project
build_cmd=${build_cmd}' -configuration '${build_config}

if [ "$build_target" != "" ];then
build_cmd=${build_cmd}' -target '${build_target}
fi

fi


#编译工程
cd $project_path
$build_cmd || exit

#进入build路径
Expand All @@ -142,11 +206,6 @@ fi
mkdir ipa-build


#生成的app文件目录
appdirname=Release-iphoneos
if [ $build_config = Debug ];then
appdirname=Debug-iphoneos
fi

#app文件名称
appname=$(basename ./${appdirname}/*.app)
Expand All @@ -170,4 +229,3 @@ if [ "$output_path" != "" ];then
cp ${build_path}/ipa-build/${ipa_name}.ipa $output_path/${ipa_name}.ipa
echo "Copy ipa file successfully to the path $output_path/${ipa_name}.ipa"
fi
# 修改内容:#--------------------------------------------

0 comments on commit 3299268

Please sign in to comment.