diff options
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/java/java.go b/java/java.go index 0d39a6a78..70aba8e2c 100644 --- a/java/java.go +++ b/java/java.go @@ -1683,6 +1683,9 @@ type JavaApiLibraryProperties struct { // extracting the compiled class files provided by the // full_api_surface_stub module. Full_api_surface_stub *string + + // Version of previously released API file for compatibility check. + Previous_api *string `android:"path"` } func ApiLibraryFactory() android.Module { @@ -1812,6 +1815,28 @@ 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, srcFiles android.Paths) android.Paths { + sortedSrcFiles := android.Paths{} + + 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,10 +1887,18 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { 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) + migratingNullability := String(al.properties.Previous_api) != "" + if migratingNullability { + previousApi := android.PathForModuleSrc(ctx, String(al.properties.Previous_api)) + cmd.FlagWithInput("--migrate-nullness ", previousApi) + } + al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar") al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, "metalava", "stubs.jar") al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName())) |