[ObjC] Move the version check out into a sh_test.

Since the sources can't reference each other, this is what helps keep them in
sync. Move it out to be a stand alone test in bazel instead of having it wired
into the Xcode projects.

PiperOrigin-RevId: 508429454
diff --git a/objectivec/BUILD.bazel b/objectivec/BUILD.bazel
index a6258d8..612667c 100644
--- a/objectivec/BUILD.bazel
+++ b/objectivec/BUILD.bazel
@@ -101,6 +101,18 @@
     testee = "//conformance:conformance_objc",
 )
 
+# -------------------------------------------------------------------
+# Current Version Check between Generator and Runtime Sources
+sh_test(
+    name = "check_version_stamps",
+    size = "small",
+    srcs = ["DevTools/check_version_stamps.sh"],
+    data = [
+        "GPBBootstrap.h",
+        "//src/google/protobuf/compiler/objectivec:file.cc",
+    ],
+)
+
 ################################################################################
 # Distribution files
 ################################################################################
diff --git a/objectivec/DevTools/check_version_stamps.sh b/objectivec/DevTools/check_version_stamps.sh
index 5972e35..8b6d496 100755
--- a/objectivec/DevTools/check_version_stamps.sh
+++ b/objectivec/DevTools/check_version_stamps.sh
@@ -3,21 +3,24 @@
 # This script checks that the runtime version number constant in the compiler
 # source and in the runtime source is the same.
 #
-# A distro can be made of the protobuf sources with only a subset of the
-# languages, so if the compiler depended on the Objective C runtime, those
-# builds would break. At the same time, we don't want the runtime source
-# depending on the compiler sources; so two copies of the constant are needed.
-
-readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
-readonly ProtoRootDir="${ScriptDir}/../.."
+# We don't really want the generator sources directly referencing the runtime
+# or the reverse, so they both have the same constant defined, and this script
+# is used in a test to ensure the values stay in sync.
 
 die() {
     echo "Error: $1"
     exit 1
 }
 
-readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/file.cc"
-readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
+readonly GeneratorSrc="src/google/protobuf/compiler/objectivec/file.cc"
+readonly RuntimeSrc="objectivec/GPBBootstrap.h"
+
+if [[ ! -e "${GeneratorSrc}" ]] ; then
+  die "Failed to find generator file: ${GeneratorSrc}"
+fi
+if [[ ! -e "${RuntimeSrc}" ]] ; then
+  die "Failed to find runtime file: ${RuntimeSrc}"
+fi
 
 check_constant() {
   local ConstantName="$1"
diff --git a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
index f2c1df6..0970108 100644
--- a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
@@ -610,7 +610,6 @@
 			isa = PBXNativeTarget;
 			buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
 			buildPhases = (
-				F4B62A781AF91F6000AFCEDC /* Script: Check Runtime Stamps */,
 				8BBEA4A1147C727100C4ADB7 /* Resources */,
 				8BBEA4A2147C727100C4ADB7 /* Sources */,
 				8BBEA4A3147C727100C4ADB7 /* Frameworks */,
@@ -697,25 +696,6 @@
 		};
 /* End PBXResourcesBuildPhase section */
 
-/* Begin PBXShellScriptBuildPhase section */
-		F4B62A781AF91F6000AFCEDC /* Script: Check Runtime Stamps */ = {
-			isa = PBXShellScriptBuildPhase;
-			alwaysOutOfDate = 1;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			inputPaths = (
-			);
-			name = "Script: Check Runtime Stamps";
-			outputPaths = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
-			showEnvVarsInLog = 0;
-		};
-/* End PBXShellScriptBuildPhase section */
-
 /* Begin PBXSourcesBuildPhase section */
 		7461B52B0F94FAF800A0C422 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
diff --git a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
index 1874b5c..80d13fd 100644
--- a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
@@ -617,7 +617,6 @@
 			isa = PBXNativeTarget;
 			buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
 			buildPhases = (
-				F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */,
 				8BBEA4A1147C727100C4ADB7 /* Resources */,
 				8BBEA4A2147C727100C4ADB7 /* Sources */,
 				8BBEA4A3147C727100C4ADB7 /* Frameworks */,
@@ -704,25 +703,6 @@
 		};
 /* End PBXResourcesBuildPhase section */
 
-/* Begin PBXShellScriptBuildPhase section */
-		F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */ = {
-			isa = PBXShellScriptBuildPhase;
-			alwaysOutOfDate = 1;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			inputPaths = (
-			);
-			name = "Script: Check Runtime Stamps";
-			outputPaths = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
-			showEnvVarsInLog = 0;
-		};
-/* End PBXShellScriptBuildPhase section */
-
 /* Begin PBXSourcesBuildPhase section */
 		7461B52B0F94FAF800A0C422 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
diff --git a/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj
index 71fcdd1..01de877 100644
--- a/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj
@@ -617,7 +617,6 @@
 			isa = PBXNativeTarget;
 			buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
 			buildPhases = (
-				F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */,
 				8BBEA4A1147C727100C4ADB7 /* Resources */,
 				8BBEA4A2147C727100C4ADB7 /* Sources */,
 				8BBEA4A3147C727100C4ADB7 /* Frameworks */,
@@ -704,25 +703,6 @@
 		};
 /* End PBXResourcesBuildPhase section */
 
-/* Begin PBXShellScriptBuildPhase section */
-		F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */ = {
-			isa = PBXShellScriptBuildPhase;
-			alwaysOutOfDate = 1;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			inputPaths = (
-			);
-			name = "Script: Check Runtime Stamps";
-			outputPaths = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
-			showEnvVarsInLog = 0;
-		};
-/* End PBXShellScriptBuildPhase section */
-
 /* Begin PBXSourcesBuildPhase section */
 		7461B52B0F94FAF800A0C422 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
diff --git a/src/google/protobuf/compiler/objectivec/BUILD.bazel b/src/google/protobuf/compiler/objectivec/BUILD.bazel
index a776793..c3a3aff 100644
--- a/src/google/protobuf/compiler/objectivec/BUILD.bazel
+++ b/src/google/protobuf/compiler/objectivec/BUILD.bazel
@@ -133,6 +133,13 @@
     ],
 )
 
+# Exposed only for the version check to ensure the ObjC Runtime and Generator
+# are in sync.
+exports_files(
+    ["file.cc"],
+    visibility = ["//objectivec:__pkg__"],
+)
+
 ################################################################################
 # Distribution packaging
 ################################################################################