diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-01-11 07:10:34 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-01-11 07:10:34 +0000 |
commit | ae1366f60d2f46d8747fddef40762a7376ab7442 (patch) | |
tree | 427c9e4957770c3cc79d3c74d60e2a5001368470 /ui | |
parent | a9b3cd4788e890658193335690e3e438cc64bf9c (diff) | |
parent | 0c517bd9e4d98c223990b8ea8e0a425e02f40153 (diff) | |
download | build_soong-ae1366f60d2f46d8747fddef40762a7376ab7442.tar.gz build_soong-ae1366f60d2f46d8747fddef40762a7376ab7442.tar.bz2 build_soong-ae1366f60d2f46d8747fddef40762a7376ab7442.zip |
Merge "Fatal error on insufficient resource to use Goma in Soong UI."
Diffstat (limited to 'ui')
-rw-r--r-- | ui/build/goma.go | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/ui/build/goma.go b/ui/build/goma.go index d0dc9cfc..015a7c77 100644 --- a/ui/build/goma.go +++ b/ui/build/goma.go @@ -15,34 +15,65 @@ package build import ( - "errors" + "fmt" + "math" "path/filepath" + "strconv" + "strings" "android/soong/ui/metrics" ) const gomaCtlScript = "goma_ctl.py" +const gomaLeastNProcs = 2500 +const gomaLeastNFiles = 16000 -var gomaCtlNotFound = errors.New("goma_ctl.py not found") +// ulimit returns ulimit result for |opt|. +// if the resource is unlimited, it returns math.MaxInt32 so that a caller do +// not need special handling of the returned value. +// +// Note that since go syscall package do not have RLIMIT_NPROC constant, +// we use bash ulimit instead. +func ulimitOrFatal(ctx Context, config Config, opt string) int { + commandText := fmt.Sprintf("ulimit %s", opt) + cmd := Command(ctx, config, commandText, "bash", "-c", commandText) + output := strings.TrimRight(string(cmd.CombinedOutputOrFatal()), "\n") + ctx.Verbose(output + "\n") + ctx.Verbose("done\n") + + if output == "unlimited" { + return math.MaxInt32 + } + num, err := strconv.Atoi(output) + if err != nil { + ctx.Fatalf("ulimit returned unexpected value: %s: %v\n", opt, err) + } + return num +} -func startGoma(ctx Context, config Config) error { +func startGoma(ctx Context, config Config) { ctx.BeginTrace(metrics.RunSetupTool, "goma_ctl") defer ctx.EndTrace() + if u := ulimitOrFatal(ctx, config, "-u"); u < gomaLeastNProcs { + ctx.Fatalf("max user processes is insufficient: %d; want >= %d.\n", u, gomaLeastNProcs) + } + if n := ulimitOrFatal(ctx, config, "-n"); n < gomaLeastNFiles { + ctx.Fatalf("max open files is insufficient: %d; want >= %d.\n", n, gomaLeastNFiles) + } + var gomaCtl string if gomaDir, ok := config.Environment().Get("GOMA_DIR"); ok { gomaCtl = filepath.Join(gomaDir, gomaCtlScript) } else if home, ok := config.Environment().Get("HOME"); ok { gomaCtl = filepath.Join(home, "goma", gomaCtlScript) } else { - return gomaCtlNotFound + ctx.Fatalln("goma_ctl.py not found") } cmd := Command(ctx, config, "goma_ctl.py ensure_start", gomaCtl, "ensure_start") if err := cmd.Run(); err != nil { - ctx.Fatalf("goma_ctl.py ensure_start failed with: %v", err) + ctx.Fatalf("goma_ctl.py ensure_start failed with: %v\n", err) } - - return nil } |