When xcodebuild
is run it will put the build directory under the Derived Data path. This script will locate that path. It requires a file named README.md to be in the project directory.
Created
December 9, 2021 23:18
-
-
Save brennanMKE/5ca36274b3249c2086a09950039feb8f to your computer and use it in GitHub Desktop.
Locate Build Path
This file contains 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
#!/bin/sh | |
PROJECT_DIR=$1 | |
if [ -z "${PROJECT_DIR}" ]; then | |
PROJECT_DIR=$(pwd) | |
fi | |
PLIST_BUDDY=/usr/libexec/PlistBuddy | |
if [ ! -f ${PLIST_BUDDY} ]; then | |
echo "PlistBuddy is not available." | |
exit 1 | |
fi | |
DERIVED_DATA_DIR="${HOME}/Library/Developer/Xcode/DerivedData" | |
findup() | |
{ | |
TARGET=$1 | |
PWD=$(pwd) | |
START="${PWD}" | |
while [ ! "${PWD}" -ef .. ]; do | |
[ -e "${TARGET}" ] && echo "$PWD" && return | |
cd .. || return | |
PWD=$(pwd) | |
done | |
} | |
read_build_dir() | |
{ | |
BUILD_DIR=$1 | |
INFO_PLIST="${BUILD_DIR}/info.plist" | |
if [ ! -f "${INFO_PLIST}" ]; then | |
return | |
fi | |
WORKSPACE_PATH=$(${PLIST_BUDDY} -c "Print WorkspacePath" "${INFO_PLIST}") | |
if [ -z "${WORKSPACE_PATH}" ]; then | |
return | |
fi | |
EFFECTIVE_WORKSPACE_PATH=$(findup README.md) | |
if [ "${PROJECT_DIR}" == "${EFFECTIVE_WORKSPACE_PATH}" ] ; then | |
echo "${BUILD_DIR}" | |
exit 0 | |
fi | |
} | |
read_build_dirs() | |
{ | |
for BUILD_DIR in $(find "${DERIVED_DATA_DIR}" -type d -maxdepth 1); do | |
read_build_dir ${BUILD_DIR} | |
done | |
exit 0 | |
} | |
read_build_dirs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment