Merge "Add support for the remote execution of metalava actions."
This commit is contained in:
commit
a1ffd53fe4
|
@ -24,6 +24,7 @@ import (
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/java/config"
|
"android/soong/java/config"
|
||||||
|
"android/soong/remoteexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -1375,7 +1376,31 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi
|
||||||
srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
|
srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *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().BuiltTool(ctx, "metalava").
|
cmd := rule.Command()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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"},
|
||||||
|
ExecStrategy: execStrategy,
|
||||||
|
Inputs: inputs,
|
||||||
|
ToolchainInputs: []string{config.JavaCmd(ctx).String()},
|
||||||
|
Platform: map[string]string{remoteexec.PoolKey: pool},
|
||||||
|
}).NoVarTemplate(ctx.Config()))
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.BuiltTool(ctx, "metalava").
|
||||||
Flag(config.JavacVmFlags).
|
Flag(config.JavacVmFlags).
|
||||||
FlagWithArg("-encoding ", "UTF-8").
|
FlagWithArg("-encoding ", "UTF-8").
|
||||||
FlagWithArg("-source ", javaVersion.String()).
|
FlagWithArg("-source ", javaVersion.String()).
|
||||||
|
|
|
@ -82,17 +82,31 @@ type REParams struct {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pctx.VariableFunc("Wrapper", func(ctx android.PackageVarContext) string {
|
pctx.VariableFunc("Wrapper", func(ctx android.PackageVarContext) string {
|
||||||
if override := ctx.Config().Getenv("RBE_WRAPPER"); override != "" {
|
return wrapper(ctx.Config())
|
||||||
return override
|
|
||||||
}
|
|
||||||
return DefaultWrapperPath
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the remote execution wrapper template to be added as a prefix to the rule's command.
|
func wrapper(cfg android.Config) string {
|
||||||
func (r *REParams) Template() string {
|
if override := cfg.Getenv("RBE_WRAPPER"); override != "" {
|
||||||
template := "${remoteexec.Wrapper}"
|
return override
|
||||||
|
}
|
||||||
|
return DefaultWrapperPath
|
||||||
|
}
|
||||||
|
|
||||||
|
// Template generates the remote execution wrapper template to be added as a prefix to the rule's
|
||||||
|
// command.
|
||||||
|
func (r *REParams) Template() string {
|
||||||
|
return "${remoteexec.Wrapper}" + r.wrapperArgs()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoVarTemplate generate the remote execution wrapper template without variables, to be used in
|
||||||
|
// RuleBuilder.
|
||||||
|
func (r *REParams) NoVarTemplate(cfg android.Config) string {
|
||||||
|
return wrapper(cfg) + r.wrapperArgs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *REParams) wrapperArgs() string {
|
||||||
|
args := ""
|
||||||
var kvs []string
|
var kvs []string
|
||||||
labels := r.Labels
|
labels := r.Labels
|
||||||
if len(labels) == 0 {
|
if len(labels) == 0 {
|
||||||
|
@ -102,7 +116,7 @@ func (r *REParams) Template() string {
|
||||||
kvs = append(kvs, k+"="+v)
|
kvs = append(kvs, k+"="+v)
|
||||||
}
|
}
|
||||||
sort.Strings(kvs)
|
sort.Strings(kvs)
|
||||||
template += " --labels=" + strings.Join(kvs, ",")
|
args += " --labels=" + strings.Join(kvs, ",")
|
||||||
|
|
||||||
var platform []string
|
var platform []string
|
||||||
for k, v := range r.Platform {
|
for k, v := range r.Platform {
|
||||||
|
@ -116,32 +130,32 @@ func (r *REParams) Template() string {
|
||||||
}
|
}
|
||||||
if platform != nil {
|
if platform != nil {
|
||||||
sort.Strings(platform)
|
sort.Strings(platform)
|
||||||
template += " --platform=\"" + strings.Join(platform, ",") + "\""
|
args += " --platform=\"" + strings.Join(platform, ",") + "\""
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy := r.ExecStrategy
|
strategy := r.ExecStrategy
|
||||||
if strategy == "" {
|
if strategy == "" {
|
||||||
strategy = defaultExecStrategy
|
strategy = defaultExecStrategy
|
||||||
}
|
}
|
||||||
template += " --exec_strategy=" + strategy
|
args += " --exec_strategy=" + strategy
|
||||||
|
|
||||||
if len(r.Inputs) > 0 {
|
if len(r.Inputs) > 0 {
|
||||||
template += " --inputs=" + strings.Join(r.Inputs, ",")
|
args += " --inputs=" + strings.Join(r.Inputs, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.RSPFile != "" {
|
if r.RSPFile != "" {
|
||||||
template += " --input_list_paths=" + r.RSPFile
|
args += " --input_list_paths=" + r.RSPFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.OutputFiles) > 0 {
|
if len(r.OutputFiles) > 0 {
|
||||||
template += " --output_files=" + strings.Join(r.OutputFiles, ",")
|
args += " --output_files=" + strings.Join(r.OutputFiles, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.ToolchainInputs) > 0 {
|
if len(r.ToolchainInputs) > 0 {
|
||||||
template += " --toolchain_inputs=" + strings.Join(r.ToolchainInputs, ",")
|
args += " --toolchain_inputs=" + strings.Join(r.ToolchainInputs, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
return template + " -- "
|
return args + " -- "
|
||||||
}
|
}
|
||||||
|
|
||||||
// StaticRules returns a pair of rules based on the given RuleParams, where the first rule is a
|
// StaticRules returns a pair of rules based on the given RuleParams, where the first rule is a
|
||||||
|
|
|
@ -17,6 +17,8 @@ package remoteexec
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTemplate(t *testing.T) {
|
func TestTemplate(t *testing.T) {
|
||||||
|
@ -64,6 +66,22 @@ func TestTemplate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNoVarTemplate(t *testing.T) {
|
||||||
|
params := &REParams{
|
||||||
|
Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
|
||||||
|
Inputs: []string{"$in"},
|
||||||
|
OutputFiles: []string{"$out"},
|
||||||
|
Platform: map[string]string{
|
||||||
|
ContainerImageKey: DefaultImage,
|
||||||
|
PoolKey: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
want := fmt.Sprintf("prebuilts/remoteexecution-client/live/rewrapper --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=local --inputs=$in --output_files=$out -- ", DefaultImage)
|
||||||
|
if got := params.NoVarTemplate(android.NullConfig("")); got != want {
|
||||||
|
t.Errorf("NoVarTemplate() returned\n%s\nwant\n%s", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTemplateDeterminism(t *testing.T) {
|
func TestTemplateDeterminism(t *testing.T) {
|
||||||
r := &REParams{
|
r := &REParams{
|
||||||
Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
|
Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
|
||||||
|
|
Loading…
Reference in New Issue