summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
author Jihoon Kang <jihoonkang@google.com> 2023-09-20 23:43:32 +0000
committer Jihoon Kang <jihoonkang@google.com> 2023-09-22 16:55:43 +0000
commita96a7b1e13f04c79831347acc02bedc62cfd954e (patch)
tree89e50313e6c5c4eb2078aa42f79320e9fb0ea113 /java/java.go
parent6be0f00671e39a8b744a10bd1d0c91dc8724d4b2 (diff)
Remove naming conventioned based file sorting in java_api_library
With api_files property being removed from java_api_library, all api files are passed to java_api_library via java_api_contribution, which provide api_surface information. Instead of relying on the naming convention of the api files, java_api_library can utilize this information to sort the api files from narrower api scope to the wider api scope. Test: m --build-from-text-stub Bug: 295429988 Change-Id: Idd832778833c072c6b7e9d1f775533e5f4e2af00
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go41
1 files changed, 18 insertions, 23 deletions
diff --git a/java/java.go b/java/java.go
index aba4faac0..7e2366433 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1814,31 +1814,22 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
}
}
-// API signature file names sorted from
-// the narrowest api scope to the widest api scope
-var scopeOrderedSourceFileNames = allApiScopes.Strings(
- func(s *apiScope) string { return s.apiFilePrefix + "current.txt" })
-
-func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo) android.Paths {
- var sortedSrcFiles android.Paths
-
- for i, apiScope := range allApiScopes {
- for _, srcFileInfo := range srcFilesInfo {
- if srcFileInfo.ApiFile.Base() == scopeOrderedSourceFileNames[i] || srcFileInfo.ApiSurface == apiScope.name {
- sortedSrcFiles = append(sortedSrcFiles, android.PathForSource(ctx, srcFileInfo.ApiFile.String()))
- }
- }
- }
-
- if len(srcFilesInfo) != len(sortedSrcFiles) {
- var srcFiles android.Paths
- for _, srcFileInfo := range srcFilesInfo {
- srcFiles = append(srcFiles, srcFileInfo.ApiFile)
+// Map where key is the api scope name and value is the int value
+// representing the order of the api scope, narrowest to the widest
+var scopeOrderMap = allApiScopes.MapToIndex(
+ func(s *apiScope) string { return s.name })
+
+func (al *ApiLibrary) sortApiFilesByApiScope(ctx android.ModuleContext, srcFilesInfo []JavaApiImportInfo) []JavaApiImportInfo {
+ for _, srcFileInfo := range srcFilesInfo {
+ if srcFileInfo.ApiSurface == "" {
+ ctx.ModuleErrorf("Api surface not defined for the associated api file %s", srcFileInfo.ApiFile)
}
- ctx.ModuleErrorf("Unrecognizable source file found within %s", srcFiles)
}
+ sort.Slice(srcFilesInfo, func(i, j int) bool {
+ return scopeOrderMap[srcFilesInfo[i].ApiSurface] < scopeOrderMap[srcFilesInfo[j].ApiSurface]
+ })
- return sortedSrcFiles
+ return srcFilesInfo
}
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -1881,7 +1872,11 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
})
- srcFiles := al.sortApiFilesByApiScope(ctx, srcFilesInfo)
+ srcFilesInfo = al.sortApiFilesByApiScope(ctx, srcFilesInfo)
+ var srcFiles android.Paths
+ for _, srcFileInfo := range srcFilesInfo {
+ srcFiles = append(srcFiles, android.PathForSource(ctx, srcFileInfo.ApiFile.String()))
+ }
if srcFiles == nil && !ctx.Config().AllowMissingDependencies() {
ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName())