Merge "Add sandbox property to the javadoc rule." am: 997a2f5b4e am: a195919e38

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

Change-Id: I31135dccd6451355fdaff3f86db309f45fc2a2a7
This commit is contained in:
Ramy Medhat
2020-06-20 01:58:49 +00:00
committed by Automerger Merge Worker
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 {
@@ -1435,41 +1439,25 @@ 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()}
if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
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").