Support using api-versions.xml from another module
Metalava has two different flags surrounding api-levels: - one for generating api-versions.xml to a file - one for applying api-versions.xml from a file Previously, soong always applied both of these arguments at the same time, such that framework-doc-stubs both generated and applied api-versions.xml. Add support for using api-versions.xml from another module name as well. Bug: 187398174 Test: droidstubs_test.go Change-Id: I8288fe4788336d5d5c60d09d48b00ca111449fba
This commit is contained in:
@@ -135,6 +135,9 @@ type DroidstubsProperties struct {
|
|||||||
// if set to true, Metalava will allow framework SDK to contain API levels annotations.
|
// if set to true, Metalava will allow framework SDK to contain API levels annotations.
|
||||||
Api_levels_annotations_enabled *bool
|
Api_levels_annotations_enabled *bool
|
||||||
|
|
||||||
|
// Apply the api levels database created by this module rather than generating one in this droidstubs.
|
||||||
|
Api_levels_module *string
|
||||||
|
|
||||||
// the dirs which Metalava extracts API levels annotations from.
|
// the dirs which Metalava extracts API levels annotations from.
|
||||||
Api_levels_annotations_dirs []string
|
Api_levels_annotations_dirs []string
|
||||||
|
|
||||||
@@ -234,6 +237,7 @@ func (d *Droidstubs) StubsSrcJar() android.Path {
|
|||||||
var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
|
var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
|
||||||
var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
|
var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
|
||||||
var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
|
var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
|
||||||
|
var metalavaAPILevelsModuleTag = dependencyTag{name: "metalava-api-levels-module-tag"}
|
||||||
|
|
||||||
func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
d.Javadoc.addDeps(ctx)
|
d.Javadoc.addDeps(ctx)
|
||||||
@@ -255,6 +259,10 @@ func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
|
ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.properties.Api_levels_module != nil {
|
||||||
|
ctx.AddDependency(ctx.Module(), metalavaAPILevelsModuleTag, proptools.String(d.properties.Api_levels_module))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
|
func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
|
||||||
@@ -365,21 +373,35 @@ func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *a
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
|
func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
|
||||||
if !Bool(d.properties.Api_levels_annotations_enabled) {
|
var apiVersions android.Path
|
||||||
return
|
if proptools.Bool(d.properties.Api_levels_annotations_enabled) {
|
||||||
|
d.apiLevelsGenerationFlags(ctx, cmd)
|
||||||
|
apiVersions = d.apiVersionsXml
|
||||||
|
} else {
|
||||||
|
ctx.VisitDirectDepsWithTag(metalavaAPILevelsModuleTag, func(m android.Module) {
|
||||||
|
if s, ok := m.(*Droidstubs); ok {
|
||||||
|
apiVersions = s.apiVersionsXml
|
||||||
|
} else {
|
||||||
|
ctx.PropertyErrorf("api_levels_module",
|
||||||
|
"module %q is not a droidstubs module", ctx.OtherModuleName(m))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if apiVersions != nil {
|
||||||
|
cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String())
|
||||||
|
cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
|
||||||
|
cmd.FlagWithInput("--apply-api-levels ", apiVersions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
d.apiVersionsXml = android.PathForModuleOut(ctx, "metalava", "api-versions.xml")
|
func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
|
||||||
|
|
||||||
if len(d.properties.Api_levels_annotations_dirs) == 0 {
|
if len(d.properties.Api_levels_annotations_dirs) == 0 {
|
||||||
ctx.PropertyErrorf("api_levels_annotations_dirs",
|
ctx.PropertyErrorf("api_levels_annotations_dirs",
|
||||||
"has to be non-empty if api levels annotations was enabled!")
|
"has to be non-empty if api levels annotations was enabled!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.apiVersionsXml = android.PathForModuleOut(ctx, "metalava", "api-versions.xml")
|
||||||
cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
|
cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
|
||||||
cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
|
|
||||||
cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String())
|
|
||||||
cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
|
|
||||||
|
|
||||||
filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar")
|
filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar")
|
||||||
|
|
||||||
|
@@ -46,6 +46,12 @@ func TestDroidstubs(t *testing.T) {
|
|||||||
api_levels_annotations_enabled: true,
|
api_levels_annotations_enabled: true,
|
||||||
api_levels_jar_filename: "android.other.jar",
|
api_levels_jar_filename: "android.other.jar",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
droidstubs {
|
||||||
|
name: "stubs-applying-api-versions",
|
||||||
|
srcs: ["bar-doc/a.java"],
|
||||||
|
api_levels_module: "bar-stubs-other",
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
map[string][]byte{
|
map[string][]byte{
|
||||||
"bar-doc/a.java": nil,
|
"bar-doc/a.java": nil,
|
||||||
@@ -53,26 +59,37 @@ func TestDroidstubs(t *testing.T) {
|
|||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
moduleName string
|
moduleName string
|
||||||
expectedJarFilename string
|
expectedJarFilename string
|
||||||
|
generate_xml bool
|
||||||
high_mem bool
|
high_mem bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
moduleName: "bar-stubs",
|
moduleName: "bar-stubs",
|
||||||
|
generate_xml: true,
|
||||||
expectedJarFilename: "android.jar",
|
expectedJarFilename: "android.jar",
|
||||||
high_mem: false,
|
high_mem: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
moduleName: "bar-stubs-other",
|
moduleName: "bar-stubs-other",
|
||||||
|
generate_xml: true,
|
||||||
expectedJarFilename: "android.other.jar",
|
expectedJarFilename: "android.other.jar",
|
||||||
high_mem: true,
|
high_mem: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
moduleName: "stubs-applying-api-versions",
|
||||||
|
generate_xml: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, c := range testcases {
|
for _, c := range testcases {
|
||||||
m := ctx.ModuleForTests(c.moduleName, "android_common")
|
m := ctx.ModuleForTests(c.moduleName, "android_common")
|
||||||
manifest := m.Output("metalava.sbox.textproto")
|
manifest := m.Output("metalava.sbox.textproto")
|
||||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, manifest)
|
sboxProto := android.RuleBuilderSboxProtoForTests(t, manifest)
|
||||||
expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename
|
cmdline := String(sboxProto.Commands[0].Command)
|
||||||
if actual := String(sboxProto.Commands[0].Command); !strings.Contains(actual, expected) {
|
android.AssertStringContainsEquals(t, "api-versions generation flag", cmdline, "--generate-api-levels", c.generate_xml)
|
||||||
t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, actual)
|
if c.expectedJarFilename != "" {
|
||||||
|
expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename
|
||||||
|
if !strings.Contains(cmdline, expected) {
|
||||||
|
t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, cmdline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metalava := m.Rule("metalava")
|
metalava := m.Rule("metalava")
|
||||||
|
Reference in New Issue
Block a user