这与GCC在另一个类Unix系统上工作正常:
-D__BUILD_VERSION = $(cat build_number)
好的XCode我试图使用以下内容:
-D__BUILD_VERSION = $(cat $PROJECT_DIR / build_number)
但它不起作用,我做错了什么?在XCode中,如何将cat build_number的结果分配给__BUILD_VERSION定义的变量?
解决方法 如果你试图在 Xcode编译构建阶段设置该值,你可能会遇到麻烦,因为我不知道任何解释 *** 作都是在您尝试设置您尝试设置的方式设置的情况下进行的他们了对于自动设置版本号,我有一个更复杂的半自动版本和自动编号方案,所以我不必记得改变,或者所以我可以给我想要的版本号但总是增加内部版本号,在两种情况下,它都会将内部版本号放在iOS系统设置中显示的应用程序设置的“关于”框中.
你可能不需要太多,但是有一些技巧可以获取和编写你可能觉得有用的信息,并可能为你的问题找到解决方案.
以下脚本的灵感来自堆栈溢出的答案,如何做到这一点,我目前无法找到.我投入了更多的工作,因为(a)我希望版本号显示在系统设置中显示的设置中; (b)Xcode缓存Info.pList文件的内容,因此这样做并不像我预期的那么简单.
在编译之前的构建阶段,我运行以下(仅在安装未选中时使用运行脚本)
sh xolawareStashProductSettings.sh
xolawareStashProductSettings.sh的内容检查info.pList文件的git状态,如果不清理,暂时将其存放在一边以备日后恢复.
#!/bin/sh## should be run prior to the copy Bundle Resources step# and prior to any version information modifIEr scriptsINFOPList_GIT_PATH=${PROJECT}/`basename ${INFOPList_file}`echo "-- Temp Hold ${INFOPList_GIT_PATH} Script --"set -e# a fallback in case the user has made changes to the fileif [ `git status --porcelain ${INFOPList_GIT_PATH} ]|wc -l` -gt 0 ]; then echo cp -p ${INFOPList_GIT_PATH} ${TARGET_TEMP_DIR} cp -p ${INFOPList_GIT_PATH} ${TARGET_TEMP_DIR}fi
脚本#2(仅在安装未选中时使用运行脚本):
sh xolawareStashSettingsBundleRootPList.sh
xolawareStashSettingsBundleRootPList.sh的内容类似于脚本1的内容.
#!/bin/sh## should be run prior to the copy Bundle Resources step# and prior to any version information modifIEr scriptsecho '-- Temp Hold Settings.bundle/Root.pList Script --'ROOT_PList=${PROJECT}/Resources/Settings.bundle/Root.pListset -e# a fallback in case the user has made changes to the fileif [ `git status --porcelain ${ROOT_PList} ]|wc -l` -gt 0 ]; then echo cp -p ${ROOT_PList} ${TARGET_TEMP_DIR} cp -p ${ROOT_PList} ${TARGET_TEMP_DIR}fi
脚本#3(仅在安装时检查运行脚本)
sh xolawareIncrementProductSettingsBuildNumber.sh
xolawareIncrementProductSettingsBuildNumber的内容使用pListbuddy来查看它是什么并将其碰到一个:
#!/bin/sh## this should be prior to xolawareAboutInfoVersionInfoInSettings.shecho "-- auto-Increment ${INFOPList_file} Build Version Install Script --"PListBUDDYCMD="/usr/libexec/PListBuddy -c"CONfigURATION_BUILD_SETTINGS_PATH=${CONfigURATION_BUILD_DIR}/${INFOPList_PATH}CFBV=$(${PListBUDDYCMD} "Print :CFBundLeversion" ${PRODUCT_SETTINGS_PATH})if [[ "${CFBV}" == "" ]]; then echo "No build number in ${PRODUCT_SETTINGS_PATH}" exit 2fiCFBV=$(expr $CFBV + 1)set -eecho ${PListBUDDYCMD} "Set :CFBundLeversion $CFBV" "${PRODUCT_SETTINGS_PATH}"${PListBUDDYCMD} "Set :CFBundLeversion $CFBV" "${PRODUCT_SETTINGS_PATH}"echo ${PListBUDDYCMD} "Set :CFBundLeversion $CFBV" "${CONfigURATION_BUILD_SETTINGS_PATH}"${PListBUDDYCMD} "Set :CFBundLeversion $CFBV" "${CONfigURATION_BUILD_SETTINGS_PATH}"
脚本#4(仅在安装未选中时使用运行脚本)
sh xolawareProductSettingsShortVersion-from-git.shsh xolawareAboutInfoVersionInfoInSettings.sh
xolawareProductSettingsShortVersion-from-git的内容依赖于我在git中正确标记我的分支,但是如果我忘记了,它将使用自上次提交以来为我自动编译我的构建的提交数量.
#!/bin/sh## this should be run after xolawareStashSettingsBundleRootPList.sh# and prior to xolawareAboutInfoVersionInfoInSettings.shecho '-- Get Product Settings Short Version String from git describe --'PListBUDDYCMD="/usr/libexec/PListBuddy -c"CONfigURATION_BUILD_SETTINGS_PATH=${CONfigURATION_BUILD_DIR}/${INFOPList_PATH}CFBVS=`git describe|awk '{split(#!/bin/sh## this should be invoked after xolawareStashInfoAndRootPList.sh,# xolawareIncrementProductSettingsBuildNumber.sh and # xolawareProductSettingsShortVersion-from-git.sh,and before# the regular copy Bundle Resources Build Phaseecho '-- auto-Insert Version Info In System Settings Script --'PListBUDDYCMD="/usr/libexec/PListBuddy -c"ROOT_PList=${PROJECT_DIR}/${PROJECT}/Resources/Settings.bundle/Root.pListCFBSVS=`exec -c ${PListBUDDYCMD} "Print :CFBundleShortVersionString" ${PRODUCT_SETTINGS_PATH}`CFBV=`exec -c ${PListBUDDYCMD} "Print :CFBundLeversion" ${PRODUCT_SETTINGS_PATH}`set -eecho ${PListBUDDYCMD} "Set :PreferenceSpecifIErs:1:DefaultValue '${CFBSVS} (b${CFBV})'" ${ROOT_PList}${PListBUDDYCMD} "Set :PreferenceSpecifIErs:1:DefaultValue '${CFBSVS} (b${CFBV})'" ${ROOT_PList},a,"-"); print a[1]}'`CFBVSI=`git describe|awk '{split(sh xolawareStashRestoresettingsBundleRootPList.sh,"-"); print a[2]}'`if [[ "$CFBVSI" != "" ]]; then CFBVS=${CFBVS}.${CFBVSI}fiset -eecho ${PListBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${PRODUCT_SETTINGS_PATH}"${PListBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${PRODUCT_SETTINGS_PATH}"echo ${PListBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${CONfigURATION_BUILD_SETTINGS_PATH}"${PListBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${CONfigURATION_BUILD_SETTINGS_PATH}"
xolawareAboutInfoVersionInfoInSettings.sh的内容将内容放在我想要的Root.pList的About框中.它依赖于About框是您的settings.bundle的Root.pList中的第一个东西:
#!/bin/sh## should be run as the second to last script in Build Phases,after the copy Bundle Resources Phaseecho "-- Manual Restore $INFOPList_file Script --"ROOT_PList=${PROJECT}/Resources/Settings.bundle/Root.pListset -e# first,see if it was stashed earlIEr due to uncommitted changesif [ -e ${TARGET_TEMP_DIR}/Root.pList ]; then echo mv ${TARGET_TEMP_DIR}/Root.pList ${ROOT_PList} mv ${TARGET_TEMP_DIR}/Root.pList ${ROOT_PList}# the better option when available: restore to the pristine stateelif [ `git status --porcelain ${ROOT_PList}|wc -l` -gt 0 ]; then echo git checkout -- ${ROOT_PList} git checkout -- ${ROOT_PList}fi
还有一些清理脚本可以在Compile,link&之后运行.复制捆绑资源阶段
sh xolawareProductSettings-git-commit-and-tag.sh#!/bin/sh## this should be run after xolawareAboutInfoVersionInfoInSettings.sh# and xolawareProductSettingsShortVersion-from-git.shecho "-- ${INFOPList_file} git commit & tag Install Script --"SCRIPT_VERSION=`/usr/libexec/PListBuddy -c 'Print :CFBundleShortVersionString' ${INFOPList_file}`SCRIPT_BUILD_NUMBER=`/usr/libexec/PListbuddy -c 'Print :CFBundLeversion' ${INFOPList_file}`if [ `git status --porcelain ${SCRIPT_INFO_PList}|wc -l` -gt 0 ]; then echo git commit -m '"'version ${SCRIPT_VERSION} build ${SCRIPT_BUILD_NUMBER}'"' ${INFOPList_file} git commit -m "version ${SCRIPT_VERSION} build ${SCRIPT_BUILD_NUMBER}" ${INFOPList_file}fiecho git tag -f ${SCRIPT_VERSION}git tag -f -F /dev/null ${SCRIPT_VERSION}
这可能没有必要,但我调整Root.pList中的其他项目以用于发布版本,因此这将恢复调试版本的这些设置.
最后,如果我还没有标记该项目,那么自动标记git repo的步骤:
总结以上是内存溢出为你收集整理的XCode C/C++标志Bash脚本全部内容,希望文章能够帮你解决XCode C/C++标志Bash脚本所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)