This question is a component of this question and an extension to this question which has been solved. This situation might feel a pinch constructed but it is a simplified version of one step of the original question.
Basically in my app I have a script that outputs a folder with a few files inside of it. This folder is output to $(BUILT_PRODUCTS_DIR)/build/
and is referenced via a PBXBuildFile.
Because I put a wait in the script (to simulate a long build I have in my real project) it is very obvious when the script is or isn't run. The goal would be for it to run only when its dependencies have changed.
The trick is if I put this script as a "run script" phase within my final target dependency analysis works great. The script only runs when the dependencies are updated. However if I put the "run script" phase into an aggregate target then add it as a Target Dependency in the main target Xcode wants to run the script every time. Regardless of if the dependencies have changed. However if you build just the aggregate target alone everything goes just fine. It only builds when it has to.
To me this does not quite make sense. I thought that dependency analysis of the script within my aggregate target would be the same regardless of whether that script was within the aggregate target or the main target.
In my app I ideally need the aggregate target to be shared by multiple other targets. While I could put the script in each it would be more foolproof to have them share an aggregate target.
Why would dependency analysis come to a different conclusion when the script is within an aggregate target that is a target dependency of the main target?
If it helps here is the script and the entire project can be found here on GitHub if you would like to play with it.
mkdir -p "${SCRIPT_OUTPUT_FILE_0}/build/"
echo "Pausing for 10 seconds before creating files..."
sleep 10
cat "${SCRIPT_INPUT_FILE_0}"
cat > "${SCRIPT_OUTPUT_FILE_0}/build/index.html" << EOF
<!DOCTYPE html>
<html>
<head>
<title>Simple Page</title>
</head>
<body>
<h1>Welcome to Simple Page</h1>
<p>Generated at: $(date)</p>
</body>
</html>
EOF
cat > "${SCRIPT_OUTPUT_FILE_0}/build/page.html" << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>Simple Page</title>
</head>
<body>
</body>
</html>
EOF