美文网首页tool for work命令行/Shell持续集成
使用plutil/PlistBuddy获取项目的配置信息

使用plutil/PlistBuddy获取项目的配置信息

作者: 独孤流 | 来源:发表于2019-08-17 17:17 被阅读2次

前言

在之前文章里提出过因为项目一份代码要根据不同的平台导出不同的的包,解决方式是使用多Target或一个target在打包时动态修改bundld及描述文件,现在记录下多target下查找每个target的配置信息

#!/bin/bash

#定义要查找的target
find_target="xxx"
#要解析的xcodeproj
src_root_path="/xxx/xxx"
#SRCROOT=$src_root_path
xcodeproj_path="$src_root_path/xxx.xcodeproj"
##项目配置文件本质上也是一个xml,所以可以用/usr/libexec/PlistBuddy进行读和写
pbxproj_path="$xcodeproj_path/project.pbxproj"
xcworkspace_path="$src_root_path/xxx.xcworkspace"

#将描述文件解析成plist文件
tempVarFile="./tempVarFile.txt"
if [ ! -f $tempVarFile ];then
touch $tempVarFile
else
  rm -f $tempVarFile
  touch $tempVarFile
fi


#打印所有的target,纯粹为了打印使用
xcodebuild -project $xcodeproj_path -list -alltargets
#将pbxproj项目配置文件转换成jsno文件好人工阅读解析
#plutil -convert json -r -o "./test.json" "$pbxproj_path"
#获取根配置
pbx_rootObject=$(/usr/libexec/PlistBuddy -c "print :rootObject:" $pbxproj_path)
echo $pbx_rootObject
#获取根配置对应的所有targets列表
pbx_targets=$(/usr/libexec/PlistBuddy -c "print :objects:$pbx_rootObject:targets" $pbxproj_path)

#将查找到的所有targets的id转换成数组
array_targets=(${pbx_targets//,/ })
echo "total:${#array_targets[@]} realCount:$[${#array_targets[@]}-3] find:$find_target"
#查找次数
find_times=0
#遍历所有target对应的id
for pbx_target in ${array_targets[@]}
do
echo $pbx_target
real_pbx_target=""
#判断只有不是Array,{,}这几个的才是真正的target的id
  if  [ $pbx_target != "Array"  -a  $pbx_target != "{"   -a   $pbx_target !=  "}" ];  then
    find_times=$[$find_times+1]
#获取targetId对应的名字,并和查找的名字对比
    target_name=$(/usr/libexec/PlistBuddy -c "print :objects:$pbx_target:name" $pbxproj_path)
    if [ $target_name != $find_target ]
    then
      continue
    fi
    real_pbx_target=$pbx_target
#打包
    if [ $target_name == $find_target ]
    then
       break
    fi
   fi
done

 echo "find_times:$find_times"
echo "real_pbx_target:$real_pbx_target"
 target_buildConfigurationList=$(/usr/libexec/PlistBuddy -c "print :objects:$pbx_target:buildConfigurationList" $pbxproj_path)
 target_debug=$(/usr/libexec/PlistBuddy -c "print :objects:$target_buildConfigurationList:buildConfigurations:0" $pbxproj_path)
 target_release=$(/usr/libexec/PlistBuddy -c "print :objects:$target_buildConfigurationList:buildConfigurations:1" $pbxproj_path)

 target_debug_identifier=$(/usr/libexec/PlistBuddy -c "print :objects:$target_debug:buildSettings:PRODUCT_BUNDLE_IDENTIFIER" $pbxproj_path)
 target_debug_profile=$(/usr/libexec/PlistBuddy -c "print :objects:$target_debug:buildSettings:PROVISIONING_PROFILE_SPECIFIER" $pbxproj_path)
 target_debug_team=$(/usr/libexec/PlistBuddy -c "print :objects:$target_debug:buildSettings:DEVELOPMENT_TEAM" $pbxproj_path)
 #iPhone Developer, iPhone Distribute
 target_debug_code=$(/usr/libexec/PlistBuddy -c "print :objects:$target_debug:buildSettings:CODE_SIGN_IDENTITY" $pbxproj_path)
 #manual auto
 target_debug_style=$(/usr/libexec/PlistBuddy -c "print :objects:$target_debug:buildSettings:CODE_SIGN_STYLE" $pbxproj_path)

 target_release_identifier=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:PRODUCT_BUNDLE_IDENTIFIER" $pbxproj_path)
 target_release_profileName=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:PROVISIONING_PROFILE_SPECIFIER" $pbxproj_path)
 target_release_profileId=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:PROVISIONING_PROFILE" $pbxproj_path)
 target_release_team=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:DEVELOPMENT_TEAM" $pbxproj_path)
 #iPhone Developer, iPhone Distribute
 target_release_code=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:CODE_SIGN_IDENTITY" $pbxproj_path)
 #manual auto
 target_release_style=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:CODE_SIGN_STYLE" $pbxproj_path)
 target_release_infoPath=$(/usr/libexec/PlistBuddy -c "print :objects:$target_release:buildSettings:INFOPLIST_FILE" $pbxproj_path)
 real_target_release_infoPath=${target_release_infoPath/\$(SRCROOT)/$src_root_path}



 echo "\r\n"
 echo "targetId:$pbx_target"
 echo "target_name:$target_name"
 echo "target_configList:$target_buildConfigurationList"
 echo "target_release:$target_release"
 echo "target_debug:$target_debug"

 echo "target_release_identifier:$target_release_identifier"
 echo "target_release_profileName:$target_release_profileName"
 echo "target_release_profileId:$target_release_profileId"
 echo "target_release_team:$target_release_team"
 echo "target_release_code:$target_release_code"
 echo "target_release_style:$target_release_style"
 echo "target_release_infoPath:$target_release_infoPath"
 echo "real_target_release_infoPath:$real_target_release_infoPath"



 #manual auto
 real_sign_style="Manual"
 /usr/libexec/PlistBuddy -c "Set :objects:$target_release:buildSettings:CODE_SIGN_STYLE $real_sign_style" $pbxproj_path

 #manual auto
 real_sign_style="Manual"
 /usr/libexec/PlistBuddy -c "Set :objects:$target_debug:buildSettings:CODE_SIGN_STYLE $real_sign_style" $pbxproj_path


#通过对项目里的project.xcodeproj配置文件信息生成导出ipa包的ExportOptions.plist描述文件
 cat > "./ExportOptions.plist" << END_TEXT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<true/>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>enterprise</string>
<key>provisioningProfiles</key>
<dict>
 <key>${target_release_identifier}</key>
 <string>${target_release_profileName}</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>${target_release_team}</string>
<key>thinning</key>
<string>&lt;none&gt;</string>
</dict>
</plist>
END_TEXT

 #生成archive
  xcodebuild archive \
 -workspace "$xcworkspace_path" \
 -scheme ${find_target} \
 -configuration Release \
 -archivePath "./test.xcarchive"

 #导出ipa
 xcodebuild -exportArchive \
 -archivePath "./test.xcarchive" \
 -exportPath "./test_ipa" \
 -exportOptionsPlist "./ExportOptions.plist"

 # 压缩dSYM文件
 zip -q -r "./test.app.dSYM.zip" "./test.xcarchive/dSYMs/${find_target}.app.dSYM"



参考资料:

for var1 in 1 2 3
do
   for var2 in 0 5
   do
      if [ $var1 -eq 2 -a $var2 -eq 0 ]
      then
         break 2
      else
         echo "$var1 $var2"
      fi
   done
done原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/shell/unix-loop-control.html


a=1  
a=$(($a+1))  
a=$[$a+1]  
a=`expr $a + 1`  
let a++  
let a+=1
-a         与 
-o        或 
!        非
str="i,like,you,csdn"
arr=(${str//,/ })

for s in ${arr[@]}
do
    echo $s
done
# 取得数组元素的个数
length=${#array_name[@]}
# 或者
length=${#array_name[*]}
# 取得数组单个元素的长度
lengthn=${#array_name[n]}

相关文章

网友评论

    本文标题:使用plutil/PlistBuddy获取项目的配置信息

    本文链接:https://www.haomeiwen.com/subject/osrksctx.html