-
Notifications
You must be signed in to change notification settings - Fork 9
/
step.go
40 lines (34 loc) · 803 Bytes
/
step.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 24 september 2014
package main
import (
"fmt"
"os"
"os/exec"
"flag"
"bytes"
"strings"
)
var showall = flag.Bool("x", false, "show all commands as they run")
// Step represents a single step in the build process.
type Step struct {
Name string
Line []string
Output *bytes.Buffer
Error error
}
func (s *Step) Do() {
if *showall {
fmt.Printf("%s\n", strings.Join(s.Line, " "))
}
cmd := exec.Command(s.Line[0], s.Line[1:]...)
cmd.Env = os.Environ()
s.Output = new(bytes.Buffer)
cmd.Stdout = s.Output
cmd.Stderr = s.Output
s.Error = cmd.Run()
}
// Stage is a list of Steps.
// Each Step in the Stage is run concurrently.
// A build process consists of multiple Stages.
// All Steps in the current Stage must be run to completion before other Steps will run.
type Stage []*Step