# Created by chenche on 13-1-21.
#!/bin/bash
cnt=1
if [ $# -ne $cnt ]; then
echo "error param num, only allow 1 params(case sensitive)!"
echo "example:"
echo "package "
exit -1
fi
buildSettings=""
xcodebuild -configuration $1 -target -showBuildSettings | grep --color=never -E '=' | awk -F"=" -v currentPath=$PWD '{
gsub(/[[:blank:]]/,"",$1); #去除$1中的所有blank
sub(/^[[:blank:]|"]/,"",$2); #去除头的blank,以及头的双引号
sub(/[[:blank:]|"]$/,"", $2); #去除尾的blank,以及尾的双引号
#print "export "$1"=\134""$2"\134"";
#print $1"=\134""$2"\134"";
if (tmp == "" && $1=="BUILD_DIR"){
tmp=$2;
sub(//Products$/, "/", tmp);
pattern=tmp"[Products|Intermediates]";
#print pattern;
#print tmp;
}
else if (tmp !="") {
#如果是给gsub传pattern参数,pattern参数的值无需在两端加"/"
#pattern1 = "/Build/[Products|Intermediates]";
#pattern1 = "/Build\//";
#print pattern1;
r = match($2, tmp);
if (tmp != "" && r) {
#print tmp" $2="$2;
gsub(pattern, currentPath"/build", $2);
#gsub(/Build/[Products|Intermediates]/, "00000000", $2);
#print $2;
}
}
print $1"="$2; #key=value
}' >buildTmp
while read buf
do
#echo $c
arr[$c]=$buf
let "c = $c + 1"
done
rm -rf buildTmp
#只有awk支持关联数组,shell本身的数组不支持,仅支持数字的下标
#echo "array len:" $c
for((i=0;i
do
key=${arr[$i]/=/}61 value=${arr[$i]/=/}
#UID is readonly
if [ "$key" != "UID" ]; then
# if [ -d "$value" ]; then
# echo $key,$value
# fi
export $key="$value"
fi
done
echo -e "\033[33;40;1m---------start building ...---------\033[0m"
xcodebuild -configuration $1 -target
echo -e "\033[33;40;1m---------build over------------------------------\033[0m"
echo -e "\033[33;40;1m---------start packaging ...--------\033[0m"
IPA_PATH=$SRCROOT/ipa
PAYLOAD_PATH=$IPA_PATH/Payload
mkdir -p $PAYLOAD_PATH
cp -r $TARGET_BUILD_DIR/$WRAPPER_NAME $PAYLOAD_PATH
cd $IPA_PATH
zip -r $PRODUCT_NAME.ipa *
mv $PRODUCT_NAME.ipa $SRCROOT
rm -rf $IPA_PATH
echo -e "\033[33;40;1m---------.ipa is done.-------------------\033[0m"