Merge "Support passing multiple last api files to metalava in droidstubs" into main am: 40639d7d7a

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2955008

Change-Id: I2da9624da8a671bce9d10a9fa8d46958b4db17ce
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2024-04-19 20:20:18 +00:00
committed by Automerger Merge Worker
3 changed files with 43 additions and 26 deletions

View File

@@ -532,8 +532,8 @@ func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.Ru
cmd.Flag(config.MetalavaAnnotationsFlags) cmd.Flag(config.MetalavaAnnotationsFlags)
if params.migratingNullability { if params.migratingNullability {
previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api)) previousApiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Previous_api)})
cmd.FlagWithInput("--migrate-nullness ", previousApi) cmd.FlagForEachInput("--migrate-nullness ", previousApiFiles)
} }
if s := String(d.properties.Validate_nullability_from_list); s != "" { if s := String(d.properties.Validate_nullability_from_list); s != "" {
@@ -692,11 +692,11 @@ func (d *Droidstubs) apiCompatibilityFlags(ctx android.ModuleContext, cmd *andro
ctx.PropertyErrorf("out", "out property may not be combined with check_api") ctx.PropertyErrorf("out", "out property may not be combined with check_api")
} }
apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file)) apiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Check_api.Last_released.Api_file)})
removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file)) removedApiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Check_api.Last_released.Removed_api_file)})
cmd.FlagWithInput("--check-compatibility:api:released ", apiFile) cmd.FlagForEachInput("--check-compatibility:api:released ", apiFiles)
cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile) cmd.FlagForEachInput("--check-compatibility:removed:released ", removedApiFiles)
baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file) baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
if baselineFile.Valid() { if baselineFile.Valid() {
@@ -950,9 +950,12 @@ func (d *Droidstubs) everythingOptionalCmd(ctx android.ModuleContext, cmd *andro
// Add API lint options. // Add API lint options.
if doApiLint { if doApiLint {
newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since) var newSince android.Paths
if newSince.Valid() { if d.properties.Check_api.Api_lint.New_since != nil {
cmd.FlagWithInput("--api-lint ", newSince.Path()) newSince = android.PathsForModuleSrc(ctx, []string{proptools.String(d.properties.Check_api.Api_lint.New_since)})
}
if len(newSince) > 0 {
cmd.FlagForEachInput("--api-lint ", newSince)
} else { } else {
cmd.Flag("--api-lint") cmd.Flag("--api-lint")
} }

View File

@@ -367,10 +367,23 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) {
info := latest[k] info := latest[k]
name := PrebuiltApiCombinedModuleName(info.module, info.scope, "latest") name := PrebuiltApiCombinedModuleName(info.module, info.scope, "latest")
// Iterate until the currentApiScope does not extend any other api scopes
// i.e. is not a superset of any other api scopes
// the relationship between the api scopes is defined in java/sdk_library.go
var srcs []string var srcs []string
currentApiScope := scopeByName[info.scope] currentApiScope := scopeByName[info.scope]
for currentApiScope != nil {
if _, ok := latest[fmt.Sprintf("%s.%s", info.module, currentApiScope.name)]; ok {
srcs = append(srcs, PrebuiltApiModuleName(info.module, currentApiScope.name, "latest")) srcs = append(srcs, PrebuiltApiModuleName(info.module, currentApiScope.name, "latest"))
}
currentApiScope = currentApiScope.extends
}
// srcs is currently listed in the order from the widest api scope to the narrowest api scopes
// e.g. module lib -> system -> public
// In order to pass the files in metalava from the narrowest api scope to the widest api scope,
// the list has to be reversed.
android.ReverseSliceInPlace(srcs)
createCombinedApiFilegroupModule(mctx, name, srcs) createCombinedApiFilegroupModule(mctx, name, srcs)
} }
} }

View File

@@ -705,10 +705,10 @@ type scopePaths struct {
annotationsZip android.OptionalPath annotationsZip android.OptionalPath
// The path to the latest API file. // The path to the latest API file.
latestApiPath android.OptionalPath latestApiPaths android.Paths
// The path to the latest removed API file. // The path to the latest removed API file.
latestRemovedApiPath android.OptionalPath latestRemovedApiPaths android.Paths
} }
func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
@@ -829,28 +829,25 @@ func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx an
}) })
} }
func extractSingleOptionalOutputPath(dep android.Module) (android.OptionalPath, error) { func extractOutputPaths(dep android.Module) (android.Paths, error) {
var paths android.Paths var paths android.Paths
if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok {
paths = sourceFileProducer.Srcs() paths = sourceFileProducer.Srcs()
return paths, nil
} else { } else {
return android.OptionalPath{}, fmt.Errorf("module %q does not produce source files", dep) return nil, fmt.Errorf("module %q does not produce source files", dep)
} }
if len(paths) != 1 {
return android.OptionalPath{}, fmt.Errorf("expected one path from %q, got %q", dep, paths)
}
return android.OptionalPathForPath(paths[0]), nil
} }
func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error {
outputPath, err := extractSingleOptionalOutputPath(dep) outputPaths, err := extractOutputPaths(dep)
paths.latestApiPath = outputPath paths.latestApiPaths = outputPaths
return err return err
} }
func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error {
outputPath, err := extractSingleOptionalOutputPath(dep) outputPaths, err := extractOutputPaths(dep)
paths.latestRemovedApiPath = outputPath paths.latestRemovedApiPaths = outputPaths
return err return err
} }
@@ -1625,11 +1622,15 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
scopes[scope.name] = scopeInfo scopes[scope.name] = scopeInfo
scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName)
scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName)
if p := scopePaths.latestApiPath; p.Valid() { if p := scopePaths.latestApiPaths; len(p) > 0 {
scopeInfo["latest_api"] = p.Path().String() // The last path in the list is the one that applies to this scope, the
// preceding ones, if any, are for the scope(s) that it extends.
scopeInfo["latest_api"] = p[len(p)-1].String()
} }
if p := scopePaths.latestRemovedApiPath; p.Valid() { if p := scopePaths.latestRemovedApiPaths; len(p) > 0 {
scopeInfo["latest_removed_api"] = p.Path().String() // The last path in the list is the one that applies to this scope, the
// preceding ones, if any, are for the scope(s) that it extends.
scopeInfo["latest_removed_api"] = p[len(p)-1].String()
} }
} }
android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo})