blob: ceea4bf2bc646b6831a20adc56389691064b8e85 [file] [log] [blame]
Ramy Medhatbbf25672019-07-17 12:30:04 +00001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package build
16
17import (
18 "path/filepath"
19
20 "android/soong/ui/metrics"
21)
22
23const bootstrapCmd = "bootstrap"
24const rbeLeastNProcs = 2500
25const rbeLeastNFiles = 16000
26
27func startRBE(ctx Context, config Config) {
28 ctx.BeginTrace(metrics.RunSetupTool, "rbe_bootstrap")
29 defer ctx.EndTrace()
30
31 if u := ulimitOrFatal(ctx, config, "-u"); u < rbeLeastNProcs {
32 ctx.Fatalf("max user processes is insufficient: %d; want >= %d.\n", u, rbeLeastNProcs)
33 }
34 if n := ulimitOrFatal(ctx, config, "-n"); n < rbeLeastNFiles {
35 ctx.Fatalf("max open files is insufficient: %d; want >= %d.\n", n, rbeLeastNFiles)
36 }
37
38 var rbeBootstrap string
39 if rbeDir, ok := config.Environment().Get("RBE_DIR"); ok {
40 rbeBootstrap = filepath.Join(rbeDir, bootstrapCmd)
41 } else if home, ok := config.Environment().Get("HOME"); ok {
42 rbeBootstrap = filepath.Join(home, "rbe", bootstrapCmd)
43 } else {
44 ctx.Fatalln("rbe bootstrap not found")
45 }
46
47 cmd := Command(ctx, config, "boostrap", rbeBootstrap)
48
49 if output, err := cmd.CombinedOutput(); err != nil {
50 ctx.Fatalf("rbe bootstrap failed with: %v\n%s\n", err, output)
51 }
52}