Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
script to delete unwanted buildconfig from xcodeproj file
#!/bin/bash
# get these ids by "grep -B 2 buildConfigurations project.pbxproj"
targets=("040030D22004301100C4B676" "0420B3DA1FD1E91B00F66B8C" "042171FE1F7EB27500B3578D" "0421731D1F7EB3EC00B3578D" "04CD5F511FD0D1650053BE87" "3461E09E1A7BF77600B666A1" "3461E0C21A7BF77600B666A1" "A0D180071F46067500E00C0C")
# get these xcodebuild -project YOURPROJ.xcodeproj -list
configsToSkip=("us-debug" "us-debug-free" "us-release" "us-release-free" )
# Un-comment below line for debugging
# set -x
RED='\033[0;31m'
NC='\033[0m' # No Color
GREEN='\033[0;32m'
COMMENTCOLOR='\033[0;90m'
plistbuddy=/usr/libexec/plistbuddy
file=project.pbxproj
echo "\n"
echo "${RED}YOU'VE BEEN WARNED:${NC} Xcode buildconfig remover\n\n"
echo "I recommend keep copy of your .xcodeproj file\n\n"
echo "STEPS:\n"
echo "1. Find all build configurations to filter the one you want to keep"
echo " > ${GREEN}xcodebuild -project YOURPROJ.xcodeproj -list ${COMMENTCOLOR}#copy config list under build configurations. Replace variable \"configsToSkip\" contents with your config list${NC}"
echo "2. Convert the text plist to xml based one"
echo " > ${GREEN}/usr/libexec/PlistBuddy -x -c \"Print\" project.pbxproj > project.xml ${COMMENTCOLOR}#duplicate project.xml and rename it as project.pbxproj${NC}"
echo "3. Find keys of \"buildConfigurations\" from your project.pbxproj"
echo " > ${GREEN}grep -B 2 buildConfigurations project.pbxproj${NC} ${COMMENTCOLOR}#Replace variable \"targets\" with the \"GUIDS\" keys from the command results${NC}"
echo "4. Comeback after updating variables \"targets\" and \"config2skip\" to run the script"
echo "\n\n"
read -p "YES to continue or any key to abort: " confirm && [[ $confirm == "YES" ]] || exit 1
# echo "user typed YES"
echo "\n${RED}YOU'VE BEEN WARNED!${NC} Good luck\n"
date # for time profiling
for targetId in ${targets[@]}; do
echo "id: $targetId"
buildConfigurationList=`$plistbuddy -c "Print :objects:$targetId:buildConfigurations" "$file" | sed -e '/Array {/d' -e '/}/d' -e 's/^[ \t]*//'`
for configurationId in ${buildConfigurationList[@]}; do
# echo $configurationId
buildConfig=`$plistbuddy -c "Print :objects:$configurationId:name" "$file"`
# echo "$configurationId = $buildConfig"
if [[ ${configsToSkip[*]} =~ $buildConfig ]]
then
echo "[${GREEN}SKIP${NC}] $configurationId = $buildConfig"
else
echo "[${RED}DELE${NC}] $configurationId = $buildConfig"
$plistbuddy -c "delete :objects:$configurationId" "$file" && sed -i '' "/$configurationId/d" "$file"
fi
done
done
date # for time profiling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.