Improve Windows compatibility (#118)
- Use travis build matrix to test on Windows and macOS - Make utility func compatible with host OS. Use filepath package to manipulate path strings for stripping $GOPATH from working directory. - Delegate to go/build pkg for getting Go paths Co-authored-by: Mike Lee <mike.lee@safeguardproperties.com> Co-authored-by: Lucas Bremgartner <lucas@bremis.ch>
This commit is contained in:
parent
072c0cd09b
commit
7615cbe602
19
.travis.yml
19
.travis.yml
@ -6,11 +6,20 @@ branches:
|
|||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
go:
|
jobs:
|
||||||
- 1.11.x
|
include:
|
||||||
- 1.12.x
|
- os: linux
|
||||||
- 1.13.x
|
go: 1.11.x
|
||||||
- tip
|
- os: linux
|
||||||
|
go: 1.12.x
|
||||||
|
- os: linux
|
||||||
|
go: 1.13.x
|
||||||
|
- os: linux
|
||||||
|
go: tip
|
||||||
|
- os: osx
|
||||||
|
go: 1.13.x
|
||||||
|
- os: windows
|
||||||
|
go: 1.13.x
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- go get golang.org/x/lint/golint
|
- go get golang.org/x/lint/golint
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go/build"
|
||||||
"go/format"
|
"go/format"
|
||||||
"go/types"
|
"go/types"
|
||||||
"io"
|
"io"
|
||||||
@ -355,18 +356,15 @@ func stripVendorPath(p string) string {
|
|||||||
return strings.TrimLeft(path.Join(parts[1:]...), "/")
|
return strings.TrimLeft(path.Join(parts[1:]...), "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// stripGopath takes the directory to a package and remove the gopath to get the
|
// stripGopath takes the directory to a package and removes the
|
||||||
// canonical package name.
|
// $GOPATH/src path to get the canonical package name.
|
||||||
//
|
|
||||||
// taken from https://github.com/ernesto-jimenez/gogen
|
|
||||||
// Copyright (c) 2015 Ernesto Jiménez
|
|
||||||
func stripGopath(p string) string {
|
func stripGopath(p string) string {
|
||||||
for _, gopath := range gopaths() {
|
for _, srcDir := range build.Default.SrcDirs() {
|
||||||
p = strings.TrimPrefix(p, path.Join(gopath, "src")+"/")
|
rel, err := filepath.Rel(srcDir, p)
|
||||||
|
if err != nil || strings.HasPrefix(rel, "..") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return filepath.ToSlash(rel)
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func gopaths() []string {
|
|
||||||
return strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator))
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user