Merge "NDK Api Coverage" am: 582bebf051

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1320013

Change-Id: Ifd3e96cdb196c0a899f107257e74195f0fb7f7ea
This commit is contained in:
Sophie Zheng 2020-06-11 18:35:51 +00:00 committed by Automerger Merge Worker
commit 6574db06ec
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_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())
}
})
}

View file

@ -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
}

View file

@ -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",
],
}