mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 08:14:03 +00:00
Update build.go and run_integration_tests.go
This commit is contained in:
parent
841326d713
commit
96e66bb3e9
34
build.go
34
build.go
@ -30,7 +30,11 @@ func specialDir(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
base := filepath.Base(name)
|
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.
|
// 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.
|
// 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...)
|
args = append([]string{"build"}, args...)
|
||||||
cmd := exec.Command("go", args...)
|
cmd := exec.Command("go", args...)
|
||||||
cmd.Env = append(cleanEnv(), "GOPATH="+gopath)
|
cmd.Env = append(cleanEnv(), "GOPATH="+gopath)
|
||||||
|
cmd.Dir = cwd
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
verbosePrintf("go %s\n", args)
|
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.
|
// 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...)
|
args = append([]string{"test"}, args...)
|
||||||
cmd := exec.Command("go", args...)
|
cmd := exec.Command("go", args...)
|
||||||
cmd.Env = append(cleanEnv(), "GOPATH="+gopath)
|
cmd.Env = append(cleanEnv(), "GOPATH="+gopath)
|
||||||
|
cmd.Dir = cwd
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
verbosePrintf("go %s\n", args)
|
verbosePrintf("go %s\n", args)
|
||||||
@ -293,6 +299,7 @@ func main() {
|
|||||||
runTests = true
|
runTests = true
|
||||||
case "-h":
|
case "-h":
|
||||||
showUsage(os.Stdout)
|
showUsage(os.Stdout)
|
||||||
|
return
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "Error: unknown option %q\n\n", arg)
|
fmt.Fprintf(os.Stderr, "Error: unknown option %q\n\n", arg)
|
||||||
showUsage(os.Stderr)
|
showUsage(os.Stderr)
|
||||||
@ -322,11 +329,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verbosePrintf("create GOPATH at %v\n", gopath)
|
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)
|
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 {
|
if err = updateGopath(gopath, vendor, ""); err != nil {
|
||||||
die("copying files from %v to %v failed: %v\n", root, gopath, err)
|
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" {
|
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()
|
version := getVersion()
|
||||||
compileTime := time.Now().Format(timeFormat)
|
compileTime := time.Now().Format(timeFormat)
|
||||||
constants := Constants{`main.compiledAt`: compileTime}
|
constants := Constants{`main.compiledAt`: compileTime}
|
||||||
@ -358,10 +372,10 @@ func main() {
|
|||||||
args := []string{
|
args := []string{
|
||||||
"-tags", strings.Join(buildTags, " "),
|
"-tags", strings.Join(buildTags, " "),
|
||||||
"-ldflags", ldflags,
|
"-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 {
|
if err != nil {
|
||||||
die("build failed: %v\n", err)
|
die("build failed: %v\n", err)
|
||||||
}
|
}
|
||||||
@ -369,7 +383,7 @@ func main() {
|
|||||||
if runTests {
|
if runTests {
|
||||||
verbosePrintf("running tests\n")
|
verbosePrintf("running tests\n")
|
||||||
|
|
||||||
err = test(gopath, "github.com/restic/restic/...")
|
err = test(filepath.Join(gopath, "src"), gopath, "restic/...")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die("running tests failed: %v\n", err)
|
die("running tests failed: %v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -154,27 +154,31 @@ func (env *TravisEnvironment) RunTests() {
|
|||||||
os.Setenv("RESTIC_TEST_FUSE", "0")
|
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 {
|
if *runCrossCompile {
|
||||||
// compile for all target architectures with tags
|
// compile for all target architectures with tags
|
||||||
for _, tags := range []string{"release", "debug"} {
|
for _, tags := range []string{"release", "debug"} {
|
||||||
run("gox", "-verbose",
|
runWithEnv(envWithGOPATH, "gox", "-verbose",
|
||||||
"-os", strings.Join(env.goxOS, " "),
|
"-os", strings.Join(env.goxOS, " "),
|
||||||
"-arch", strings.Join(env.goxArch, " "),
|
"-arch", strings.Join(env.goxArch, " "),
|
||||||
"-tags", tags,
|
"-tags", tags,
|
||||||
"-output", "/tmp/{{.Dir}}_{{.OS}}_{{.Arch}}",
|
"-output", "/tmp/{{.Dir}}_{{.OS}}_{{.Arch}}",
|
||||||
"./cmd/restic")
|
"restic/cmd/restic")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the build script
|
// run the build script
|
||||||
run("go", "run", "build.go")
|
run("go", "run", "build.go")
|
||||||
|
|
||||||
var (
|
var srv *MinioServer
|
||||||
testEnv map[string]string
|
|
||||||
srv *MinioServer
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if env.minio != "" {
|
if env.minio != "" {
|
||||||
srv, err = NewMinioServer(env.minio)
|
srv, err = NewMinioServer(env.minio)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -182,11 +186,13 @@ func (env *TravisEnvironment) RunTests() {
|
|||||||
os.Exit(8)
|
os.Exit(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
testEnv = minioEnv
|
for k, v := range minioEnv {
|
||||||
|
envWithGOPATH[k] = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the tests and gather coverage information
|
// run the tests and gather coverage information
|
||||||
runWithEnv(testEnv, "gotestcover", "-coverprofile", "all.cov", "./...")
|
runWithEnv(envWithGOPATH, "gotestcover", "-coverprofile", "all.cov", "restic/...")
|
||||||
|
|
||||||
runGofmt()
|
runGofmt()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user