From d9ff4cda557758db7ed0847e78b36466fda6b163 Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Mon, 16 Aug 2021 17:23:09 +0800 Subject: [PATCH 1/2] Allow setting platform constraints with --exec_constraints --- cmd/rbe_configs_gen/rbe_configs_gen.go | 6 ++++++ pkg/rbeconfigsgen/options.go | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/rbe_configs_gen/rbe_configs_gen.go b/cmd/rbe_configs_gen/rbe_configs_gen.go index f83e767a8..cc4256dd7 100644 --- a/cmd/rbe_configs_gen/rbe_configs_gen.go +++ b/cmd/rbe_configs_gen/rbe_configs_gen.go @@ -22,6 +22,7 @@ import ( "fmt" "log" "os" + "strings" "github.com/bazelbuild/bazel-toolchains/pkg/monitoring" "github.com/bazelbuild/bazel-toolchains/pkg/rbeconfigsgen" @@ -50,6 +51,7 @@ var ( cppToolchainTarget = flag.String("cpp_toolchain_target", "", "(Optional) Set the CPP toolchain target. When exec_os is linux, the default is cc-compiler-k8. When exec_os is windows, the default is cc-compiler-x64_windows.") genJavaConfigs = flag.Bool("generate_java_configs", true, "(Optional) Generate Java configs. Defaults to true.") javaUseLocalRuntime = flag.Bool("java_use_local_runtime", false, "(Optional) Make the generated java toolchain use the new local_java_runtime rule instead of java_runtime. Otherwise, the Bazel version will be used to infer which rule to use.") + execConstraints = flag.String("exec_constraints", "", "(Optional) Set the platform constraint values. Use ',' to seperate multiple values.") // Other misc arguments. tempWorkDir = flag.String("temp_work_dir", "", "(Optional) Temporary directory to use to store intermediate files. Defaults to a temporary directory automatically allocated by the OS. The temporary working directory is deleted at the end unless --cleanup=false is specified.") @@ -155,6 +157,9 @@ func main() { log.Fatalf("Failed to initialize monitoring: %v", err) } + platformParams := new(rbeconfigsgen.PlatformToolchainsTemplateParams) + platformParams.ExecConstraints = strings.Split(*execConstraints, ",") + o := rbeconfigsgen.Options{ BazelVersion: *bazelVersion, BazelPath: *bazelPath, @@ -168,6 +173,7 @@ func main() { OutputManifest: *outputManifest, GenCPPConfigs: *genCppConfigs, CppGenEnvJSON: *cppEnvJSON, + PlatformParams: platformParams, CPPToolchainTargetName: *cppToolchainTarget, GenJavaConfigs: *genJavaConfigs, JavaUseLocalRuntime: *javaUseLocalRuntime, diff --git a/pkg/rbeconfigsgen/options.go b/pkg/rbeconfigsgen/options.go index b32965a34..2d9fb25c9 100644 --- a/pkg/rbeconfigsgen/options.go +++ b/pkg/rbeconfigsgen/options.go @@ -195,8 +195,13 @@ func (o *Options) ApplyDefaults(os string) error { if !ok { return fmt.Errorf("got unknown OS %q, want one of %s", os, strings.Join(validOS, ", ")) } - o.PlatformParams = new(PlatformToolchainsTemplateParams) - *o.PlatformParams = dopts.PlatformParams + + if len(o.PlatformParams.ExecConstraints) == 0 { + o.PlatformParams.ExecConstraints = dopts.PlatformParams.ExecConstraints + } + o.PlatformParams.TargetConstraints = dopts.PlatformParams.TargetConstraints + o.PlatformParams.OSFamily = dopts.PlatformParams.OSFamily + o.CPPConfigTargets = dopts.CPPConfigTargets o.CPPConfigRepo = dopts.CPPConfigRepo o.CppBazelCmd = dopts.CppBazelCmd From 39f6363ffaa465d3f009d1d954ea4e19e2f07438 Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Tue, 17 Aug 2021 10:30:25 +0800 Subject: [PATCH 2/2] Fix tests --- pkg/rbeconfigsgen/options.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/rbeconfigsgen/options.go b/pkg/rbeconfigsgen/options.go index 2d9fb25c9..b46cc687e 100644 --- a/pkg/rbeconfigsgen/options.go +++ b/pkg/rbeconfigsgen/options.go @@ -196,6 +196,10 @@ func (o *Options) ApplyDefaults(os string) error { return fmt.Errorf("got unknown OS %q, want one of %s", os, strings.Join(validOS, ", ")) } + if o.PlatformParams == nil { + o.PlatformParams = new(PlatformToolchainsTemplateParams) + } + if len(o.PlatformParams.ExecConstraints) == 0 { o.PlatformParams.ExecConstraints = dopts.PlatformParams.ExecConstraints }