Don't require godep to build

This commit is contained in:
Jakob Borg
2014-09-28 13:07:13 +02:00
parent 39ef35db0c
commit 9d816694ba
+20 -24
View File
@@ -67,28 +67,22 @@ func main() {
checkRequiredGoVersion() checkRequiredGoVersion()
if check() != nil {
setup()
}
if flag.NArg() == 0 { if flag.NArg() == 0 {
install("./cmd/...") install("./cmd/...")
return return
} }
switch flag.Arg(0) { for _, cmd := range flag.Args() {
switch cmd {
case "setup":
setup()
case "install": case "install":
pkg := "./cmd/..." pkg := "./cmd/..."
if flag.NArg() > 2 {
pkg = flag.Arg(1)
}
install(pkg) install(pkg)
case "build": case "build":
pkg := "./cmd/syncthing" pkg := "./cmd/syncthing"
if flag.NArg() > 2 {
pkg = flag.Arg(1)
}
var tags []string var tags []string
if noupgrade { if noupgrade {
tags = []string{"noupgrade"} tags = []string{"noupgrade"}
@@ -97,9 +91,6 @@ func main() {
case "test": case "test":
pkg := "./..." pkg := "./..."
if flag.NArg() > 2 {
pkg = flag.Arg(1)
}
test(pkg) test(pkg)
case "assets": case "assets":
@@ -127,13 +118,9 @@ func main() {
clean() clean()
default: default:
log.Fatalf("Unknown command %q", flag.Arg(0)) log.Fatalf("Unknown command %q", cmd)
} }
} }
func check() error {
_, err := exec.LookPath("godep")
return err
} }
func checkRequiredGoVersion() { func checkRequiredGoVersion() {
@@ -163,24 +150,25 @@ func setup() {
} }
func test(pkg string) { func test(pkg string) {
runPrint("godep", "go", "test", "-short", "-timeout", "10s", pkg) setBuildEnv()
runPrint("go", "test", "-short", "-timeout", "10s", pkg)
} }
func install(pkg string) { func install(pkg string) {
os.Setenv("GOBIN", "./bin") os.Setenv("GOBIN", "./bin")
setBuildEnv() setBuildEnv()
runPrint("godep", "go", "install", "-ldflags", ldflags(), pkg) runPrint("go", "install", "-ldflags", ldflags(), pkg)
} }
func build(pkg string, tags []string) { func build(pkg string, tags []string) {
rmr("syncthing", "syncthing.exe") rmr("syncthing", "syncthing.exe")
args := []string{"go", "build", "-ldflags", ldflags()} args := []string{"build", "-ldflags", ldflags()}
if len(tags) > 0 { if len(tags) > 0 {
args = append(args, "-tags", strings.Join(tags, ",")) args = append(args, "-tags", strings.Join(tags, ","))
} }
args = append(args, pkg) args = append(args, pkg)
setBuildEnv() setBuildEnv()
runPrint("godep", args...) runPrint("go", args...)
} }
func buildTar() { func buildTar() {
@@ -230,10 +218,18 @@ func setBuildEnv() {
if goarch == "386" { if goarch == "386" {
os.Setenv("GO386", "387") os.Setenv("GO386", "387")
} }
wd, err := os.Getwd()
if err != nil {
log.Println("Warning: can't determine current dir:", err)
log.Println("Build might not work as expected")
}
os.Setenv("GOPATH", fmt.Sprintf("%s%c%s", filepath.Join(wd, "Godeps", "_workspace"), os.PathListSeparator, os.Getenv("GOPATH")))
log.Println("GOPATH=" + os.Getenv("GOPATH"))
} }
func assets() { func assets() {
runPipe("internal/auto/gui.files.go", "godep", "go", "run", "cmd/genassets/main.go", "gui") setBuildEnv()
runPipe("internal/auto/gui.files.go", "go", "run", "cmd/genassets/main.go", "gui")
} }
func xdr() { func xdr() {