2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Update build.go and run_integration_tests.go

This commit is contained in:
Alexander Neumann 2016-02-14 17:39:51 +01:00
parent 841326d713
commit 96e66bb3e9
2 changed files with 40 additions and 20 deletions

View File

@ -30,7 +30,11 @@ func specialDir(name string) bool {
}
base := filepath.Base(name)
return base[0] == '_' || base[0] == '.'
if base == "vendor" || base[0] == '_' || base[0] == '.' {
return true
}
return false
}
// excludePath returns true if the file should not be copied to the new GOPATH.
@ -177,10 +181,11 @@ func cleanEnv() (env []string) {
}
// build runs "go build args..." with GOPATH set to gopath.
func build(gopath string, args ...string) error {
func build(cwd, gopath string, args ...string) error {
args = append([]string{"build"}, args...)
cmd := exec.Command("go", args...)
cmd.Env = append(cleanEnv(), "GOPATH="+gopath)
cmd.Dir = cwd
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
verbosePrintf("go %s\n", args)
@ -189,10 +194,11 @@ func build(gopath string, args ...string) error {
}
// test runs "go test args..." with GOPATH set to gopath.
func test(gopath string, args ...string) error {
func test(cwd, gopath string, args ...string) error {
args = append([]string{"test"}, args...)
cmd := exec.Command("go", args...)
cmd.Env = append(cleanEnv(), "GOPATH="+gopath)
cmd.Dir = cwd
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
verbosePrintf("go %s\n", args)
@ -293,6 +299,7 @@ func main() {
runTests = true
case "-h":
showUsage(os.Stdout)
return
default:
fmt.Fprintf(os.Stderr, "Error: unknown option %q\n\n", arg)
showUsage(os.Stderr)
@ -322,11 +329,11 @@ func main() {
}
verbosePrintf("create GOPATH at %v\n", gopath)
if err = updateGopath(gopath, root, "github.com/restic/restic"); err != nil {
if err = updateGopath(gopath, filepath.Join(root, "src"), ""); err != nil {
die("copying files from %v to %v failed: %v\n", root, gopath, err)
}
vendor := filepath.Join(root, "Godeps", "_workspace", "src")
vendor := filepath.Join(root, "vendor", "src")
if err = updateGopath(gopath, vendor, ""); err != nil {
die("copying files from %v to %v failed: %v\n", root, gopath, err)
}
@ -342,10 +349,17 @@ func main() {
}
}()
output := "restic"
outputFilename := "restic"
if runtime.GOOS == "windows" {
output = "restic.exe"
outputFilename = "restic.exe"
}
cwd, err := os.Getwd()
if err != nil {
die("Getwd() returned %v\n", err)
}
output := filepath.Join(cwd, outputFilename)
version := getVersion()
compileTime := time.Now().Format(timeFormat)
constants := Constants{`main.compiledAt`: compileTime}
@ -358,10 +372,10 @@ func main() {
args := []string{
"-tags", strings.Join(buildTags, " "),
"-ldflags", ldflags,
"-o", output, "github.com/restic/restic/cmd/restic",
"-o", output, "restic/cmd/restic",
}
err = build(gopath, args...)
err = build(filepath.Join(gopath, "src"), gopath, args...)
if err != nil {
die("build failed: %v\n", err)
}
@ -369,7 +383,7 @@ func main() {
if runTests {
verbosePrintf("running tests\n")
err = test(gopath, "github.com/restic/restic/...")
err = test(filepath.Join(gopath, "src"), gopath, "restic/...")
if err != nil {
die("running tests failed: %v\n", err)
}

View File

@ -154,27 +154,31 @@ func (env *TravisEnvironment) RunTests() {
os.Setenv("RESTIC_TEST_FUSE", "0")
}
cwd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "Getwd() returned error: %v", err)
os.Exit(9)
}
envWithGOPATH := make(map[string]string)
envWithGOPATH["GOPATH"] = cwd + ":" + filepath.Join(cwd, "vendor")
if *runCrossCompile {
// compile for all target architectures with tags
for _, tags := range []string{"release", "debug"} {
run("gox", "-verbose",
runWithEnv(envWithGOPATH, "gox", "-verbose",
"-os", strings.Join(env.goxOS, " "),
"-arch", strings.Join(env.goxArch, " "),
"-tags", tags,
"-output", "/tmp/{{.Dir}}_{{.OS}}_{{.Arch}}",
"./cmd/restic")
"restic/cmd/restic")
}
}
// run the build script
run("go", "run", "build.go")
var (
testEnv map[string]string
srv *MinioServer
err error
)
var srv *MinioServer
if env.minio != "" {
srv, err = NewMinioServer(env.minio)
if err != nil {
@ -182,11 +186,13 @@ func (env *TravisEnvironment) RunTests() {
os.Exit(8)
}
testEnv = minioEnv
for k, v := range minioEnv {
envWithGOPATH[k] = v
}
}
// run the tests and gather coverage information
runWithEnv(testEnv, "gotestcover", "-coverprofile", "all.cov", "./...")
runWithEnv(envWithGOPATH, "gotestcover", "-coverprofile", "all.cov", "restic/...")
runGofmt()