| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "io/ioutil" | 9 "io/ioutil" |
| 10 "os" | 10 "os" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 type recipeRun struct { | 34 type recipeRun struct { |
| 35 repositoryPath string | 35 repositoryPath string |
| 36 | 36 |
| 37 // The following are command line recipes.py command line arguments. | 37 // The following are command line recipes.py command line arguments. |
| 38 | 38 |
| 39 recipe string | 39 recipe string |
| 40 propertiesJSON string | 40 propertiesJSON string |
| 41 propertiesFile string | 41 propertiesFile string |
| 42 outputResultJSONFile string | 42 outputResultJSONFile string |
| 43 workDir string // Where to run the recipe. | 43 workDir string // Where to run the recipe. |
| 44 timestamps bool // Whether to print CURRENT_TIMESTAMP annota
tions. |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Command creates a exec.Cmd for running a recipe. | 47 // Command creates a exec.Cmd for running a recipe. |
| 47 func (r *recipeRun) Command() (*exec.Cmd, error) { | 48 func (r *recipeRun) Command() (*exec.Cmd, error) { |
| 48 cfgPath := filepath.Join(r.repositoryPath, "infra/config/recipes.cfg") | 49 cfgPath := filepath.Join(r.repositoryPath, "infra/config/recipes.cfg") |
| 49 cfg, err := readConfig(cfgPath) | 50 cfg, err := readConfig(cfgPath) |
| 50 if err != nil { | 51 if err != nil { |
| 51 return nil, err | 52 return nil, err |
| 52 } | 53 } |
| 53 | 54 |
| 54 if cfg.RecipesPath == nil || *cfg.RecipesPath == "" { | 55 if cfg.RecipesPath == nil || *cfg.RecipesPath == "" { |
| 55 return nil, fmt.Errorf("recipe_path is unspecified in %q", cfgPa
th) | 56 return nil, fmt.Errorf("recipe_path is unspecified in %q", cfgPa
th) |
| 56 } | 57 } |
| 57 | 58 |
| 58 recipesPy := path.Join(r.repositoryPath, *cfg.RecipesPath, "recipes.py") | 59 recipesPy := path.Join(r.repositoryPath, *cfg.RecipesPath, "recipes.py") |
| 59 if _, err := os.Stat(recipesPy); os.IsNotExist(err) { | 60 if _, err := os.Stat(recipesPy); os.IsNotExist(err) { |
| 60 return nil, fmt.Errorf("%q does not exist", recipesPy) | 61 return nil, fmt.Errorf("%q does not exist", recipesPy) |
| 61 } | 62 } |
| 62 | 63 |
| 63 cmd := exec.Command( | 64 cmd := exec.Command( |
| 64 "python", recipesPy, | 65 "python", recipesPy, |
| 65 "run", | 66 "run", |
| 66 "--properties", r.propertiesJSON, | 67 "--properties", r.propertiesJSON, |
| 67 "--properties-file", r.propertiesFile, | 68 "--properties-file", r.propertiesFile, |
| 68 "--workdir", r.workDir, | 69 "--workdir", r.workDir, |
| 69 "--output-result-json", r.outputResultJSONFile, | 70 "--output-result-json", r.outputResultJSONFile, |
| 70 r.recipe, | |
| 71 ) | 71 ) |
| 72 if r.timestamps { |
| 73 cmd.Args = append(cmd.Args, "--timestamps") |
| 74 } |
| 75 cmd.Args = append(cmd.Args, r.recipe) |
| 76 |
| 72 cmd.Stdout = os.Stdout | 77 cmd.Stdout = os.Stdout |
| 73 cmd.Stderr = os.Stderr | 78 cmd.Stderr = os.Stderr |
| 74 return cmd, nil | 79 return cmd, nil |
| 75 } | 80 } |
| OLD | NEW |