Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2019 03:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save palaniraja/75ae5b7c200c13395fa0ddc0ac818918 to your computer and use it in GitHub Desktop.
script to delete unwanted buildconfig from xcodeproj file
# 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
NC='\033[0m' # No Color
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 ]]
echo "[${GREEN}SKIP${NC}] $configurationId = $buildConfig"
echo "[${RED}DELE${NC}] $configurationId = $buildConfig"
$plistbuddy -c "delete :objects:$configurationId" "$file" && sed -i '' "/$configurationId/d" "$file"
date # for time profiling
Copy link

raniemi commented Oct 6, 2023

Thanks Palani! I found this really helpful.

In the spirit of paying it back/forward, you might find this enhancement beneficial:

local json=$(plutil -convert json -o - $file)
local targets=($(echo $json | jq -r '.objects | to_entries[] | select(.value.buildConfigurations).key'))

Copy link

😎 thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment