Skip to content

Commit

Permalink
Fix compilation for old versions of go
Browse files Browse the repository at this point in the history
  • Loading branch information
sevlyar committed May 4, 2019
1 parent 2ee3304 commit dcccaf7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ language: go

go:
- 1.3
- 1.5
- tip

before_install:
- go get -t -v ./...

script:
- go test -coverprofile=coverage.txt -covermode=atomic
- go test -v -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
80 changes: 80 additions & 0 deletions compilation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package daemon

import (
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"testing"
)

func TestCompilation(t *testing.T) {
if testing.Short() {
t.Skip("short mode")
}
if !requireMinor(5) {
t.Skip(runtime.Version(), "cross-compilation requires compiler bootstrapping")
}

pairs := []string{
"darwin/386",
"darwin/amd64",
"dragonfly/amd64",
"freebsd/386",
"freebsd/amd64",
"freebsd/arm",
"linux/386",
"linux/amd64",
"linux/arm",
"linux/arm64",
"netbsd/386",
"netbsd/amd64",
"netbsd/arm",
"openbsd/386",
"openbsd/amd64",
"openbsd/arm",
"solaris/amd64",
"windows/386",
"windows/amd64",

// TODO(yar): support plan9
//"plan9/386",
//"plan9/amd64",
//"plan9/arm",
}

env := os.Environ()
for i := range pairs {
p := pairs[i]
pair := strings.Split(p, "/")
goos, goarch := pair[0], pair[1]
if goos == "solaris" && !requireMinor(7) {
t.Log("skip, solaris requires at least go1.7")
continue
}
cmd := exec.Command("go", "build", "./")
env := append([]string(nil), env...)
cmd.Env = append(env, "GOOS="+goos, "GOARCH="+goarch)
out, err := cmd.CombinedOutput()
if len(out) > 0 {
t.Log(p, "\n", string(out))
}
if err != nil {
t.Error(p, err)
}
}
}

func requireMinor(minor int) bool {
str := runtime.Version()
if !strings.HasPrefix(str, "go1.") {
return true
}
str = strings.TrimPrefix(str, "go1.")
ver, err := strconv.Atoi(str)
if err != nil {
return false
}
return ver >= minor
}
1 change: 1 addition & 0 deletions syscall_dup.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// +build !linux !arm64
// +build !windows
// +build go1.7

package daemon

Expand Down
13 changes: 13 additions & 0 deletions syscall_dup_pre17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !linux !arm64
// +build !windows
// +build !go1.7

package daemon

import (
"syscall"
)

func syscallDup(oldfd int, newfd int) (err error) {
return syscall.Dup2(oldfd, newfd)
}

0 comments on commit dcccaf7

Please sign in to comment.