Yoshisato Yanagisawa | 2cb0e5d | 2019-01-10 10:14:16 +0900 | [diff] [blame^] | 1 | // Copyright 2018 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 | |
| 15 | package build |
| 16 | |
| 17 | import ( |
| 18 | "errors" |
| 19 | "path/filepath" |
| 20 | |
| 21 | "android/soong/ui/metrics" |
| 22 | ) |
| 23 | |
| 24 | const gomaCtlScript = "goma_ctl.py" |
| 25 | |
| 26 | var gomaCtlNotFound = errors.New("goma_ctl.py not found") |
| 27 | |
| 28 | func startGoma(ctx Context, config Config) error { |
| 29 | ctx.BeginTrace(metrics.RunSetupTool, "goma_ctl") |
| 30 | defer ctx.EndTrace() |
| 31 | |
| 32 | var gomaCtl string |
| 33 | if gomaDir, ok := config.Environment().Get("GOMA_DIR"); ok { |
| 34 | gomaCtl = filepath.Join(gomaDir, gomaCtlScript) |
| 35 | } else if home, ok := config.Environment().Get("HOME"); ok { |
| 36 | gomaCtl = filepath.Join(home, "goma", gomaCtlScript) |
| 37 | } else { |
| 38 | return gomaCtlNotFound |
| 39 | } |
| 40 | |
| 41 | cmd := Command(ctx, config, "goma_ctl.py ensure_start", gomaCtl, "ensure_start") |
| 42 | |
| 43 | if err := cmd.Run(); err != nil { |
| 44 | ctx.Fatalf("goma_ctl.py ensure_start failed with: %v", err) |
| 45 | } |
| 46 | |
| 47 | return nil |
| 48 | } |