Add a check that dependencies don't include conflicting explicit versions

When manually specifying #impl dependencies it can get difficult to
debug issues when both libfoo and libfoo#impl are in the dependencies.
Add a check that the list of shared libraries doesn't include two
of the same library with different explicit versions.

Bug: 372543712
Test: TestCheckConflictingExplicitVersions
Flag: EXEMPT host only
Change-Id: I6863999259ba10381c3bdb8d5ac817736ca4601a
diff --git a/cc/cc_test.go b/cc/cc_test.go
index e906706..22f7c9f 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -3321,3 +3321,20 @@
 		t.Errorf("expected %q in cflags, got %q", "-Xclang -verify", cFlags_cv)
 	}
 }
+
+func TestCheckConflictingExplicitVersions(t *testing.T) {
+	PrepareForIntegrationTestWithCc.
+		ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(
+			`shared_libs: duplicate shared libraries with different explicit versions: "libbar" and "libbar#impl"`,
+		)).
+		RunTestWithBp(t, `
+			cc_library {
+				name: "libfoo",
+				shared_libs: ["libbar", "libbar#impl"],
+			}
+
+			cc_library {
+				name: "libbar",
+			}
+		`)
+}