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
This commit is contained in:
sophiez
2020-05-29 13:37:12 -07:00
committed by Sophie Zheng
parent b858c6d497
commit 58cabb7af6
3 changed files with 47 additions and 3 deletions

View File

@@ -457,6 +457,9 @@ func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.
entries.SetString("LOCAL_MODULE_PATH", path) entries.SetString("LOCAL_MODULE_PATH", path)
entries.SetString("LOCAL_MODULE_STEM", stem) entries.SetString("LOCAL_MODULE_STEM", stem)
entries.SetBool("LOCAL_NO_NOTICE_FILE", true) entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
if c.parsedCoverageXmlPath.String() != "" {
entries.SetString("SOONG_NDK_API_XML", "$(SOONG_NDK_API_XML) "+c.parsedCoverageXmlPath.String())
}
}) })
} }

View File

@@ -25,6 +25,10 @@ import (
"android/soong/android" "android/soong/android"
) )
func init() {
pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser")
}
var ( var (
toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/scriptlib/gen_stub_libs.py") toolPath = pctx.SourcePathVariable("toolPath", "build/soong/cc/scriptlib/gen_stub_libs.py")
@@ -35,6 +39,12 @@ var (
CommandDeps: []string{"$toolPath"}, CommandDeps: []string{"$toolPath"},
}, "arch", "apiLevel", "apiMap", "flags") }, "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" ndkLibrarySuffix = ".ndk"
ndkPrebuiltSharedLibs = []string{ ndkPrebuiltSharedLibs = []string{
@@ -111,8 +121,9 @@ type stubDecorator struct {
properties libraryProperties properties libraryProperties
versionScriptPath android.ModuleGenPath versionScriptPath android.ModuleGenPath
installPath android.Path parsedCoverageXmlPath android.ModuleOutPath
installPath android.Path
} }
// OMG GO // 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 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 { func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") { if !strings.HasSuffix(String(c.properties.Symbol_file), ".map.txt") {
ctx.PropertyErrorf("symbol_file", "must end with .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.properties.ApiLevel, "")
c.versionScriptPath = versionScript c.versionScriptPath = versionScript
if c.properties.ApiLevel == "current" && ctx.PrimaryArch() {
c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile)
}
return objs return objs
} }

View File

@@ -21,3 +21,12 @@ python_test_host {
"test_ndk_api_coverage_parser.py", "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",
],
}