From 58cabb7af6a5e8c2fe8cee031f1669b442d0f3d1 Mon Sep 17 00:00:00 2001 From: sophiez Date: Fri, 29 May 2020 13:37:12 -0700 Subject: [PATCH] NDK Api Coverage Enable ndk_library processing for api code coverage. All parsed generated xml files will be dist and later upload to artifacts. Test: m ndk Change-Id: I76ac52f60d5bbb106308658cf7417b845af9a49e --- cc/androidmk.go | 3 +++ cc/ndk_library.go | 38 +++++++++++++++++++++++++++++++++++--- cc/scriptlib/Android.bp | 9 +++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/cc/androidmk.go b/cc/androidmk.go index 3ce1a8955..8f5ce38b3 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -457,6 +457,9 @@ func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android. entries.SetString("LOCAL_MODULE_PATH", path) entries.SetString("LOCAL_MODULE_STEM", stem) entries.SetBool("LOCAL_NO_NOTICE_FILE", true) + if c.parsedCoverageXmlPath.String() != "" { + entries.SetString("SOONG_NDK_API_XML", "$(SOONG_NDK_API_XML) "+c.parsedCoverageXmlPath.String()) + } }) } diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 3759329ee..d79badbc4 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -25,6 +25,10 @@ import ( "android/soong/android" ) +func init() { + pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser") +} + var ( toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/scriptlib/gen_stub_libs.py") @@ -35,6 +39,12 @@ var ( CommandDeps: []string{"$toolPath"}, }, "arch", "apiLevel", "apiMap", "flags") + parseNdkApiRule = pctx.AndroidStaticRule("parseNdkApiRule", + blueprint.RuleParams{ + Command: "$ndk_api_coverage_parser $in $out --api-map $apiMap", + CommandDeps: []string{"$ndk_api_coverage_parser"}, + }, "apiMap") + ndkLibrarySuffix = ".ndk" ndkPrebuiltSharedLibs = []string{ @@ -111,8 +121,9 @@ type stubDecorator struct { properties libraryProperties - versionScriptPath android.ModuleGenPath - installPath android.Path + versionScriptPath android.ModuleGenPath + parsedCoverageXmlPath android.ModuleOutPath + installPath android.Path } // OMG GO @@ -308,14 +319,35 @@ func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, ge return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil, nil), versionScriptPath } +func parseSymbolFileForCoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath { + apiLevelsJson := android.GetApiLevelsJson(ctx) + symbolFilePath := android.PathForModuleSrc(ctx, symbolFile) + outputFileName := strings.Split(symbolFilePath.Base(), ".")[0] + parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFileName+".xml") + ctx.Build(pctx, android.BuildParams{ + Rule: parseNdkApiRule, + Description: "parse ndk api symbol file for api coverage: " + symbolFilePath.Rel(), + Outputs: []android.WritablePath{parsedApiCoveragePath}, + Input: symbolFilePath, + Args: map[string]string{ + "apiMap": apiLevelsJson.String(), + }, + }) + return parsedApiCoveragePath +} + func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") { ctx.PropertyErrorf("symbol_file", "must end with .map.txt") } - objs, versionScript := compileStubLibrary(ctx, flags, String(c.properties.Symbol_file), + symbolFile := String(c.properties.Symbol_file) + objs, versionScript := compileStubLibrary(ctx, flags, symbolFile, c.properties.ApiLevel, "") c.versionScriptPath = versionScript + if c.properties.ApiLevel == "current" && ctx.PrimaryArch() { + c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile) + } return objs } diff --git a/cc/scriptlib/Android.bp b/cc/scriptlib/Android.bp index daebfe156..ff9a2f0f3 100644 --- a/cc/scriptlib/Android.bp +++ b/cc/scriptlib/Android.bp @@ -21,3 +21,12 @@ python_test_host { "test_ndk_api_coverage_parser.py", ], } + +python_binary_host { + name: "ndk_api_coverage_parser", + main: "ndk_api_coverage_parser.py", + srcs: [ + "gen_stub_libs.py", + "ndk_api_coverage_parser.py", + ], +}