Add sandbox property to the javadoc rule.

The sandbox property indicates whether metalava should only read
inputs explicitly specified on the command line. This CL adds the
property and sets the appropriate configuration for RBE depending
on whether the sandbox is set or not.
Bug: b/156613606
Test: built aosp_crosshatch-userdebug with/without RBE_METALAVA.
Change-Id: I7256d29f18e0af18dbe65d1c7dbbf62fd3d65f4c
Merged-In: I7256d29f18e0af18dbe65d1c7dbbf62fd3d65f4c
This commit is contained in:
Ramy Medhat
2020-06-13 17:38:27 -04:00
parent f221e59429
commit abe1a1aa3e
2 changed files with 57 additions and 30 deletions

View File

@@ -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").