make.go: don't depend on a shell script to get the git version.

Fixes building on Windows; https://code.google.com/p/camlistore/issues/detail?id=181

Change-Id: I6f25589567e610aa63d5bcd91e7efe9aaab7c050
This commit is contained in:
Brad Fitzpatrick 2013-07-28 18:15:04 -07:00
parent 4c04df0c9a
commit 831f5c3a06
1 changed files with 25 additions and 3 deletions

28
make.go
View File

@ -366,11 +366,33 @@ func getVersion(camRoot string) string {
if err == nil {
return strings.TrimSpace(string(slurp))
}
out, err := exec.Command(filepath.Join(camRoot, "misc", "gitversion")).Output()
return gitVersion(camRoot)
}
var gitVersionRx = regexp.MustCompile(`\b\d\d\d\d-\d\d-\d\d-[0-9a-f]{7,7}\b`)
// gitVersion returns the git version of the git repo at camRoot as a
// string of the form "yyyy-mm-dd-xxxxxxx", with an optional trailing
// '+' if there are any local uncomitted modifications to the tree.
func gitVersion(camRoot string) string {
cmd := exec.Command("git", "rev-list", "--max-count=1", "--pretty=format:'%ad-%h'", "--date=short", "HEAD")
cmd.Dir = camRoot
out, err := cmd.Output()
if err != nil {
log.Fatalf("Error running ./misc/gitversion to determine Camlistore version: %v", err)
log.Fatalf("Error running git rev-list in %s: %v", camRoot, err)
}
return strings.TrimSpace(string(out))
v := strings.TrimSpace(string(out))
if m := gitVersionRx.FindStringSubmatch(v); m != nil {
v = m[0]
} else {
panic("Failed to find git version in " + v)
}
cmd = exec.Command("git", "diff", "--exit-code")
cmd.Dir = camRoot
if err := cmd.Run(); err != nil {
v += "+"
}
return v
}
// verifyCamlistoreRoot crashes if dir isn't the Camlistore root directory.