From 0b09ad7f349bbf62bca57c6cdbeadc073ddbcae0 Mon Sep 17 00:00:00 2001 From: Jerome Gaillard Date: Thu, 10 Oct 2019 19:29:11 +0100 Subject: [PATCH] Update droidstubs build target This allows to use Metalava to generate metadata files useful for Android Studio as part of a droidstubs target. Once those files have been created in a new metadata folder, they are zipped to make it easier to transfer them into the out/target/common/obj/PACKAGING folder where they can then be picked up by the SDK build to be included there. Bug: 142480924 Test: m sdk Change-Id: I4be1c9e78369c65ee9cd94706c6d20ab0df6b797 Merged-In: I4be1c9e78369c65ee9cd94706c6d20ab0df6b797 --- java/androidmk.go | 3 +++ java/droiddoc.go | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index 7a939e849..43b9f4883 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -508,6 +508,9 @@ func (dstubs *Droidstubs) AndroidMk() android.AndroidMkData { if dstubs.jdiffDocZip != nil { fmt.Fprintln(w, "LOCAL_DROIDDOC_JDIFF_DOC_ZIP := ", dstubs.jdiffDocZip.String()) } + if dstubs.metadataZip != nil { + fmt.Fprintln(w, "LOCAL_DROIDDOC_METADATA_ZIP := ", dstubs.metadataZip.String()) + } if dstubs.checkCurrentApiTimestamp != nil { fmt.Fprintln(w, ".PHONY:", dstubs.Name()+"-check-current-api") fmt.Fprintln(w, dstubs.Name()+"-check-current-api:", diff --git a/java/droiddoc.go b/java/droiddoc.go index 6bac5bb7d..f56cae826 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -77,6 +77,8 @@ var ( `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` + `$opts && ` + `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` + + `(if $writeSdkValues; then ${config.SoongZipCmd} -write_if_changed -d -o $metadataZip ` + + `-C $metadataDir -D $metadataDir; fi) && ` + `rm -rf "$srcJarDir"`, CommandDeps: []string{ "${config.ZipSyncCmd}", @@ -89,7 +91,7 @@ var ( Restat: true, }, "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs", - "classpathArgs", "sourcepathArgs", "opts") + "classpathArgs", "sourcepathArgs", "opts", "writeSdkValues", "metadataZip", "metadataDir") metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck", blueprint.RuleParams{ @@ -1257,6 +1259,9 @@ type Droidstubs struct { jdiffDocZip android.WritablePath jdiffStubsSrcJar android.WritablePath + + metadataZip android.WritablePath + metadataDir android.WritablePath } func DroidstubsFactory() android.Module { @@ -1391,7 +1396,8 @@ func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext, } if Bool(d.properties.Write_sdk_values) { - metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String() + d.metadataDir = android.PathForModuleOut(ctx, "metadata") + metalavaFlags = metalavaFlags + " --sdk-values " + d.metadataDir.String() } if Bool(d.properties.Create_doc_stubs) { @@ -1543,6 +1549,19 @@ func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits andr implicitOutputs android.WritablePaths, javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) { + var writeSdkValues, metadataZip, metadataDir string + if Bool(d.properties.Write_sdk_values) { + writeSdkValues = "true" + d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip") + metadataZip = d.metadataZip.String() + metadataDir = d.metadataDir.String() + implicitOutputs = append(implicitOutputs, d.metadataZip) + } else { + writeSdkValues = "false" + metadataZip = "" + metadataDir = "" + } + ctx.Build(pctx, android.BuildParams{ Rule: metalava, Description: "Metalava", @@ -1560,6 +1579,9 @@ func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits andr "classpathArgs": classpathArgs, "sourcepathArgs": sourcepathArgs, "opts": opts, + "writeSdkValues": writeSdkValues, + "metadataZip": metadataZip, + "metadataDir": metadataDir, }, }) }