[Author: thomasvl]

Make the target for all tests directly depend on the tests instead of shelling out to xcode build (make things nicer in 3.2.x tool chain).
Add an action to the GTM Framework to nuke any *.gcda files to help make coverage tracking easier.
Mac OS test runner script:
  Not be verbose (for the 3.2.x tool chain).
  Add a var to cause it only to remove target *.gcda files.
  Add a var to force tests to only run one at a time (via some pyton that emulates linux's flock).
Make the UnitTesting and AppKit tests use the flock support so they don't fight over the colorsync profile.

R=dmaclach
DELTA=141  (102 added, 28 deleted, 11 changed)
diff --git a/GTM.xcodeproj/project.pbxproj b/GTM.xcodeproj/project.pbxproj
index 9364e46..e360a09 100644
--- a/GTM.xcodeproj/project.pbxproj
+++ b/GTM.xcodeproj/project.pbxproj
@@ -11,9 +11,12 @@
 			isa = PBXAggregateTarget;
 			buildConfigurationList = F47204340D33BEDF00E9F378 /* Build configuration list for PBXAggregateTarget "All UnitTests" */;
 			buildPhases = (
-				8BAA9A2B0F7AF44A00DF4F12 /* ShellScript */,
 			);
 			dependencies = (
+				F4E4279810B7484B00F28A35 /* PBXTargetDependency */,
+				F4E4279610B7484B00F28A35 /* PBXTargetDependency */,
+				F4E4279210B7484B00F28A35 /* PBXTargetDependency */,
+				F4E4279410B7484B00F28A35 /* PBXTargetDependency */,
 			);
 			name = "All UnitTests";
 			productName = "All UnitTests";
@@ -387,13 +390,6 @@
 			remoteGlobalIDString = 8B45A2890DA49B99001148C5;
 			remoteInfo = UIUnitTestingHarness;
 		};
-		8BFE13BE0FB0F2D8001BE894 /* PBXContainerItemProxy */ = {
-			isa = PBXContainerItemProxy;
-			containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
-			proxyType = 1;
-			remoteGlobalIDString = 8B45A2890DA49B99001148C5;
-			remoteInfo = UIUnitTestingHarness;
-		};
 		8BFE13C00FB0F2D8001BE894 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
 			containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
@@ -415,6 +411,34 @@
 			remoteGlobalIDString = F42E086C0D199A5B00D5DDE0;
 			remoteInfo = GTM;
 		};
+		F4E4279110B7484B00F28A35 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
+			proxyType = 1;
+			remoteGlobalIDString = 8BFE13BC0FB0F2D8001BE894 /* UnitTest - AddressBook */;
+			remoteInfo = "UnitTest - AddressBook";
+		};
+		F4E4279310B7484B00F28A35 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
+			proxyType = 1;
+			remoteGlobalIDString = F48FE2630D198C1E009257D2 /* UnitTest - AppKit */;
+			remoteInfo = "UnitTest - AppKit";
+		};
+		F4E4279510B7484B00F28A35 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
+			proxyType = 1;
+			remoteGlobalIDString = F42E08110D19987200D5DDE0 /* UnitTest - Foundation */;
+			remoteInfo = "UnitTest - Foundation";
+		};
+		F4E4279710B7484B00F28A35 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
+			proxyType = 1;
+			remoteGlobalIDString = 8B45A0270DA4696C001148C5 /* UnitTest - UnitTesting */;
+			remoteInfo = "UnitTest - UnitTesting";
+		};
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
@@ -1504,7 +1528,6 @@
 			buildRules = (
 			);
 			dependencies = (
-				8BFE13BD0FB0F2D8001BE894 /* PBXTargetDependency */,
 				8BFE13BF0FB0F2D8001BE894 /* PBXTargetDependency */,
 			);
 			name = "UnitTest - AddressBook";
@@ -1540,6 +1563,7 @@
 				F42E08690D199A5B00D5DDE0 /* Resources */,
 				F42E086A0D199A5B00D5DDE0 /* Sources */,
 				F42E086B0D199A5B00D5DDE0 /* Frameworks */,
+				F4E4297B10B753C600F28A35 /* ShellScript */,
 			);
 			buildRules = (
 			);
@@ -1749,20 +1773,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "# Run the unit tests in this test bundle.\n\"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"";
-		};
-		8BAA9A2B0F7AF44A00DF4F12 /* ShellScript */ = {
-			isa = PBXShellScriptBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			inputPaths = (
-			);
-			outputPaths = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "GTMXcodeNote() {\n  echo ${ThisScript}:${1}: note: GTM ${2}\n}\n\nGTMXcodeNote ${LINENO} \"Removing gcov data files from ${CONFIGURATION_TEMP_DIR}\"\n( cd \"${CONFIGURATION_TEMP_DIR}\" &&  find . -type f -name \"*.gcda\" -print0 | xargs -0 rm -f )\n\nxcodebuild -project \"GTM.xcodeproj\" -target \"UnitTest - UnitTesting\" -configuration \"${CONFIGURATION}\" OBJROOT=\"${OBJROOT}\" SYMROOT=\"${SYMROOT}\" CACHE_ROOT=\"${CACHE_ROOT}\" GTM_DO_NOT_REMOVE_GCOV_DATA=1\nxcodebuild -project \"GTM.xcodeproj\" -target \"UnitTest - Foundation\" -configuration \"${CONFIGURATION}\" OBJROOT=\"${OBJROOT}\" SYMROOT=\"${SYMROOT}\" CACHE_ROOT=\"${CACHE_ROOT}\" GTM_DO_NOT_REMOVE_GCOV_DATA=1\nxcodebuild -project \"GTM.xcodeproj\" -target \"UnitTest - AppKit\" -configuration \"${CONFIGURATION}\" OBJROOT=\"${OBJROOT}\" SYMROOT=\"${SYMROOT}\" CACHE_ROOT=\"${CACHE_ROOT}\" GTM_DO_NOT_REMOVE_GCOV_DATA=1\nxcodebuild -project \"GTM.xcodeproj\" -target \"UnitTest - AddressBook\" -configuration \"${CONFIGURATION}\" OBJROOT=\"${OBJROOT}\" SYMROOT=\"${SYMROOT}\" CACHE_ROOT=\"${CACHE_ROOT}\" GTM_DO_NOT_REMOVE_GCOV_DATA=1";
+			shellScript = "# Run the unit tests in this test bundle.\nGTM_REMOVE_TARGET_GCOV_ONLY=1 GTM_ONE_TEST_AT_A_TIME=1 \"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"";
 		};
 		8BFE13F10FB0F2D8001BE894 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
@@ -1775,7 +1786,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "# Run the unit tests in this test bundle.\n\"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"\n";
+			shellScript = "# Run the unit tests in this test bundle.\nGTM_REMOVE_TARGET_GCOV_ONLY=1 \"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"\n";
 		};
 		F42E081D0D19987200D5DDE0 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
@@ -1788,7 +1799,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "# Run the unit tests in this test bundle.\n\"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"";
+			shellScript = "# Run the unit tests in this test bundle.\nGTM_REMOVE_TARGET_GCOV_ONLY=1 \"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"";
 		};
 		F48FE2620D198C1E009257D2 /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
@@ -1801,7 +1812,20 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "# Run the unit tests in this test bundle.\n\"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"\n";
+			shellScript = "# Run the unit tests in this test bundle.\nGTM_REMOVE_TARGET_GCOV_ONLY=1 GTM_ONE_TEST_AT_A_TIME=1 \"${SRCROOT}/UnitTesting/RunMacOSUnitTests.sh\"\n";
+		};
+		F4E4297B10B753C600F28A35 /* ShellScript */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "# Every time we build, clean up the gcda files just incase someone is trying to look at coverage.\nGTM_GCOV_CLEANUP_DIR=\"${OBJECT_FILE_DIR}-${CURRENT_VARIANT}\"\nif [ \"${GTM_GCOV_CLEANUP_DIR}\" != \"-\" ]; then\n  if [ -d \"${GTM_GCOV_CLEANUP_DIR}\" ]; then\n    echo \"note: Removing gcov data files from ${GTM_GCOV_CLEANUP_DIR}\"\n    (cd \"${GTM_GCOV_CLEANUP_DIR}\" && \\\n      find . -type f -name \"*.gcda\" -print0 | xargs -0 rm -f )\n  fi\nfi\n";
 		};
 /* End PBXShellScriptBuildPhase section */
 
@@ -2026,11 +2050,6 @@
 			target = 8B45A2890DA49B99001148C5 /* UIUnitTestingHarness */;
 			targetProxy = 8BAA9A340F7AF50600DF4F12 /* PBXContainerItemProxy */;
 		};
-		8BFE13BD0FB0F2D8001BE894 /* PBXTargetDependency */ = {
-			isa = PBXTargetDependency;
-			target = 8B45A2890DA49B99001148C5 /* UIUnitTestingHarness */;
-			targetProxy = 8BFE13BE0FB0F2D8001BE894 /* PBXContainerItemProxy */;
-		};
 		8BFE13BF0FB0F2D8001BE894 /* PBXTargetDependency */ = {
 			isa = PBXTargetDependency;
 			target = F42E086C0D199A5B00D5DDE0 /* GTM */;
@@ -2046,6 +2065,26 @@
 			target = F42E086C0D199A5B00D5DDE0 /* GTM */;
 			targetProxy = F42E08780D199AA600D5DDE0 /* PBXContainerItemProxy */;
 		};
+		F4E4279210B7484B00F28A35 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			target = 8BFE13BC0FB0F2D8001BE894 /* UnitTest - AddressBook */;
+			targetProxy = F4E4279110B7484B00F28A35 /* PBXContainerItemProxy */;
+		};
+		F4E4279410B7484B00F28A35 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			target = F48FE2630D198C1E009257D2 /* UnitTest - AppKit */;
+			targetProxy = F4E4279310B7484B00F28A35 /* PBXContainerItemProxy */;
+		};
+		F4E4279610B7484B00F28A35 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			target = F42E08110D19987200D5DDE0 /* UnitTest - Foundation */;
+			targetProxy = F4E4279510B7484B00F28A35 /* PBXContainerItemProxy */;
+		};
+		F4E4279810B7484B00F28A35 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			target = 8B45A0270DA4696C001148C5 /* UnitTest - UnitTesting */;
+			targetProxy = F4E4279710B7484B00F28A35 /* PBXContainerItemProxy */;
+		};
 /* End PBXTargetDependency section */
 
 /* Begin PBXVariantGroup section */
diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt
index cc2a282..420c575 100644
--- a/ReleaseNotes.txt
+++ b/ReleaseNotes.txt
@@ -354,6 +354,12 @@
 - Added configurations GTMiPhone for all the new configs, updated the build
   scripts to build all iPhone SDKs also.
 
+- RunMacOSUnitTests supports GTM_REMOVE_TARGET_GCOV_ONLY to have only gcda
+  removed from the target and not the whole project.
+
+- RunMacOSUnitTests supports GTM_ONE_TEST_AT_A_TIME to have only one test
+  run at a time to support global state (color sync profile, etc.).
+
 
 Release 1.5.1
 Changes since 1.5.0
diff --git a/UnitTesting/RunMacOSUnitTests.sh b/UnitTesting/RunMacOSUnitTests.sh
index f2e12e9..34fd23a 100755
--- a/UnitTesting/RunMacOSUnitTests.sh
+++ b/UnitTesting/RunMacOSUnitTests.sh
@@ -22,7 +22,6 @@
 
 set -o errexit
 set -o nounset 
-set -o verbose
 
 # Controlling environment variables:
 #
@@ -56,6 +55,19 @@
 #   non-zero value.
 GTM_DO_NOT_REMOVE_GCOV_DATA=${GTM_DO_NOT_REMOVE_GCOV_DATA:=0}
 
+# GTM_REMOVE_TARGET_GCOV_ONLY
+#   By default all *.gcda files are removed form the project.  Setting this to
+#   1 causes only the *.gcda files for the target to be removed.
+#   If GTM_DO_NOT_REMOVE_GCOV_DATA is set, this has no effect.
+GTM_REMOVE_TARGET_GCOV_ONLY=${GTM_REMOVE_TARGET_GCOV_ONLY:=0}
+
+# GTM_ONE_TEST_AT_A_TIME
+#   By default your tests run how ever parallel your projects/targets are
+#   setup.  Setting this to 1 will cause only one to run at a time, this is
+#   useful if you are doing UI tests with the helper that controls the
+#   colorsync profile, or any other machine wide state.
+GTM_ONE_TEST_AT_A_TIME=${GTM_ONE_TEST_AT_A_TIME:=0}
+
 ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
 ScriptName=$(basename "$0")
 ThisScript="${ScriptDir}/${ScriptName}"
@@ -64,6 +76,19 @@
   echo ${ThisScript}:${1}: note: GTM ${2}
 }
 
+# Helper that works like the linux flock util, so you can run something, but
+# have only one run at a time.
+MaybeFlock() {
+  if [ $GTM_ONE_TEST_AT_A_TIME ]; then
+    python -c "import fcntl, subprocess, sys
+file = open('$TMPDIR/GTM_one_test_at_a_time', 'a')
+fcntl.flock(file.fileno(), fcntl.LOCK_EX)
+sys.exit(subprocess.call(sys.argv[1:]))" "${@}"
+  else
+    "${@}"
+  fi
+}
+
 # The workaround below is due to
 # Radar 6248062 otest won't run with MallocHistory enabled under rosetta
 # Basically we go through and check what architecture we are running on
@@ -177,14 +202,14 @@
   ARCHS="${LEAK_TEST_ARCHS}"
   VALID_ARCHS="${LEAK_TEST_ARCHS}"
   GTMXcodeNote ${LINENO} "Leak checking enabled for $ARCHS. Ignoring leaks from $GTM_LEAKS_SYMBOLS_TO_IGNORE."
-  "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
+  MaybeFlock "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
   
   # Running leaks on architectures that don't support leaks.
   unset MallocStackLogging
   GTM_ENABLE_LEAKS=0
   ARCHS="${NO_LEAK_TEST_ARCHS}"
   VALID_ARCHS="${NO_LEAK_TEST_ARCHS}"
-  "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
+  MaybeFlock "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
 }
 
 # Jack up some memory stress so we can catch more bugs.
@@ -209,10 +234,14 @@
 fi
 
 if [ ! $GTM_DO_NOT_REMOVE_GCOV_DATA ]; then
-  if [ "${CONFIGURATION_TEMP_DIR}" != "-" ]; then
-    if [ -d "${CONFIGURATION_TEMP_DIR}" ]; then
-      GTMXcodeNote ${LINENO} "Removing gcov data files from ${CONFIGURATION_TEMP_DIR}"
-      (cd "${CONFIGURATION_TEMP_DIR}" && \
+  GTM_GCOV_CLEANUP_DIR="${CONFIGURATION_TEMP_DIR}"
+  if [ $GTM_REMOVE_TARGET_GCOV_ONLY ]; then
+    GTM_GCOV_CLEANUP_DIR="${OBJECT_FILE_DIR}-${CURRENT_VARIANT}"
+  fi
+  if [ "${GTM_GCOV_CLEANUP_DIR}" != "-" ]; then
+    if [ -d "${GTM_GCOV_CLEANUP_DIR}" ]; then
+      GTMXcodeNote ${LINENO} "Removing gcov data files from ${GTM_GCOV_CLEANUP_DIR}"
+      (cd "${GTM_GCOV_CLEANUP_DIR}" && \
         find . -type f -name "*.gcda" -print0 | xargs -0 rm -f )
     fi
   fi
@@ -224,5 +253,5 @@
   RunTests  
 else
   GTMXcodeNote ${LINENO} "Leak checking disabled."
-  "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
+  MaybeFlock "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
 fi