From 455b0bf92265057b28d816389d6cdadae005e158 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 8 Apr 2020 18:18:03 +0100 Subject: [PATCH] Allow droidstubs to not generate any stubs Needed to optimize the handling of the module_lib API surface which currently has to be generated with two separate droidstubs instances, one to generate the stubs and another to generate the .txt file. This allows the module generating the .txt file to avoid also wasting time generating stubs that are not used. This change: * Adds a generate_stubs property that defaults to true to allow the behavior to be customized on a per module basis. * Uses either the stubs srcjar or the api .txt file as the OutputFile for the AndroidMkEntries to ensure that they get written out properly. * Rearranges the code for generating stubs to make it easier to turn it off. Bug: 146727827 Bug: 153306490 Test: m droid Check output dir of framework-sdkextensions-api-module_libs_api to make sure it does not contain any sources or srcjars. Merged-In: Ib8025019f8a7a8cf5fa8765d76b5ad470af20006 Change-Id: Ib8025019f8a7a8cf5fa8765d76b5ad470af20006 --- java/androidmk.go | 15 +++++++++++++-- java/droiddoc.go | 48 +++++++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index d8a38842f..7d575253b 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -517,10 +517,21 @@ func (ddoc *Droiddoc) AndroidMkEntries() []android.AndroidMkEntries { } func (dstubs *Droidstubs) AndroidMkEntries() []android.AndroidMkEntries { + // If the stubsSrcJar is not generated (because generate_stubs is false) then + // use the api file as the output file to ensure the relevant phony targets + // are created in make if only the api txt file is being generated. This is + // needed because an invalid output file would prevent the make entries from + // being written. + // TODO(b/146727827): Revert when we do not need to generate stubs and API separately. + distFile := android.OptionalPathForPath(dstubs.apiFile) + outputFile := android.OptionalPathForPath(dstubs.stubsSrcJar) + if !outputFile.Valid() { + outputFile = distFile + } return []android.AndroidMkEntries{android.AndroidMkEntries{ Class: "JAVA_LIBRARIES", - DistFile: android.OptionalPathForPath(dstubs.apiFile), - OutputFile: android.OptionalPathForPath(dstubs.stubsSrcJar), + DistFile: distFile, + OutputFile: outputFile, Include: "$(BUILD_SYSTEM)/soong_droiddoc_prebuilt.mk", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(entries *android.AndroidMkEntries) { diff --git a/java/droiddoc.go b/java/droiddoc.go index b0efaa5bd..0947247b9 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -301,6 +301,11 @@ type DroidstubsProperties struct { // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false. Create_doc_stubs *bool + // if set to false then do not write out stubs. Defaults to true. + // + // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately. + Generate_stubs *bool + // is set to true, Metalava will allow framework SDK to contain API levels annotations. Api_levels_annotations_enabled *bool @@ -1285,7 +1290,7 @@ func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { } } -func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) { +func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) { if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || String(d.properties.Api_filename) != "" { @@ -1341,11 +1346,13 @@ func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuil cmd.FlagWithArg("--sdk-values ", d.metadataDir.String()) } - if Bool(d.properties.Create_doc_stubs) { - cmd.FlagWithArg("--doc-stubs ", stubsDir.String()) - } else { - cmd.FlagWithArg("--stubs ", stubsDir.String()) - cmd.Flag("--exclude-documentation-from-stubs") + if stubsDir.Valid() { + if Bool(d.properties.Create_doc_stubs) { + cmd.FlagWithArg("--doc-stubs ", stubsDir.String()) + } else { + cmd.FlagWithArg("--stubs ", stubsDir.String()) + cmd.Flag("--exclude-documentation-from-stubs") + } } } @@ -1502,15 +1509,18 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Create rule for metalava - d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") - srcJarDir := android.PathForModuleOut(ctx, "srcjars") - stubsDir := android.PathForModuleOut(ctx, "stubsDir") rule := android.NewRuleBuilder() - rule.Command().Text("rm -rf").Text(stubsDir.String()) - rule.Command().Text("mkdir -p").Text(stubsDir.String()) + generateStubs := BoolDefault(d.properties.Generate_stubs, true) + var stubsDir android.OptionalPath + if generateStubs { + d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") + stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir")) + rule.Command().Text("rm -rf").Text(stubsDir.String()) + rule.Command().Text("mkdir -p").Text(stubsDir.String()) + } srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) @@ -1536,13 +1546,15 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { cmd.ImplicitOutput(android.PathForModuleGen(ctx, o)) } - rule.Command(). - BuiltTool(ctx, "soong_zip"). - Flag("-write_if_changed"). - Flag("-jar"). - FlagWithOutput("-o ", d.Javadoc.stubsSrcJar). - FlagWithArg("-C ", stubsDir.String()). - FlagWithArg("-D ", stubsDir.String()) + if generateStubs { + rule.Command(). + BuiltTool(ctx, "soong_zip"). + Flag("-write_if_changed"). + Flag("-jar"). + FlagWithOutput("-o ", d.Javadoc.stubsSrcJar). + FlagWithArg("-C ", stubsDir.String()). + FlagWithArg("-D ", stubsDir.String()) + } if Bool(d.properties.Write_sdk_values) { d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")