Revert "Fixes incorrect install names on darwin platforms" (#15450)

This reverts commit b06f49507e02384cb4ff1ff862da2a673e9a081f.

Also had to add a missing mnemonic function call parameter to `getDynamicLibrarySoname`. Copy-pasted the parameter from the other use of that function in the codebase.

Tested manually with a custom toolchain and there is also a test from the reverted code.

Fixes #15214

Closes #15261.

PiperOrigin-RevId: 446662219

Co-authored-by: Chris Clearwater <chris@clearwater.dev>
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
index d807f2e..330bcdc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
@@ -820,7 +820,10 @@
               getLinkType().linkerOrArchiver().equals(LinkerOrArchiver.LINKER),
               configuration.getBinDirectory(repositoryName).getExecPath(),
               output.getExecPathString(),
-              output.getRootRelativePath().getBaseName(),
+              SolibSymlinkAction.getDynamicLibrarySoname(
+                  output.getRootRelativePath(),
+                  /* preserveName= */ false,
+                  actionConstructionContext.getConfiguration().getMnemonic()),
               linkType.equals(LinkTargetType.DYNAMIC_LIBRARY),
               paramFile != null ? paramFile.getExecPathString() : null,
               thinltoParamFile != null ? thinltoParamFile.getExecPathString() : null,
diff --git a/src/test/shell/bazel/cpp_darwin_integration_test.sh b/src/test/shell/bazel/cpp_darwin_integration_test.sh
index 4676e6c..e26d2a9 100755
--- a/src/test/shell/bazel/cpp_darwin_integration_test.sh
+++ b/src/test/shell/bazel/cpp_darwin_integration_test.sh
@@ -124,59 +124,41 @@
 }
 
 function test_cc_test_with_explicit_install_name() {
-  mkdir -p cpp/install_name
-  cat > cpp/install_name/BUILD <<EOF
+  mkdir -p cpp
+  cat > cpp/BUILD <<EOF
 cc_library(
   name = "foo",
   srcs = ["foo.cc"],
-)
-cc_binary(
-  name = "libbar.so",
-  srcs = ["bar.cc"],
-  linkshared = 1,
-)
-cc_binary(
-  name = "libbaz.dylib",
-  srcs = ["baz.cc"],
-  linkshared = 1,
+  hdrs = ["foo.h"],
 )
 cc_test(
   name = "test",
-  srcs = ["test.cc", ":libbar.so", ":libbaz.dylib"],
+  srcs = ["test.cc"],
   deps = [":foo"],
 )
 EOF
-  cat > cpp/install_name/foo.cc <<EOF
-  int foo() { return 2; }
-EOF
-  cat > cpp/install_name/bar.cc <<EOF
-  int bar() { return 12; }
-EOF
-  cat > cpp/install_name/baz.cc <<EOF
-  int baz() { return 42; }
-EOF
-  cat > cpp/install_name/test.cc <<EOF
+  cat > cpp/foo.h <<EOF
   int foo();
-  int bar();
-  int baz();
+EOF
+  cat > cpp/foo.cc <<EOF
+  int foo() { return 0; }
+EOF
+  cat > cpp/test.cc <<EOF
+  #include "cpp/foo.h"
   int main() {
-    int result = foo() + bar() + baz();
-    if (result == 56) {
-      return 0;
-    } else {
-      return result;
-    }
+    return foo();
   }
 EOF
 
-  bazel test --incompatible_macos_set_install_name //cpp/install_name:test || \
-      fail "bazel test //cpp/install_name:test failed"
+  bazel test --incompatible_macos_set_install_name //cpp:test || \
+      fail "bazel test //cpp:test failed"
   # Ensure @rpath is correctly set in the binary.
-  ./bazel-bin/cpp/install_name/test || \
+  ./bazel-bin/cpp/test || \
       fail "//cpp:test workspace execution failed, expected return 0, got $?"
   cd bazel-bin
-  ./cpp/install_name/test || \
+  ./cpp/test || \
       fail "//cpp:test execution failed, expected 0, but $?"
 }
 
 run_suite "Tests for Bazel's C++ rules on Darwin"
+