| 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 "strings" | 9 "strings" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 }, v) | 28 }, v) |
| 29 } | 29 } |
| 30 | 30 |
| 31 // buildComponent runs the varuous build scripts defined by the specified | 31 // buildComponent runs the varuous build scripts defined by the specified |
| 32 // deployment component. | 32 // deployment component. |
| 33 // | 33 // |
| 34 // After running the build scripts, variable substitution will occur on "c" | 34 // After running the build scripts, variable substitution will occur on "c" |
| 35 // to update its directory. | 35 // to update its directory. |
| 36 func buildComponent(w *work, c *layoutDeploymentComponent, root *managedfs.Dir)
error { | 36 func buildComponent(w *work, c *layoutDeploymentComponent, root *managedfs.Dir)
error { |
| 37 if src := c.source(); !src.Source.RunScripts { | 37 if src := c.source(); !src.Source.RunScripts { |
| 38 » » return errors.Reason("refusing to run scripts (run_scripts is fa
lse for %(source)q)"). | 38 » » return errors.Reason("refusing to run scripts (run_scripts is fa
lse for %q)", src.title).Err() |
| 39 » » » D("source", src.title).Err() | |
| 40 } | 39 } |
| 41 | 40 |
| 42 // Create our build directories and map them to variables. | 41 // Create our build directories and map them to variables. |
| 43 c.buildDirs = make(map[string]string, len(c.Build)) | 42 c.buildDirs = make(map[string]string, len(c.Build)) |
| 44 dirs := make([]*managedfs.Dir, len(c.Build)) | 43 dirs := make([]*managedfs.Dir, len(c.Build)) |
| 45 for i, b := range c.Build { | 44 for i, b := range c.Build { |
| 46 if _, has := c.buildDirs[b.DirKey]; has { | 45 if _, has := c.buildDirs[b.DirKey]; has { |
| 47 » » » return errors.Reason("duplicate build key [%(key)s]").D(
"key", b.DirKey).Err() | 46 » » » return errors.Reason("duplicate build key [%s]", b.DirKe
y).Err() |
| 48 } | 47 } |
| 49 | 48 |
| 50 dir, err := root.EnsureDirectory(fmt.Sprintf("%d_%s", i, flatten
VarToDir(b.DirKey))) | 49 dir, err := root.EnsureDirectory(fmt.Sprintf("%d_%s", i, flatten
VarToDir(b.DirKey))) |
| 51 if err != nil { | 50 if err != nil { |
| 52 » » » return errors.Annotate(err).Reason("failed to create bui
ld directory").Err() | 51 » » » return errors.Annotate(err, "failed to create build dire
ctory").Err() |
| 53 } | 52 } |
| 54 | 53 |
| 55 dirs[i] = dir | 54 dirs[i] = dir |
| 56 c.buildDirs[b.DirKey] = dir.String() | 55 c.buildDirs[b.DirKey] = dir.String() |
| 57 } | 56 } |
| 58 | 57 |
| 59 // Apply build directories. | 58 // Apply build directories. |
| 60 if err := c.expandPaths(); err != nil { | 59 if err := c.expandPaths(); err != nil { |
| 61 » » return errors.Annotate(err).Reason("failed to expand component p
aths").Err() | 60 » » return errors.Annotate(err, "failed to expand component paths").
Err() |
| 62 } | 61 } |
| 63 | 62 |
| 64 // Run all of our build scripts in parallel. | 63 // Run all of our build scripts in parallel. |
| 65 err := w.RunMulti(func(workC chan<- func() error) { | 64 err := w.RunMulti(func(workC chan<- func() error) { |
| 66 for i, b := range c.Build { | 65 for i, b := range c.Build { |
| 67 i, b := i, b | 66 i, b := i, b |
| 68 workC <- func() error { | 67 workC <- func() error { |
| 69 return runComponentBuild(w, c, b, dirs[i]) | 68 return runComponentBuild(w, c, b, dirs[i]) |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 }) | 71 }) |
| 73 if err != nil { | 72 if err != nil { |
| 74 » » return errors.Annotate(err).Reason("failed to run component buil
ds").Err() | 73 » » return errors.Annotate(err, "failed to run component builds").Er
r() |
| 75 } | 74 } |
| 76 return nil | 75 return nil |
| 77 } | 76 } |
| 78 | 77 |
| 79 func runComponentBuild(w *work, c *layoutDeploymentComponent, b *deploy.Componen
t_Build, root *managedfs.Dir) error { | 78 func runComponentBuild(w *work, c *layoutDeploymentComponent, b *deploy.Componen
t_Build, root *managedfs.Dir) error { |
| 80 switch t := b.Operation.(type) { | 79 switch t := b.Operation.(type) { |
| 81 case *deploy.Component_Build_PythonScript_: | 80 case *deploy.Component_Build_PythonScript_: |
| 82 ps := t.PythonScript | 81 ps := t.PythonScript |
| 83 | 82 |
| 84 python, err := w.python() | 83 python, err := w.python() |
| 85 if err != nil { | 84 if err != nil { |
| 86 return err | 85 return err |
| 87 } | 86 } |
| 88 | 87 |
| 89 src := c.source() | 88 src := c.source() |
| 90 scriptPath := src.pathTo(ps.Path, c.comp.Path) | 89 scriptPath := src.pathTo(ps.Path, c.comp.Path) |
| 91 buildDir := root.String() | 90 buildDir := root.String() |
| 92 | 91 |
| 93 args := append(make([]string, 0, 2+len(ps.ExtraArgs)), | 92 args := append(make([]string, 0, 2+len(ps.ExtraArgs)), |
| 94 src.checkoutPath(), | 93 src.checkoutPath(), |
| 95 buildDir) | 94 buildDir) |
| 96 args = append(args, ps.ExtraArgs...) | 95 args = append(args, ps.ExtraArgs...) |
| 97 | 96 |
| 98 if err := python.exec(scriptPath, args...).cwd(buildDir).check(w
); err != nil { | 97 if err := python.exec(scriptPath, args...).cwd(buildDir).check(w
); err != nil { |
| 99 » » » return errors.Annotate(err).Reason("failed to execute [%
(scriptPath)s]").D("scriptPath", scriptPath).Err() | 98 » » » return errors.Annotate(err, "failed to execute [%s]", sc
riptPath).Err() |
| 100 } | 99 } |
| 101 return nil | 100 return nil |
| 102 | 101 |
| 103 default: | 102 default: |
| 104 » » return errors.Reason("unknown build type %(type)T").D("type", t)
.Err() | 103 » » return errors.Reason("unknown build type %T", t).Err() |
| 105 } | 104 } |
| 106 } | 105 } |
| OLD | NEW |