Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d9287b6c authored by Sophie Zheng's avatar Sophie Zheng Committed by Gerrit Code Review
Browse files

Merge "Also generate api lists based on symbol files for cc_library rule during build time."

parents c5e452b2 4c4f8032
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -294,6 +294,9 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries
			if library.buildStubs() {
				entries.SetBool("LOCAL_NO_NOTICE_FILE", true)
			}
			if library.apiListCoverageXmlPath.String() != "" {
				entries.SetString("SOONG_CC_API_XML", "$(SOONG_CC_API_XML) "+library.apiListCoverageXmlPath.String())
			}
		})
	}
	// If a library providing a stub is included in an APEX, the private APIs of the library
+16 −0
Original line number Diff line number Diff line
@@ -244,3 +244,19 @@ func coverageMutator(mctx android.BottomUpMutatorContext) {
		m[1].(Coverage).EnableCoverageIfNeeded()
	}
}

func parseSymbolFileForAPICoverage(ctx ModuleContext, symbolFile string) android.ModuleOutPath {
	apiLevelsJson := android.GetApiLevelsJson(ctx)
	symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
	outputFile := ctx.baseModuleName() + ".xml"
	parsedApiCoveragePath := android.PathForModuleOut(ctx, outputFile)
	rule := android.NewRuleBuilder(pctx, ctx)
	rule.Command().
		BuiltTool("ndk_api_coverage_parser").
		Input(symbolFilePath).
		Output(parsedApiCoveragePath).
		Implicit(apiLevelsJson).
		FlagWithArg("--api-map ", apiLevelsJson.String())
	rule.Build("native_library_api_list", "Generate native API list based on symbol files for coverage measurement")
	return parsedApiCoveragePath
}
+8 −0
Original line number Diff line number Diff line
@@ -536,6 +536,8 @@ type libraryDecorator struct {
	*baseInstaller

	collectedSnapshotHeaders android.Paths

	apiListCoverageXmlPath android.ModuleOutPath
}

type ccLibraryBazelHandler struct {
@@ -951,6 +953,12 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
		objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
		library.versionScriptPath = android.OptionalPathForPath(
			nativeAbiResult.versionScript)

		// Parse symbol file to get API list for coverage
		if library.stubsVersion() == "current" && ctx.PrimaryArch() {
			library.apiListCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
		}

		return objs
	}

+1 −26
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import (

func init() {
	pctx.HostBinToolVariable("ndkStubGenerator", "ndkstubgen")
	pctx.HostBinToolVariable("ndk_api_coverage_parser", "ndk_api_coverage_parser")
	pctx.HostBinToolVariable("abidiff", "abidiff")
	pctx.HostBinToolVariable("abitidy", "abitidy")
	pctx.HostBinToolVariable("abidw", "abidw")
@@ -43,12 +42,6 @@ var (
			CommandDeps: []string{"$ndkStubGenerator"},
		}, "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")

	abidw = pctx.AndroidStaticRule("abidw",
		blueprint.RuleParams{
			Command: "$abidw --type-id-style hash --no-corpus-path " +
@@ -276,24 +269,6 @@ func compileStubLibrary(ctx ModuleContext, flags Flags, src android.Path) Object
		android.Paths{src}, nil, nil)
}

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,
		Implicits:   []android.Path{apiLevelsJson},
		Args: map[string]string{
			"apiMap": apiLevelsJson.String(),
		},
	})
	return parsedApiCoveragePath
}

func (this *stubDecorator) findImplementationLibrary(ctx ModuleContext) android.Path {
	dep := ctx.GetDirectDepWithTag(strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix),
		stubImplementation)
@@ -454,7 +429,7 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O
		}
	}
	if c.apiLevel.IsCurrent() && ctx.PrimaryArch() {
		c.parsedCoverageXmlPath = parseSymbolFileForCoverage(ctx, symbolFile)
		c.parsedCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
	}
	return objs
}