From 278193669eee7a92187f8f70a738bcda1b9e298a Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 22 Jul 2024 21:03:50 +0100 Subject: Pass config files to metalava Adds a filegroup "metalava-config-files" whose contents are passed to Metalava using the `--config-file` option. Bug: 354699349 Test: m checkapi Change-Id: I1e246517c2ef678e41214c975aecee97f9faca67 --- java/java.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 3dae4e42b..b320732cd 100644 --- a/java/java.go +++ b/java/java.go @@ -269,7 +269,7 @@ type JavaInfo struct { ImplementationAndResourcesJars android.Paths // ImplementationJars is a list of jars that contain the implementations of classes in the - //module. + // module. ImplementationJars android.Paths // ResourceJars is a list of jars that contain the resources included in the module. @@ -2039,12 +2039,17 @@ type JavaApiLibraryProperties struct { // List of aconfig_declarations module names that the stubs generated in this module // depend on. Aconfig_declarations []string + + // List of hard coded filegroups containing Metalava config files that are passed to every + // Metalava invocation that this module performs. See addMetalavaConfigFilesToCmd. + ConfigFiles []string `android:"path" blueprint:"mutated"` } func ApiLibraryFactory() android.Module { module := &ApiLibrary{} - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) module.AddProperties(&module.properties) + module.properties.ConfigFiles = getMetalavaConfigFilegroupReference() + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) module.initModuleAndImport(module) android.InitDefaultableModule(module) return module @@ -2060,7 +2065,7 @@ func (al *ApiLibrary) StubsJar() android.Path { func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, homeDir android.WritablePath, - classpath android.Paths) *android.RuleBuilderCommand { + classpath android.Paths, configFiles android.Paths) *android.RuleBuilderCommand { rule.Command().Text("rm -rf").Flag(homeDir.String()) rule.Command().Text("mkdir -p").Flag(homeDir.String()) @@ -2099,6 +2104,8 @@ func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, FlagWithArg("--hide ", "InvalidNullabilityOverride"). FlagWithArg("--hide ", "ChangedDefault") + addMetalavaConfigFilesToCmd(cmd, configFiles) + if len(classpath) == 0 { // The main purpose of the `--api-class-resolution api` option is to force metalava to ignore // classes on the classpath when an API file contains missing classes. However, as this command @@ -2310,7 +2317,9 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName()) } - cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths) + configFiles := android.PathsForModuleSrc(ctx, al.properties.ConfigFiles) + + cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, systemModulesPaths, configFiles) al.stubsFlags(ctx, cmd, stubsDir) -- cgit v1.2.3-59-g8ed1b