Sort api files by api scope in java_api_library
Recent changes in metalava (aosp/2704325) enforces api files passed as
inputs to generate stubs from txt to be sorted in the order from the
narrower api scope to the wider api scope. In order to comply with this
change, all api files passed as inputs to metalava invocations need to
be sorted in the respective order.
Test: m out/soong/.intermediates/packages/modules/IPsec/tests/cts/CtsIkeTestCases/android_common/e10894d3da5db41239526c9048962355/javac/CtsIkeTestCases.jar --build-from-text-stub --skip-soong-tests (Failing module from incorrect class hierarchy when building from text stub)
Bug: 295429988
Change-Id: I1eb1f4bf8fa34fd7dc8a0e4c04aa056258a975c5
diff --git a/java/java.go b/java/java.go
index 0d39a6a..988a074 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1812,6 +1812,28 @@
}
}
+func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFiles android.Paths) android.Paths {
+ sortedSrcFiles := android.Paths{}
+
+ // API signature file name sorted from
+ // the narrowest api scope to the widest api scope
+ scopeOrderedSourceFileNames := allApiScopes.Strings(
+ func(s *apiScope) string { return s.apiFilePrefix + "current.txt" })
+
+ for _, scopeSourceFileName := range scopeOrderedSourceFileNames {
+ for _, sourceFileName := range srcFiles {
+ if sourceFileName.Base() == scopeSourceFileName {
+ sortedSrcFiles = append(sortedSrcFiles, sourceFileName)
+ }
+ }
+ }
+ if len(srcFiles) != len(sortedSrcFiles) {
+ ctx.ModuleErrorf("Unrecognizable source file found within %s", srcFiles)
+ }
+
+ return sortedSrcFiles
+}
+
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
rule := android.NewRuleBuilder(pctx, ctx)
@@ -1862,6 +1884,8 @@
ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())
}
+ srcFiles = al.sortApiFilesByApiScope(ctx, srcFiles)
+
cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir)
al.stubsFlags(ctx, cmd, stubsDir)