mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/build: support building with missing git
This commit is contained in:
parent
727a91759b
commit
780b414b48
2 changed files with 13 additions and 11 deletions
|
|
@ -19,7 +19,6 @@ package build
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -118,12 +117,14 @@ func getDate(commit string) string {
|
|||
return ""
|
||||
}
|
||||
out := RunGit("show", "-s", "--format=%ct", commit)
|
||||
ti, err := strconv.ParseInt(strings.TrimSpace(out), 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal("Could not convert gitCommit date. Trying to parse: '" + out + "' The error is: " + err.Error())
|
||||
if out == "" {
|
||||
return ""
|
||||
}
|
||||
return time.Unix(ti, 0).Format("20060102")
|
||||
date, err := strconv.ParseInt(strings.TrimSpace(out), 10, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to parse git commit date: %v", err))
|
||||
}
|
||||
return time.Unix(date, 0).Format("20060102")
|
||||
}
|
||||
|
||||
func applyEnvFlags(env Environment) Environment {
|
||||
|
|
|
|||
|
|
@ -68,13 +68,14 @@ func RunGit(args ...string) string {
|
|||
cmd := exec.Command("git", args...)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
||||
if err := cmd.Run(); err == exec.ErrNotFound {
|
||||
if !warnedAboutGit {
|
||||
log.Println("Warning: can't find 'git' in PATH")
|
||||
warnedAboutGit = true
|
||||
if err := cmd.Run(); err != nil {
|
||||
if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound {
|
||||
if !warnedAboutGit {
|
||||
log.Println("Warning: can't find 'git' in PATH")
|
||||
warnedAboutGit = true
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
} else if err != nil {
|
||||
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
|
||||
}
|
||||
return strings.TrimSpace(stdout.String())
|
||||
|
|
|
|||
Loading…
Reference in a new issue