diff options
| -rw-r--r-- | cc/cc.go | 26 | ||||
| -rw-r--r-- | cc/cc_test.go | 17 |
2 files changed, 43 insertions, 0 deletions
@@ -19,8 +19,10 @@ package cc // is handled in builder.go import ( + "errors" "fmt" "io" + "slices" "strconv" "strings" @@ -2291,6 +2293,10 @@ func (c *Module) deps(ctx DepsContext) Deps { deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs) deps.LlndkHeaderLibs = android.LastUniqueStrings(deps.LlndkHeaderLibs) + if err := checkConflictingExplicitVersions(deps.SharedLibs); err != nil { + ctx.PropertyErrorf("shared_libs", "%s", err.Error()) + } + for _, lib := range deps.ReexportSharedLibHeaders { if !inList(lib, deps.SharedLibs) { ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) @@ -2318,6 +2324,26 @@ func (c *Module) deps(ctx DepsContext) Deps { return deps } +func checkConflictingExplicitVersions(libs []string) error { + withoutVersion := func(s string) string { + name, _ := StubsLibNameAndVersion(s) + return name + } + var errs []error + for i, lib := range libs { + libName := withoutVersion(lib) + libsToCompare := libs[i+1:] + j := slices.IndexFunc(libsToCompare, func(s string) bool { + return withoutVersion(s) == libName + }) + if j >= 0 { + errs = append(errs, fmt.Errorf("duplicate shared libraries with different explicit versions: %q and %q", + lib, libsToCompare[j])) + } + } + return errors.Join(errs...) +} + func (c *Module) beginMutator(actx android.BottomUpMutatorContext) { ctx := &baseModuleContext{ BaseModuleContext: actx, diff --git a/cc/cc_test.go b/cc/cc_test.go index e90670672..22f7c9f35 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3321,3 +3321,20 @@ func TestClangVerify(t *testing.T) { 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", + } + `) +} |