Created
November 8, 2020 21:30
-
-
Save dive/7dd0f9afb0920e114293f525f223b511 to your computer and use it in GitHub Desktop.
Shell script to generate .xcworkspace with all .xcodeproj in the current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eo pipefail | |
# Prepare the workspace in the TEMP directory | |
NAME="Temp.xcworkspace" | |
DATA_FILE="contents.xcworkspacedata" | |
TEMP_DIR=$(mktemp -d) | |
mkdir "${TEMP_DIR}/${NAME}" | |
touch "${TEMP_DIR}/${NAME}/${DATA_FILE}" | |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Workspace version = \"1.0\">" >> "${TEMP_DIR}/${NAME}/${DATA_FILE}" | |
# Find all .xcodeproj and include them to the .xcworkspace we generate | |
find . \ | |
-name "*.xcodeproj" -type d \ | |
-exec echo "<FileRef location = \"container:{}\"></FileRef>" ';' \ | |
>> "${TEMP_DIR}/${NAME}/${DATA_FILE}" | |
echo "</Workspace>" >> "${TEMP_DIR}/${NAME}/${DATA_FILE}" | |
# Remove existed .xcworkspace | |
rm -Rf "$NAME" | |
# Copy the new one from the TEMP to the current directory | |
cp -r "${TEMP_DIR}/${NAME}" . | |
printf "Generated %s.\n" "$NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generate .xcworkspace with .xcodeproj in the current directory
Can be useful for automation, etc. The idea is straight forward:
.xcodeproj
in the current directory (recursively).xcworkspace
.xcodeproj
files to the.xcworkspace
.xcworkspace
directory from the Temp directory to the current oneA few caveats:
.xcodeproj
with the same name included (most probably, compilation will fail)-not -path "PATH"
to exclude any directory from thefind