Skip to content

Commit

Permalink
Allow setting platform constraints with --exec_constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Aug 17, 2021
1 parent 27f2db2 commit f5a85a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmd/rbe_configs_gen/rbe_configs_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/bazelbuild/bazel-toolchains/pkg/monitoring"
"github.com/bazelbuild/bazel-toolchains/pkg/rbeconfigsgen"
Expand All @@ -47,6 +48,7 @@ var (
cppEnvJSON = flag.String("cpp_env_json", "", "(Optional) JSON file containing a str -> str dict of environment variables to be set when generating C++ configs inside the toolchain container. This replaces any exec OS specific defaults that would usually be applied.")
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.")
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.")
Expand Down Expand Up @@ -146,6 +148,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,
ToolchainContainer: *toolchainContainer,
Expand All @@ -157,6 +162,7 @@ func main() {
OutputManifest: *outputManifest,
GenCPPConfigs: *genCppConfigs,
CppGenEnvJSON: *cppEnvJSON,
PlatformParams: platformParams,
CPPToolchainTargetName: *cppToolchainTarget,
GenJavaConfigs: *genJavaConfigs,
TempWorkDir: *tempWorkDir,
Expand Down
9 changes: 7 additions & 2 deletions pkg/rbeconfigsgen/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,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
Expand Down

0 comments on commit f5a85a5

Please sign in to comment.