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

Commit 2f99eec4 authored by Ramy Medhat's avatar Ramy Medhat
Browse files

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.

Test: built aosp_crosshatch-userdebug with/without RBE_METALAVA.
Change-Id: I7256d29f18e0af18dbe65d1c7dbbf62fd3d65f4c
parent 3d14ab7b
Loading
Loading
Loading
Loading
+19 −3
Original line number Original line Diff line number Diff line
@@ -172,7 +172,7 @@ func (r *RuleBuilder) Inputs() Paths {


	inputs := make(map[string]Path)
	inputs := make(map[string]Path)
	for _, c := range r.commands {
	for _, c := range r.commands {
		for _, input := range c.inputs {
		for _, input := range append(c.inputs, c.implicits...) {
			inputStr := input.String()
			inputStr := input.String()
			if _, isOutput := outputs[inputStr]; !isOutput {
			if _, isOutput := outputs[inputStr]; !isOutput {
				if _, isDepFile := depFiles[inputStr]; !isDepFile {
				if _, isDepFile := depFiles[inputStr]; !isDepFile {
@@ -480,6 +480,7 @@ func (r *RuleBuilder) Build(pctx PackageContext, ctx BuilderContext, name string
type RuleBuilderCommand struct {
type RuleBuilderCommand struct {
	buf           strings.Builder
	buf           strings.Builder
	inputs        Paths
	inputs        Paths
	implicits     Paths
	orderOnlys    Paths
	orderOnlys    Paths
	outputs       WritablePaths
	outputs       WritablePaths
	depFiles      WritablePaths
	depFiles      WritablePaths
@@ -503,6 +504,16 @@ func (c *RuleBuilderCommand) addInput(path Path) string {
	return 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) {
func (c *RuleBuilderCommand) addOrderOnly(path Path) {
	c.orderOnlys = append(c.orderOnlys, 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
// Implicit adds the specified input path to the dependencies returned by RuleBuilder.Inputs without modifying the
// command line.
// command line.
func (c *RuleBuilderCommand) Implicit(path Path) *RuleBuilderCommand {
func (c *RuleBuilderCommand) Implicit(path Path) *RuleBuilderCommand {
	c.addInput(path)
	c.addImplicit(path)
	return c
	return c
}
}


@@ -631,11 +642,16 @@ func (c *RuleBuilderCommand) Implicit(path Path) *RuleBuilderCommand {
// command line.
// command line.
func (c *RuleBuilderCommand) Implicits(paths Paths) *RuleBuilderCommand {
func (c *RuleBuilderCommand) Implicits(paths Paths) *RuleBuilderCommand {
	for _, path := range paths {
	for _, path := range paths {
		c.addInput(path)
		c.addImplicit(path)
	}
	}
	return c
	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
// OrderOnly adds the specified input path to the dependencies returned by RuleBuilder.OrderOnlys
// without modifying the command line.
// without modifying the command line.
func (c *RuleBuilderCommand) OrderOnly(path Path) *RuleBuilderCommand {
func (c *RuleBuilderCommand) OrderOnly(path Path) *RuleBuilderCommand {
+38 −27
Original line number Original line Diff line number Diff line
@@ -121,6 +121,10 @@ type JavadocProperties struct {


	// names of the output files used in args that will be generated
	// names of the output files used in args that will be generated
	Out []string
	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 {
type ApiToCheck struct {
@@ -1419,41 +1423,25 @@ func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleB
}
}


func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
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.
	// Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
	rule.HighMem()
	rule.HighMem()
	cmd := rule.Command()
	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") {
	if ctx.Config().IsEnvTrue("RBE_METALAVA") {
		rule.Remoteable(android.RemoteRuleSupports{RBE: true})
		rule.Remoteable(android.RemoteRuleSupports{RBE: true})
		execStrategy := remoteexec.LocalExecStrategy
		pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava")
		if v := ctx.Config().Getenv("RBE_METALAVA_EXEC_STRATEGY"); v != "" {
		execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
			execStrategy = v
		labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"}
		}
		if !sandbox {
		pool := "metalava"
			execStrategy = remoteexec.LocalExecStrategy
		if v := ctx.Config().Getenv("RBE_METALAVA_POOL"); v != "" {
			labels["shallow"] = "true"
			pool = v
		}
		}
		inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()}
		inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()}
		if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
		if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
			inputs = append(inputs, strings.Split(v, ",")...)
			inputs = append(inputs, strings.Split(v, ",")...)
		}
		}
		cmd.Text((&remoteexec.REParams{
		cmd.Text((&remoteexec.REParams{
			Labels:          map[string]string{"type": "compile", "lang": "java", "compiler": "metalava", "shallow": "true"},
			Labels:          labels,
			ExecStrategy:    execStrategy,
			ExecStrategy:    execStrategy,
			Inputs:          inputs,
			Inputs:          inputs,
			RSPFile:         implicitsRsp.String(),
			RSPFile:         implicitsRsp.String(),
@@ -1467,8 +1455,17 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
		FlagWithArg("-encoding ", "UTF-8").
		FlagWithArg("-encoding ", "UTF-8").
		FlagWithArg("-source ", javaVersion.String()).
		FlagWithArg("-source ", javaVersion.String()).
		FlagWithRspFileInputList("@", srcs).
		FlagWithRspFileInputList("@", srcs).
		FlagWithInput("@", srcJarList).
		FlagWithInput("@", srcJarList)
		FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))

	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 {
	if implicitsRsp != nil {
		cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
		cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
@@ -1518,8 +1515,12 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {


	srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
	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,
	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)
	d.stubsFlags(ctx, cmd, stubsDir)


@@ -1638,6 +1639,16 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		cmd.FlagWithArg("--error-message:compatibility:released ", msg)
		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 {
	if generateStubs {
		rule.Command().
		rule.Command().
			BuiltTool(ctx, "soong_zip").
			BuiltTool(ctx, "soong_zip").