Skip to content

Instantly share code, notes, and snippets.

@k-thorat
Last active July 11, 2023 12:59
Show Gist options
  • Save k-thorat/53d67ad0d75ba5d2992939d7fc85c104 to your computer and use it in GitHub Desktop.
Save k-thorat/53d67ad0d75ba5d2992939d7fc85c104 to your computer and use it in GitHub Desktop.
Xcode - Run Script - Create Input & Output file list of file-types to optimise build process.
#!/bin/sh
# Read more at:
# https://stackedheaps.com/2023/07/02/optimise-xcode-builds-with-input-output-file-lists
# Script Arguments:
# $1 = xcfilelist name without extension.
# Example: SwiftFiles
# $2 = Space separated list of file extensions (case sensitive).
# Examples: "swift json"
# $3 = Optional Output directory
# Path relative to $SRCROOT for saving xcfilelist.
# By default, file will be saved in projects root directory
# **********************************************************************************
# Create xcfilelist for the list of file type.
XC_FILE_LIST_NAME=$1
LIST_OF_FILE_TYPES=$2
OUTPUT_DIRECTORY=$3
if [ ! -z $OUTPUT_DIRECTORY ]; then
PROJECT_XC_FILE=$SRCROOT/$OUTPUT_DIRECTORY/$XC_FILE_LIST_NAME.xcfilelist
else
PROJECT_XC_FILE=$SRCROOT/$XC_FILE_LIST_NAME.xcfilelist
fi
BUILD_XC_FILE=$DERIVED_FILE_DIR/$XC_FILE_LIST_NAME.xcfilelist
OUTPUT_FILE=$DERIVED_FILE_DIR/$XC_FILE_LIST_NAME.txt
# Since we append the content, we need to start over.
# Append and remove is not required for one file type.
rm -f $BUILD_XC_FILE
for FILE_TYPE in $LIST_OF_FILE_TYPES;
do
echo "Creating xcfilelist for * $FILE_TYPE * file type"
# Find files and append the contents to xcfilelist.
find $SRCROOT -name "*.$FILE_TYPE" | sed -e "s#$SRCROOT#\$(SRCROOT)#;" >> $BUILD_XC_FILE
done
# Compare SRCROOT file with DERIVED_FILE_DIR file. Copy if anything has changed.
cmp --silent $PROJECT_XC_FILE $BUILD_XC_FILE || cp -f $BUILD_XC_FILE $PROJECT_XC_FILE
# Create an output file
touch $OUTPUT_FILE
# **********************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment