From a262c0590420b99e4b768f377c8eabd1778b1dd0 Mon Sep 17 00:00:00 2001 From: Pete Gillin Date: Fri, 14 Sep 2018 14:25:48 +0100 Subject: [PATCH] Add support for nullability validation to droidstubs. This detects whether this is enabled, makes sure the other necessary flag is set to provide a suitable location, and suppresses the requirement for a previous_api. Test: making a new libcore target using this Bug: 73448108 Change-Id: Ifea3a060011a58e3288050c6c5d98b205abe25fc --- java/droiddoc.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/java/droiddoc.go b/java/droiddoc.go index fca5fc463..23614ec67 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -1390,15 +1390,23 @@ func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string { var flags string if Bool(d.properties.Annotations_enabled) { - if String(d.properties.Previous_api) == "" { - ctx.PropertyErrorf("metalava_previous_api", - "has to be non-empty if annotations was enabled!") + flags += " --include-annotations" + validatingNullability := strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") + migratingNullability := String(d.properties.Previous_api) != "" + if !(migratingNullability || validatingNullability) { + ctx.PropertyErrorf("previous_api", + "has to be non-empty if annotations was enabled (unless validating nullability)") + } + if migratingNullability { + previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api") + *implicits = append(*implicits, previousApi) + flags += " --migrate-nullness " + previousApi.String() + } + if validatingNullability { + nullabilityWarningsTxt := android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt") + *implicitOutputs = append(*implicitOutputs, nullabilityWarningsTxt) + flags += " --nullability-warnings-txt " + nullabilityWarningsTxt.String() } - previousApi := ctx.ExpandSource(String(d.properties.Previous_api), - "metalava_previous_api") - *implicits = append(*implicits, previousApi) - - flags += " --include-annotations --migrate-nullness " + previousApi.String() d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip") *implicitOutputs = append(*implicitOutputs, d.annotationsZip)