diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-07-07 01:09:15 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-07-07 01:09:15 +0000 |
commit | 033c2910d1231577df7e60230af976ef68deedb9 (patch) | |
tree | 581243623a1ae03b16c0d2c3938d45339e5a9c79 | |
parent | dc03d8e8f234235bb6e7bd4fce164a790eba8262 (diff) | |
parent | 1b7fc95d68e1a82a0119686fd3a6e311f84960a1 (diff) | |
download | build_soong-033c2910d1231577df7e60230af976ef68deedb9.tar.gz build_soong-033c2910d1231577df7e60230af976ef68deedb9.tar.bz2 build_soong-033c2910d1231577df7e60230af976ef68deedb9.zip |
Snap for 6657150 from 1b7fc95d68e1a82a0119686fd3a6e311f84960a1 to rvc-release
Change-Id: I74d908f313ea9b8837e9a6a6aad1bce8ac3ffccc
-rw-r--r-- | android/config.go | 52 | ||||
-rw-r--r-- | android/rule_builder.go | 22 | ||||
-rw-r--r-- | android/variable.go | 15 | ||||
-rw-r--r-- | apex/apex.go | 2 | ||||
-rw-r--r-- | apex/vndk_test.go | 1 | ||||
-rw-r--r-- | cc/coverage.go | 6 | ||||
-rwxr-xr-x | java/app.go | 2 | ||||
-rw-r--r-- | java/droiddoc.go | 65 | ||||
-rw-r--r-- | java/java.go | 4 |
9 files changed, 120 insertions, 49 deletions
diff --git a/android/config.go b/android/config.go index 350893ba..b6ef2684 100644 --- a/android/config.go +++ b/android/config.go @@ -406,6 +406,14 @@ func NewConfig(srcDir, buildDir string) (Config, error) { 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 } @@ -1037,27 +1045,55 @@ func (c *deviceConfig) SamplingPGO() bool { return Bool(c.config.productVariables.SamplingPGO) } -func (c *config) NativeLineCoverage() bool { - return Bool(c.productVariables.NativeLineCoverage) +// JavaCoverageEnabledForPath returns whether Java code coverage is enabled for +// path. Coverage is enabled by default when the product variable +// JavaCoveragePaths is empty. If JavaCoveragePaths is not empty, coverage is +// enabled for any path which is part of this variable (and not part of the +// JavaCoverageExcludePaths product variable). Value "*" in JavaCoveragePaths +// represents any path. +func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { + coverage := false + if c.config.productVariables.JavaCoveragePaths == nil || + InList("*", c.config.productVariables.JavaCoveragePaths) || + HasAnyPrefix(path, c.config.productVariables.JavaCoveragePaths) { + coverage = true + } + if coverage && c.config.productVariables.JavaCoverageExcludePaths != nil { + if HasAnyPrefix(path, c.config.productVariables.JavaCoverageExcludePaths) { + coverage = false + } + } + return coverage } +// Returns true if gcov or clang coverage is enabled. 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 { return Bool(c.config.productVariables.ClangCoverage) } -func (c *deviceConfig) CoverageEnabledForPath(path string) bool { +func (c *deviceConfig) GcovCoverageEnabled() bool { + return Bool(c.config.productVariables.GcovCoverage) +} + +// NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native +// 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 +// not part of the NativeCoverageExcludePaths product variable). Value "*" in +// NativeCoveragePaths represents any path. +func (c *deviceConfig) NativeCoverageEnabledForPath(path string) bool { coverage := false - if c.config.productVariables.CoveragePaths != nil { - if InList("*", c.config.productVariables.CoveragePaths) || HasAnyPrefix(path, c.config.productVariables.CoveragePaths) { + if c.config.productVariables.NativeCoveragePaths != nil { + if InList("*", c.config.productVariables.NativeCoveragePaths) || HasAnyPrefix(path, c.config.productVariables.NativeCoveragePaths) { coverage = true } } - if coverage && c.config.productVariables.CoverageExcludePaths != nil { - if HasAnyPrefix(path, c.config.productVariables.CoverageExcludePaths) { + if coverage && c.config.productVariables.NativeCoverageExcludePaths != nil { + if HasAnyPrefix(path, c.config.productVariables.NativeCoverageExcludePaths) { coverage = false } } diff --git a/android/rule_builder.go b/android/rule_builder.go index 6226548b..afb5f4e4 100644 --- a/android/rule_builder.go +++ b/android/rule_builder.go @@ -172,7 +172,7 @@ func (r *RuleBuilder) Inputs() Paths { inputs := make(map[string]Path) for _, c := range r.commands { - for _, input := range c.inputs { + for _, input := range append(c.inputs, c.implicits...) { inputStr := input.String() if _, isOutput := outputs[inputStr]; !isOutput { if _, isDepFile := depFiles[inputStr]; !isDepFile { @@ -480,6 +480,7 @@ func (r *RuleBuilder) Build(pctx PackageContext, ctx BuilderContext, name string type RuleBuilderCommand struct { buf strings.Builder inputs Paths + implicits Paths orderOnlys Paths outputs WritablePaths depFiles WritablePaths @@ -503,6 +504,16 @@ func (c *RuleBuilderCommand) addInput(path Path) string { return path.String() } +func (c *RuleBuilderCommand) addImplicit(path Path) string { + if c.sbox { + if rel, isRel, _ := maybeRelErr(c.sboxOutDir.String(), path.String()); isRel { + return "__SBOX_OUT_DIR__/" + rel + } + } + c.implicits = append(c.implicits, path) + return path.String() +} + func (c *RuleBuilderCommand) addOrderOnly(path Path) { c.orderOnlys = append(c.orderOnlys, path) } @@ -623,7 +634,7 @@ func (c *RuleBuilderCommand) Inputs(paths Paths) *RuleBuilderCommand { // Implicit adds the specified input path to the dependencies returned by RuleBuilder.Inputs without modifying the // command line. func (c *RuleBuilderCommand) Implicit(path Path) *RuleBuilderCommand { - c.addInput(path) + c.addImplicit(path) return c } @@ -631,11 +642,16 @@ func (c *RuleBuilderCommand) Implicit(path Path) *RuleBuilderCommand { // command line. func (c *RuleBuilderCommand) Implicits(paths Paths) *RuleBuilderCommand { for _, path := range paths { - c.addInput(path) + c.addImplicit(path) } return c } +// GetImplicits returns the command's implicit inputs. +func (c *RuleBuilderCommand) GetImplicits() Paths { + return c.implicits +} + // OrderOnly adds the specified input path to the dependencies returned by RuleBuilder.OrderOnlys // without modifying the command line. func (c *RuleBuilderCommand) OrderOnly(path Path) *RuleBuilderCommand { diff --git a/android/variable.go b/android/variable.go index 4da33259..983c2356 100644 --- a/android/variable.go +++ b/android/variable.go @@ -253,11 +253,16 @@ type productVariables struct { SamplingPGO *bool `json:",omitempty"` - NativeLineCoverage *bool `json:",omitempty"` - Native_coverage *bool `json:",omitempty"` - ClangCoverage *bool `json:",omitempty"` - CoveragePaths []string `json:",omitempty"` - CoverageExcludePaths []string `json:",omitempty"` + JavaCoveragePaths []string `json:",omitempty"` + JavaCoverageExcludePaths []string `json:",omitempty"` + + GcovCoverage *bool `json:",omitempty"` + ClangCoverage *bool `json:",omitempty"` + NativeCoveragePaths []string `json:",omitempty"` + NativeCoverageExcludePaths []string `json:",omitempty"` + + // Set by NewConfig + Native_coverage *bool DevicePrefer32BitApps *bool `json:",omitempty"` DevicePrefer32BitExecutables *bool `json:",omitempty"` diff --git a/apex/apex.go b/apex/apex.go index a63a8d60..f9c9b87f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1660,7 +1660,7 @@ func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizer } 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() { diff --git a/apex/vndk_test.go b/apex/vndk_test.go index 523ac263..8557faee 100644 --- a/apex/vndk_test.go +++ b/apex/vndk_test.go @@ -155,6 +155,7 @@ func TestVndkApexUsesVendorVariant(t *testing.T) { sdk_version: "current", } `, func(fs map[string][]byte, config android.Config) { + config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true) config.TestProductVariables.Native_coverage = proptools.BoolPtr(true) }) diff --git a/cc/coverage.go b/cc/coverage.go index bde07fd6..4431757d 100644 --- a/cc/coverage.go +++ b/cc/coverage.go @@ -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) { - gcovCoverage := ctx.DeviceConfig().NativeCoverageEnabled() clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled() + gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled() if !gcovCoverage && !clangCoverage { return flags, deps @@ -151,7 +151,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags func (cov *coverage) begin(ctx BaseModuleContext) { // Coverage is disabled globally - if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() { + if !ctx.DeviceConfig().NativeCoverageEnabled() { return } @@ -175,7 +175,7 @@ func (cov *coverage) begin(ctx BaseModuleContext) { if needCoverageVariant { // Coverage variant is actually built with coverage if enabled for its module path - needCoverageBuild = ctx.DeviceConfig().CoverageEnabledForPath(ctx.ModuleDir()) + needCoverageBuild = ctx.DeviceConfig().NativeCoverageEnabledForPath(ctx.ModuleDir()) } } diff --git a/java/app.go b/java/app.go index 3f12e91c..a0b208f7 100755 --- a/java/app.go +++ b/java/app.go @@ -952,7 +952,7 @@ func (a *AndroidApp) Privileged() bool { } func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { - return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled()) + return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } func (a *AndroidApp) PreventInstall() { diff --git a/java/droiddoc.go b/java/droiddoc.go index 355904d6..230b1f02 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -121,6 +121,10 @@ type JavadocProperties struct { // names of the output files used in args that will be generated Out []string + + // If set, metalava is sandboxed to only read files explicitly specified on the command + // line. Defaults to false. + Sandbox *bool } type ApiToCheck struct { @@ -1434,34 +1438,18 @@ func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleB } func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths, - srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicits android.Paths) *android.RuleBuilderCommand { + srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicitsRsp android.WritablePath, sandbox bool) *android.RuleBuilderCommand { // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel. rule.HighMem() cmd := rule.Command() - - var implicitsRsp android.WritablePath - if len(implicits) > 0 { - implicitsRsp = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp") - impRule := android.NewRuleBuilder() - impCmd := impRule.Command() - // A dummy action that copies the ninja generated rsp file to a new location. This allows us to - // add a large number of inputs to a file without exceeding bash command length limits (which - // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the - // rsp file to be ${output}.rsp. - impCmd.Text("cp").FlagWithRspFileInputList("", implicits).Output(implicitsRsp) - impRule.Build(pctx, ctx, "implicitsGen", "implicits generation") - cmd.Implicits(implicits) - cmd.Implicit(implicitsRsp) - } if ctx.Config().IsEnvTrue("RBE_METALAVA") { rule.Remoteable(android.RemoteRuleSupports{RBE: true}) - execStrategy := remoteexec.LocalExecStrategy - if v := ctx.Config().Getenv("RBE_METALAVA_EXEC_STRATEGY"); v != "" { - execStrategy = v - } - pool := "metalava" - if v := ctx.Config().Getenv("RBE_METALAVA_POOL"); v != "" { - pool = v + pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava") + execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) + labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"} + if !sandbox { + execStrategy = remoteexec.LocalExecStrategy + labels["shallow"] = "true" } inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()} inputs = append(inputs, sourcepaths.Strings()...) @@ -1469,7 +1457,7 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi inputs = append(inputs, strings.Split(v, ",")...) } cmd.Text((&remoteexec.REParams{ - Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "metalava", "shallow": "true"}, + Labels: labels, ExecStrategy: execStrategy, Inputs: inputs, RSPFile: implicitsRsp.String(), @@ -1483,8 +1471,17 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi FlagWithArg("-encoding ", "UTF-8"). FlagWithArg("-source ", javaVersion.String()). FlagWithRspFileInputList("@", srcs). - FlagWithInput("@", srcJarList). - FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) + FlagWithInput("@", srcJarList) + + if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" { + cmd.Implicit(android.PathForSource(ctx, javaHome)) + } + + if sandbox { + cmd.FlagWithOutput("--strict-input-files ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) + } else { + cmd.FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) + } if implicitsRsp != nil { cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String()) @@ -1534,8 +1531,12 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) + implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp") + cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList, - deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, d.Javadoc.implicits) + deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, implicitsRsp, + Bool(d.Javadoc.properties.Sandbox)) + cmd.Implicits(d.Javadoc.implicits) d.stubsFlags(ctx, cmd, stubsDir) @@ -1663,6 +1664,16 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { cmd.FlagWithArg("--error-message:compatibility:released ", msg) } + impRule := android.NewRuleBuilder() + impCmd := impRule.Command() + // A dummy action that copies the ninja generated rsp file to a new location. This allows us to + // add a large number of inputs to a file without exceeding bash command length limits (which + // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the + // rsp file to be ${output}.rsp. + impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp) + impRule.Build(pctx, ctx, "implicitsGen", "implicits generation") + cmd.Implicit(implicitsRsp) + if generateStubs { rule.Command(). BuiltTool(ctx, "soong_zip"). diff --git a/java/java.go b/java/java.go index 5632ff58..72c91a5e 100644 --- a/java/java.go +++ b/java/java.go @@ -633,7 +633,9 @@ type jniLib struct { } func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool { - return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") + return j.properties.Instrument && + ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") && + ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir()) } func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool { |