From f7bae9ab3ebb3c22c3499c07a25cd18e3a99dbef Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Wed, 6 Sep 2023 22:07:15 +0000 Subject: [PATCH] Fix bp2build's stub/impl selection logic for platform variants For a dependency edge A --> B (stublib), Soong will link A's platform variant against impl of B's platform variant if either of these are true 1. A and B have same apex_available 2. B has bootstrap: true 3. B is only available to platform (3) was missing from bp2build. This CL adds that. To implement this, we check the `apex_available` property of B. Test: updated bp2build tests Test: Built the internal module b/299191635 that was failing due to this Bug: 299191635 Change-Id: Iafb173a3ab20d69b89f7949ce40c6f4096396f24 --- bp2build/cc_library_conversion_test.go | 5 ----- bp2build/cc_library_shared_conversion_test.go | 2 +- cc/bp2build.go | 5 +++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 246f1693e..9bb171330 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -2867,7 +2867,6 @@ cc_library { ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{ "implementation_dynamic_deps": `select({ "//build/bazel/rules/apex:foo": ["@api_surfaces//module-libapi/current:barlib"], - "//build/bazel/rules/apex:system": ["@api_surfaces//module-libapi/current:barlib"], "//conditions:default": [":barlib"], })`, "local_includes": `["."]`, @@ -2925,10 +2924,6 @@ cc_library { "@api_surfaces//module-libapi/current:barlib", "@api_surfaces//module-libapi/current:quxlib", ], - "//build/bazel/rules/apex:system": [ - "@api_surfaces//module-libapi/current:barlib", - "@api_surfaces//module-libapi/current:quxlib", - ], "//conditions:default": [ ":barlib", ":quxlib", diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index 90b13b03f..44b97227e 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -661,7 +661,7 @@ cc_library_shared { ":libapexfoo_stable", ], "//build/bazel/rules/apex:system": [ - "@api_surfaces//module-libapi/current:libplatform_stable", + ":libplatform_stable", "@api_surfaces//module-libapi/current:libapexfoo_stable", ], "//conditions:default": [ diff --git a/cc/bp2build.go b/cc/bp2build.go index 83553c8c2..62416f79d 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -1624,6 +1624,11 @@ func setStubsForDynamicDeps(ctx android.BazelConversionPathContext, axis bazel.C if linkable, ok := ctx.Module().(LinkableInterface); ok && linkable.Bootstrap() { sameApiDomain = true } + // If dependency has `apex_available: ["//apex_available:platform]`, then the platform variant of rdep should link against its impl. + // https://cs.android.com/android/_/android/platform/build/soong/+/main:cc/cc.go;l=3617;bpv=1;bpt=0;drc=c6a93d853b37ec90786e745b8d282145e6d3b589 + if depApexAvailable := dep.(*Module).ApexAvailable(); len(depApexAvailable) == 1 && depApexAvailable[0] == android.AvailableToPlatform { + sameApiDomain = true + } } else { sameApiDomain = android.InList(apiDomain, dep.(*Module).ApexAvailable()) }