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

Commit 72cabc62 authored by Colin Cross's avatar Colin Cross Committed by Oliver Nguyen
Browse files

Make native_coverage clause work with ClangCoverage

Make uses NATIVE_COVERAGE to enable gcov coverage and CLANG_COVERAGE
to enable clang coverage.  NATIVE_COVERAGE is translated to the Soong
Native_coverage product variable which triggers the native_coverage
clause in Android.bp files.  The clause also needs to be triggered
for CLANG_COVERAGE.

Rename the existing Native_coverage product variable to GcovCoverage,
and regenerate Native_coverage when either GcovCoverage or
ClangCoverage are set.

Also remove NativeLineCoverage, it wasn't doing anything differently
than Native_coverage.

Bug: 159059537
Test: m checkbuild
Merged-In: I215124a9b35a2ad50ad562079d392e3d33da11f4
Change-Id: I215124a9b35a2ad50ad562079d392e3d33da11f4
parent 583691a0
Loading
Loading
Loading
Loading
+15 −5
Original line number Original line Diff line number Diff line
@@ -406,6 +406,14 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
		return Config{}, err
		return Config{}, err
	}
	}


	if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) {
		return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set")
	}

	config.productVariables.Native_coverage = proptools.BoolPtr(
		Bool(config.productVariables.GcovCoverage) ||
			Bool(config.productVariables.ClangCoverage))

	return Config{config}, nil
	return Config{config}, nil
}
}


@@ -1058,18 +1066,20 @@ func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool {
	return coverage
	return coverage
}
}


func (c *config) NativeLineCoverage() bool {
// Returns true if gcov or clang coverage is enabled.
	return Bool(c.productVariables.NativeLineCoverage)
}

func (c *deviceConfig) NativeCoverageEnabled() bool {
func (c *deviceConfig) NativeCoverageEnabled() bool {
	return Bool(c.config.productVariables.Native_coverage) || Bool(c.config.productVariables.NativeLineCoverage)
	return Bool(c.config.productVariables.GcovCoverage) ||
		Bool(c.config.productVariables.ClangCoverage)
}
}


func (c *deviceConfig) ClangCoverageEnabled() bool {
func (c *deviceConfig) ClangCoverageEnabled() bool {
	return Bool(c.config.productVariables.ClangCoverage)
	return Bool(c.config.productVariables.ClangCoverage)
}
}


func (c *deviceConfig) GcovCoverageEnabled() bool {
	return Bool(c.config.productVariables.GcovCoverage)
}

// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native
// code coverage is enabled for path. By default, coverage is not enabled for a
// code coverage is enabled for path. By default, coverage is not enabled for a
// given path unless it is part of the NativeCoveragePaths product variable (and
// given path unless it is part of the NativeCoveragePaths product variable (and
+4 −2
Original line number Original line Diff line number Diff line
@@ -256,12 +256,14 @@ type productVariables struct {
	JavaCoveragePaths        []string `json:",omitempty"`
	JavaCoveragePaths        []string `json:",omitempty"`
	JavaCoverageExcludePaths []string `json:",omitempty"`
	JavaCoverageExcludePaths []string `json:",omitempty"`


	NativeLineCoverage         *bool    `json:",omitempty"`
	GcovCoverage               *bool    `json:",omitempty"`
	Native_coverage            *bool    `json:",omitempty"`
	ClangCoverage              *bool    `json:",omitempty"`
	ClangCoverage              *bool    `json:",omitempty"`
	NativeCoveragePaths        []string `json:",omitempty"`
	NativeCoveragePaths        []string `json:",omitempty"`
	NativeCoverageExcludePaths []string `json:",omitempty"`
	NativeCoverageExcludePaths []string `json:",omitempty"`


	// Set by NewConfig
	Native_coverage *bool

	DevicePrefer32BitApps        *bool `json:",omitempty"`
	DevicePrefer32BitApps        *bool `json:",omitempty"`
	DevicePrefer32BitExecutables *bool `json:",omitempty"`
	DevicePrefer32BitExecutables *bool `json:",omitempty"`
	HostPrefer32BitExecutables   *bool `json:",omitempty"`
	HostPrefer32BitExecutables   *bool `json:",omitempty"`
+1 −1
Original line number Original line Diff line number Diff line
@@ -1660,7 +1660,7 @@ func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizer
}
}


func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
	return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
	return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
}
}


func (a *apexBundle) PreventInstall() {
func (a *apexBundle) PreventInstall() {
+1 −0
Original line number Original line Diff line number Diff line
@@ -155,6 +155,7 @@ func TestVndkApexUsesVendorVariant(t *testing.T) {
				sdk_version: "current",
				sdk_version: "current",
			}
			}
		`, func(fs map[string][]byte, config android.Config) {
		`, func(fs map[string][]byte, config android.Config) {
			config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true)
			config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
			config.TestProductVariables.Native_coverage = proptools.BoolPtr(true)
		})
		})


+2 −2
Original line number Original line Diff line number Diff line
@@ -74,8 +74,8 @@ func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
}
}


func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
	gcovCoverage := ctx.DeviceConfig().NativeCoverageEnabled()
	clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()
	clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()
	gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled()


	if !gcovCoverage && !clangCoverage {
	if !gcovCoverage && !clangCoverage {
		return flags, deps
		return flags, deps
@@ -151,7 +151,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags


func (cov *coverage) begin(ctx BaseModuleContext) {
func (cov *coverage) begin(ctx BaseModuleContext) {
	// Coverage is disabled globally
	// Coverage is disabled globally
	if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() {
	if !ctx.DeviceConfig().NativeCoverageEnabled() {
		return
		return
	}
	}


Loading