Pass --api-surface to Metalava
Uses the `api_surface` property and passes it down to Metalava. It will
use it to select the appropriate `<api-surface>` configuration in
`build/soong/java/metalava/main-config.xml`.
Bug: 391554590
Test: m checkapi
Change-Id: I5ec4e121239e6ecbc4dc1b2958a164f93bb8b437
diff --git a/java/droidstubs.go b/java/droidstubs.go
index e0c2e63..b13385b 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -710,7 +710,8 @@
}
func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
- srcJarList android.Path, homeDir android.WritablePath, params stubsCommandConfigParams, configFiles android.Paths) *android.RuleBuilderCommand {
+ srcJarList android.Path, homeDir android.WritablePath, params stubsCommandConfigParams,
+ configFiles android.Paths, apiSurface *string) *android.RuleBuilderCommand {
rule.Command().Text("rm -rf").Flag(homeDir.String())
rule.Command().Text("mkdir -p").Flag(homeDir.String())
@@ -756,6 +757,8 @@
addMetalavaConfigFilesToCmd(cmd, configFiles)
+ addOptionalApiSurfaceToCmd(cmd, apiSurface)
+
return cmd
}
@@ -774,6 +777,14 @@
cmd.FlagForEachInput("--config-file ", configFiles)
}
+// addOptionalApiSurfaceToCmd adds --api-surface option is apiSurface is not `nil`.
+func addOptionalApiSurfaceToCmd(cmd *android.RuleBuilderCommand, apiSurface *string) {
+ if apiSurface != nil {
+ cmd.Flag("--api-surface")
+ cmd.Flag(*apiSurface)
+ }
+}
+
// Pass flagged apis related flags to metalava. When aconfig_declarations property is not
// defined for a module, simply revert all flagged apis annotations. If aconfig_declarations
// property is defined, apply transformations and only revert the flagged apis that are not
@@ -848,7 +859,8 @@
configFiles := android.PathsForModuleSrc(ctx, d.properties.ConfigFiles)
- cmd := metalavaCmd(ctx, rule, d.Javadoc.srcFiles, srcJarList, homeDir, params.stubConfig, configFiles)
+ cmd := metalavaCmd(ctx, rule, d.Javadoc.srcFiles, srcJarList, homeDir, params.stubConfig,
+ configFiles, d.properties.Api_surface)
cmd.Implicits(d.Javadoc.implicits)
d.stubsFlags(ctx, cmd, params.stubsDir, params.stubConfig.stubsType, params.stubConfig.checkApi)
diff --git a/java/java.go b/java/java.go
index 70ebebe..83097a6 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2186,7 +2186,7 @@
func metalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
srcs android.Paths, homeDir android.WritablePath,
- classpath android.Paths, configFiles android.Paths) *android.RuleBuilderCommand {
+ classpath android.Paths, configFiles android.Paths, apiSurface *string) *android.RuleBuilderCommand {
rule.Command().Text("rm -rf").Flag(homeDir.String())
rule.Command().Text("mkdir -p").Flag(homeDir.String())
@@ -2227,6 +2227,8 @@
addMetalavaConfigFilesToCmd(cmd, configFiles)
+ addOptionalApiSurfaceToCmd(cmd, apiSurface)
+
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
@@ -2431,7 +2433,7 @@
combinedPaths := append(([]android.Path)(nil), systemModulesPaths...)
combinedPaths = append(combinedPaths, classPaths...)
combinedPaths = append(combinedPaths, bootclassPaths...)
- cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, combinedPaths, configFiles)
+ cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir, combinedPaths, configFiles, al.properties.Api_surface)
al.stubsFlags(ctx, cmd, stubsDir)