aboutsummaryrefslogtreecommitdiffstats
path: root/internal/build/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/build/util.go')
-rw-r--r--internal/build/util.go23
1 files changed, 10 insertions, 13 deletions
diff --git a/internal/build/util.go b/internal/build/util.go
index eead824b2..a821cd7f2 100644
--- a/internal/build/util.go
+++ b/internal/build/util.go
@@ -29,9 +29,7 @@ import (
"text/template"
)
-var (
- DryRunFlag = flag.Bool("n", false, "dry run, don't execute commands")
-)
+var DryRunFlag = flag.Bool("n", false, "dry run, don't execute commands")
// MustRun executes the given command and exits the host process for
// any error.
@@ -57,18 +55,18 @@ func GOPATH() string {
if len(path) == 0 {
log.Fatal("GOPATH is not set")
}
- // Ensure Godeps workspace is present in the path.
- godeps, _ := filepath.Abs(filepath.Join("Godeps", "_workspace"))
+ // Ensure that our internal vendor folder in on GOPATH
+ vendor, _ := filepath.Abs(filepath.Join("build", "_vendor"))
for _, dir := range path {
- if dir == godeps {
+ if dir == vendor {
return strings.Join(path, string(filepath.ListSeparator))
}
}
- newpath := append(path[:1], godeps)
- newpath = append(newpath, path[1:]...)
+ newpath := append(path[:1], append([]string{vendor}, path[1:]...)...)
return strings.Join(newpath, string(filepath.ListSeparator))
}
+// VERSION returns the content of the VERSION file.
func VERSION() string {
version, err := ioutil.ReadFile("VERSION")
if err != nil {
@@ -77,10 +75,8 @@ func VERSION() string {
return string(bytes.TrimSpace(version))
}
-func GitCommit() string {
- return RunGit("rev-parse", "HEAD")
-}
-
+// RunGit runs a git subcommand and returns its output.
+// The command must complete successfully.
func RunGit(args ...string) string {
cmd := exec.Command("git", args...)
var stdout, stderr bytes.Buffer
@@ -94,12 +90,13 @@ func RunGit(args ...string) string {
return strings.TrimSpace(stdout.String())
}
-// Render renders the given template file.
+// Render renders the given template file into outputFile.
func Render(templateFile, outputFile string, outputPerm os.FileMode, x interface{}) {
tpl := template.Must(template.ParseFiles(templateFile))
render(tpl, outputFile, outputPerm, x)
}
+// RenderString renders the given template string into outputFile.
func RenderString(templateContent, outputFile string, outputPerm os.FileMode, x interface{}) {
tpl := template.Must(template.New("").Parse(templateContent))
render(tpl, outputFile, outputPerm, x)