Delete unused Apple tools

StdRedirect.dylib stopped being used in this commit https://github.com/bazelbuild/rules_apple/commit/79dbaba43d5f6e4b655c9196ec2b045b410917b5 when Xcode's simctl introduced the `--console-pty` flag. This requires this rules change https://github.com/bazelbuild/rules_apple/pull/1152 (which needs to be applied internally at google before landing this)

realpath stopped being used in this commit https://github.com/bazelbuild/rules_apple/commit/cf00aaff1f31bb3284760acd48b8a5aa19a9e1d8

Closes #13447.

PiperOrigin-RevId: 378191047
diff --git a/src/BUILD b/src/BUILD
index 6dc5894..a67fe37 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -55,42 +55,6 @@
     scope = ["@bazel_tools//tools/jdk:current_java_toolchain"],
 )
 
-# Create dummy tools so we can do select to prevent building iOS target on
-# Linux.
-OSX_DUMMY_TARGETS = [
-    "src/tools/xcode/realpath/realpath",
-    "src/tools/xcode/stdredirect/StdRedirect.dylib",
-]
-
-[
-    genrule(
-        name = "dummy_darwin_tool_" + name.replace("/", "_"),
-        srcs = [],
-        outs = ["dummy_darwin_tools/" + name],
-        cmd = "touch $@",
-    )
-    for name in OSX_DUMMY_TARGETS
-]
-
-filegroup(
-    name = "darwin_tools",
-    srcs = [
-        "//src/tools/xcode/realpath:realpath",
-        "//tools/osx:xcode_locator.m",
-    ] + select({
-        "//src/conditions:iphonesdk": ["//src/tools/xcode/stdredirect:StdRedirect.dylib"],
-        "//conditions:default": [":dummy_darwin_tool_src_tools_xcode_stdredirect_StdRedirect.dylib"],
-    }),
-)
-
-filegroup(
-    name = "dummy_darwin_tools",
-    srcs = [
-        "dummy_darwin_tool_" + name.replace("/", "_")
-        for name in OSX_DUMMY_TARGETS
-    ],
-)
-
 py_library(
     name = "create_embedded_tools_lib",
     srcs = ["create_embedded_tools_lib.py"],
@@ -144,11 +108,9 @@
                "//third_party/zlib:embedded_tools",
            ] + select({
                "//src/conditions:darwin": [
-                   ":darwin_tools",
+                   "//tools/osx:xcode_locator.m",
                ],
-               "//conditions:default": [
-                   ":dummy_darwin_tools",
-               ],
+               "//conditions:default": [],
            }) + select({
                "//src/conditions:windows": [
                    "//src/tools/launcher:launcher",
@@ -173,7 +135,7 @@
     # WARNING: Only adjust the number in `expect` if you are intentionally
     # adding or removing embedded tools. Know that the more embedded tools there
     # are in Bazel, the bigger the binary becomes and the slower Bazel starts.
-    expect = 470,
+    expect = 465,
     margin = 5,  # percentage
 )
 
@@ -493,9 +455,7 @@
         "//src/tools/workspacelog:srcs",
         "//src/tools/launcher:srcs",
         "//src/tools/starlark/java/com/google/devtools/starlark/common:srcs",
-        "//src/tools/xcode/realpath:srcs",
         "//src/tools/singlejar:srcs",
-        "//src/tools/xcode/stdredirect:srcs",
         "//src/tools/remote:srcs",
         "//tools/osx:srcs",
     ],
diff --git a/src/create_embedded_tools.py b/src/create_embedded_tools.py
index 8abdf92..7721e48 100644
--- a/src/create_embedded_tools.py
+++ b/src/create_embedded_tools.py
@@ -43,10 +43,8 @@
     ('*zipper', lambda x: 'tools/zip/zipper/zipper'),
     ('*src/objc_tools/*',
      lambda x: 'tools/objc/precomp_' + os.path.basename(x)),
-    ('*xcode*StdRedirect.dylib', lambda x: 'tools/objc/StdRedirect.dylib'),
     ('*xcode*make_hashed_objlist.py',
      lambda x: 'tools/objc/make_hashed_objlist.py'),
-    ('*xcode*realpath', lambda x: 'tools/objc/realpath'),
     ('*xcode*xcode-locator', lambda x: 'tools/objc/xcode-locator'),
     ('*src/tools/xcode/*', lambda x: 'tools/objc/' + os.path.basename(x)),
     # --experimental_sibling_repository_layout=false
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
index 46f1343..7e6b766 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
@@ -94,7 +94,6 @@
         ImmutableSet.of(
             "objc_dummy.mm",
             "gcov",
-            "realpath",
             "testrunner",
             "xcrunwrapper.sh",
             "mcov",
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index 9c3fff6..bde1651 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -90,7 +90,6 @@
     args = ["$(JAVABASE)"],
     data = [
         ":test-deps",
-        "//src/test/shell/bazel/apple:objc-deps",
         "@bazel_tools//tools/bash/runfiles",
     ],
     shard_count = 3,
diff --git a/src/test/shell/bazel/apple/BUILD b/src/test/shell/bazel/apple/BUILD
index b849407..c0a170f 100644
--- a/src/test/shell/bazel/apple/BUILD
+++ b/src/test/shell/bazel/apple/BUILD
@@ -16,15 +16,10 @@
     testonly = 1,
     srcs = select({
         ":darwin": [
-            "//src/tools/xcode/realpath",
-            "//src/tools/xcode/stdredirect:StdRedirect.dylib",
             "//tools/osx:xcode-locator",
         ],
         "//conditions:default": [],
     }),
-    visibility = [
-        "//src/test/shell/bazel:__pkg__",
-    ],
 )
 
 sh_test(
diff --git a/src/tools/xcode/realpath/BUILD b/src/tools/xcode/realpath/BUILD
deleted file mode 100644
index 256c89f..0000000
--- a/src/tools/xcode/realpath/BUILD
+++ /dev/null
@@ -1,17 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-# This target will only build on a Mac.
-genrule(
-    name = "realpath_genrule",
-    srcs = ["realpath.c"],
-    outs = ["realpath"],
-    cmd = "/usr/bin/xcrun --sdk macosx clang -mmacosx-version-min=10.9 -o $@ $<",
-    output_to_bindir = 1,
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "srcs",
-    srcs = glob(["**"]),
-    visibility = ["//src:__pkg__"],
-)
diff --git a/src/tools/xcode/realpath/README b/src/tools/xcode/realpath/README
deleted file mode 100644
index 66ab179..0000000
--- a/src/tools/xcode/realpath/README
+++ /dev/null
@@ -1,14 +0,0 @@
-realpath is a simple implementation of the realpath utility:
-http://www.gnu.org/software/coreutils/manual/html_node/realpath-invocation.html
-since Mac OS X does not have anything equivalent.
-
-This version takes no options.
-
-This is based on the default GNU/Linux implementation that allows the last
-component to not exist. This is different than the Debian implementation that
-requires the last component to exist. Supporting the GNU/Linux implementation
-makes writing scripts that depend on realpath much easier, and is probably
-closer to what Apple may actually ship as a realpath implementation in the
-future.
-
-realpath only builds/runs on Darwin.
diff --git a/src/tools/xcode/realpath/realpath.c b/src/tools/xcode/realpath/realpath.c
deleted file mode 100644
index 6459774..0000000
--- a/src/tools/xcode/realpath/realpath.c
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//
-//  realpath.c
-//
-//  A simple implementation of realpath for Mac OS X.
-//  This implementation follows gnu/linux conventions and allows the last
-//  component to not exist:
-//  http://www.gnu.org/software/coreutils/manual/html_node/realpath-invocation.html
-//  Debian requires all components to exist.
-//
-
-#include <errno.h>
-#include <libgen.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-// Print a simple error message and exit.
-static void PrintError(const char *argv[]) {
-  fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
-  exit(1);
-}
-
-// Concatenate two paths together adding a '/' if appropriate.
-// Returned pointer is owned by client and should be freed.
-static char *JoinPaths(const char *path1, const char* path2) {
-  size_t len1 = strlen(path1);
-  size_t len2 = strlen(path2);
-  // +1 for '/' and +1 for '\0'
-  size_t totalSize = len1 + 1 + len2 + 1;
-  char *outPath = malloc(totalSize);
-  if (outPath == NULL) {
-    return NULL;
-  }
-  strlcpy(outPath, path1, totalSize);
-  if (len1 > 0 && len2 > 0) {
-    if (path1[len1 - 1] != '/' && path2[0] != '/') {
-      strlcat(outPath, "/", totalSize);
-    }
-  }
-  strlcat(outPath, path2, totalSize);
-  return outPath;
-}
-
-// Since this is a simple utility that quits immediately, we are not worrying
-// about making the code more complex by freeing up any memory allocations.
-int main(int argc, const char *argv[]) {
-  if (argc != 2) {
-    fprintf(stderr, "realpath <path>\n");
-    return 1;
-  }
-  const char *path = argv[1];
-  char *goodPath = realpath(path, NULL);
-  if (goodPath == NULL) {
-    if ((errno != ENOENT) || (strlen(path) == 0)) {
-      PrintError(argv);
-    }
-
-    // If only the last element is missing, then call realpath on the parent
-    // dir and append the basename back onto it.
-
-    // Technically the strdup is not required on Mac OS X, but this
-    // keeps things compatible with other basename/dirname implementations
-    // that do require a string they can modify.
-    char *dirCopy = strdup(path);
-    char *baseCopy = strdup(path);
-    if (dirCopy == NULL || baseCopy == NULL) {
-      PrintError(argv);
-    }
-    char *dir = dirname(dirCopy);
-    if (dir == NULL) {
-      PrintError(argv);
-    }
-    char *base = basename(baseCopy);
-    if (base == NULL) {
-      PrintError(argv);
-    }
-    char *realdir = realpath(dir, NULL);
-    if (realdir == NULL) {
-      PrintError(argv);
-    }
-    goodPath = JoinPaths(realdir, base);
-    if (goodPath == NULL) {
-      PrintError(argv);
-    }
-  }
-  fprintf(stdout, "%s\n", goodPath);
-  return 0;
-}
diff --git a/src/tools/xcode/stdredirect/BUILD b/src/tools/xcode/stdredirect/BUILD
deleted file mode 100644
index 1bffb6c..0000000
--- a/src/tools/xcode/stdredirect/BUILD
+++ /dev/null
@@ -1,21 +0,0 @@
-package(default_visibility = ["//src:__subpackages__"])
-
-# This target will only build on a Mac.
-# Does adhoc codesigning (codesign -s -) which is sufficient to allow it to
-# be used by the Xcode 8 build system.
-genrule(
-    name = "stdredirect_genrule",
-    srcs = ["StdRedirect.c"],
-    outs = ["StdRedirect.dylib"],
-    cmd = "/usr/bin/xcrun clang -arch i386 -arch x86_64 -mios-simulator-version-min=7.0 -dynamiclib " +
-          "  -isysroot \"$$(/usr/bin/xcrun --sdk iphonesimulator --show-sdk-path)\" " +
-          "  -o $@ $<; /usr/bin/xcrun codesign -s - $@",
-    output_to_bindir = 1,
-    visibility = ["//visibility:public"],
-)
-
-filegroup(
-    name = "srcs",
-    srcs = glob(["**"]),
-    visibility = ["//src:__pkg__"],
-)
diff --git a/src/tools/xcode/stdredirect/README b/src/tools/xcode/stdredirect/README
deleted file mode 100644
index 684e64f..0000000
--- a/src/tools/xcode/stdredirect/README
+++ /dev/null
@@ -1,3 +0,0 @@
-StdRedirect is a library that we DYLD_INSERT when running applications on the simulator so that we can redirect stdout and stderr.
-
-StdRedirect only builds/runs on Darwin.
diff --git a/src/tools/xcode/stdredirect/StdRedirect.c b/src/tools/xcode/stdredirect/StdRedirect.c
deleted file mode 100644
index 894e185..0000000
--- a/src/tools/xcode/stdredirect/StdRedirect.c
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2015 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//    http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//
-//  StdRedirect.c
-//
-//  Used for controlling stdin, stdout, stderr of iOS Applications launched in the simulator
-//  using simctl. stdin, stdout, and stderr are set using environment variables.
-//
-//  To use:
-//
-//  export GSTDIN="PATH_TO_STD_IN"
-//  export GSTDOUT="PATH_TO_STD_OUT"
-//  export GSTDERR="PATH_TO_STD_ERR"
-//  PLATFORM_PATH="$($(xcrun --sdk iphonesimulator --show-sdk-platform-path)"
-//  export SIMCTL_CHILD_DYLD_FALLBACK_FRAMEWORK_PATH="$PLATFORM_PATH/Developer/Library/Frameworks"
-//  export SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="$PLATFORM_PATH/Developer/Library/PrivateFrameworks" \
-//      "/IDEBundleInjection.framework/IDEBundleInjection:<Full path to StdRedirect.dylib>"
-//  export SIMCTL_CHILD_XCInjectBundle="Full path to your *.xctest Bundle"
-//  export SIMCTL_CHILD_XCInjectBundleInto="Full path to your app binary inside of " \
-//      "~/Library/Developer/CoreSimulator/Devices"
-//  <Launch the simulator in some fashion>
-//  xcrun simctl launch booted <device> <app binary bundle ID> -XCTest All
-
-//  Note that all of GSTDIN/GSTDOUT/GSTDERR are optional. Xcode dumps test results to GSTDERR.
-
-//  For a practical example of using it see run_tests.sh
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-// Using __assert_rtn to log asserts because it has the side benefit of
-// putting data in the CrashReport logs which would be useful.
-// __assert_rtn is a somewhat "private" api.
-// Since we are going to "assert" anyway, we ignore leaks from asprintf.
-static void SetUpStdFileDescriptor(const char *env_name, int file_no) {
-  const char *path = getenv(env_name);
-  if (path) {
-    int fd = open(path, O_RDWR | O_CREAT | O_APPEND);
-    if (fd == -1) {
-      char *crash_log_message;
-      asprintf(&crash_log_message, "Could not open %s for %s - %s",
-               env_name, path, strerror(errno));
-      __assert_rtn(__func__, __FILE__, __LINE__, crash_log_message);
-    } else {
-      if (fchmod(fd, 0666) == -1) {
-        char *crash_log_message;
-        asprintf(&crash_log_message, "Could not chmod %s for %s - %s",
-                 env_name, path, strerror(errno));
-        __assert_rtn(__func__, __FILE__, __LINE__, crash_log_message);
-      }
-      if (dup2(fd, file_no) == -1) {
-        char *crash_log_message;
-        asprintf(&crash_log_message, "Could not dup %s for %s - %s",
-                 env_name, path, strerror(errno));
-        __assert_rtn(__func__, __FILE__, __LINE__, crash_log_message);
-      }
-    }
-  }
-}
-
-__attribute__((constructor)) static void SetUpStdFileDescriptors() {
-  // Set up Error first with the hope that if out/in fail, that at least
-  // we will get errors logged.
-  SetUpStdFileDescriptor("GSTDERR", STDERR_FILENO);
-  SetUpStdFileDescriptor("GSTDOUT", STDOUT_FILENO);
-  SetUpStdFileDescriptor("GSTDIN", STDIN_FILENO);
-}
diff --git a/src/tools/xcode/stdredirect/run_tests.sh b/src/tools/xcode/stdredirect/run_tests.sh
deleted file mode 100755
index 2c5f492..0000000
--- a/src/tools/xcode/stdredirect/run_tests.sh
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/sh
-
-# Copyright 2015 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Runs a series of unit tests for an app bundle.
-# This is an example script to show how to use the StdRedirect library.
-
-# $1 path to app bundle
-# $2 path to xctest bundle
-# $3 path to stderr
-# $4 path to StdRedirect.dylib
-
-set -e
-
-if [ $# -ne 4 ]; then
-  echo "Usage RunTests <app bundle path> <xctest bundle path> <stderr path> <redirect library path>"
-  exit 1
-fi
-
-SIMULATOR_RUNNING=$(osascript -e "tell application \"System Events\" to (name of processes) contains \"iOS Simulator\"")
-
-TEST_DEVICE_ID=$(xcrun simctl create TestDevice com.apple.CoreSimulator.SimDeviceType.iPhone-6 com.apple.CoreSimulator.SimRuntime.iOS-8-3)
-
-# Instruments will return an error because we are calling it without a template arg.
-# It's the only way I know of to launch the simulator safely using xcrun.
-# This will launch the simulator with a given device. If the simulator is already running
-# it will switch to the given device.
-# Radar 21392428 xcrun should allow me to specify "iOS Simulator" in some manner
-xcrun instruments -w $TEST_DEVICE_ID &>/dev/null || true
-
-xcrun simctl install $TEST_DEVICE_ID $1
-
-PLATFORM_PATH="$(xcrun --sdk iphonesimulator --show-sdk-platform-path)"
-export SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="$PLATFORM_PATH/Developer/Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection:$4"
-export SIMCTL_CHILD_GSTDERR="$3"
-export SIMCTL_CHILD_XCInjectBundle="$2"
-BUNDLE_BASE=$(basename $1)
-BUNDLE_INFO_PLIST="$1/Info.plist"
-EXECUTABLE_NAME=$(xcrun PlistBuddy -c "Print :CFBundleExecutable" "$BUNDLE_INFO_PLIST")
-BUNDLE_ID=$(xcrun PlistBuddy -c "Print :CFBundleIdentifier" "$BUNDLE_INFO_PLIST")
-
-# The "*" is unfortunate, but there is no way to get back the UUID of the installed application.
-# Since we created the simulator from scratch, there should only be one app installed on it.
-# Radar 21392479 simctl install should return the UUID of the installed app.
-# Radar 21392325 simctl getenv never appears to function
-export SIMCTL_CHILD_XCInjectBundleInto="$HOME/Library/Developer/CoreSimulator/Devices/$TEST_DEVICE_ID/data/Containers/Bundle/Application/*/$BUNDLE_BASE/$EXECUTABLE_NAME"
-export SIMCTL_CHILD_DYLD_FALLBACK_FRAMEWORK_PATH="$PLATFORM_PATH/Developer/Library/Frameworks"
-IOS_PID=$(xcrun simctl launch $TEST_DEVICE_ID "$BUNDLE_ID" -XCTest All)
-IOS_PID=$(echo $IOS_PID | awk '{ print $2 }')
-
-# The simulator is not a subprocess of the script, so we cannot wait on it and must poll instead.
-while kill -0 "$IOS_PID" &>/dev/null; do
-  sleep 0.5
-done
-
-# If the simulator wasn't running when we started, then we should clean it up.
-if [ "${SIMULATOR_RUNNING}" = false ]; then
-  osascript -e "tell application \"iOS Simulator\" to quit"
-fi
-
-# Radar 21392585 simctl delete should allows me to delete multiple devices in one call
-xcrun simctl delete $TEST_DEVICE_ID