Skip to content

Commit 7775215

Browse files
committed
allow operator-sdk to run with composed GOPATH
1 parent ab09a3d commit 7775215

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

hack/lib/test_lib.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ function listPkgs() {
33
}
44

55
function listFiles() {
6+
# make it work with composed gopath
7+
for gopath in ${GOPATH//:/ }; do
8+
if [[ "$(pwd)" =~ "$gopath" ]]; then
9+
GOPATH="$gopath"
10+
break
11+
fi
12+
done
613
# pipeline is much faster than for loop
714
listPkgs | xargs -I {} find "${GOPATH}/src/{}" -name '*.go' | grep -v generated
815
}

internal/util/projutil/project_util.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ func CheckAndGetCurrPkg() string {
6767
if len(gopath) == 0 {
6868
log.Fatalf("get current pkg failed: GOPATH env not set")
6969
}
70-
goSrc := filepath.Join(gopath, SrcDir)
71-
70+
var goSrc string
71+
cwdInGopath := false
7272
wd := MustGetwd()
73-
if !strings.HasPrefix(filepath.Dir(wd), goSrc) {
73+
for _, path := range strings.Split(gopath, ":") {
74+
goSrc = filepath.Join(path, SrcDir)
75+
76+
if strings.HasPrefix(filepath.Dir(wd), goSrc) {
77+
cwdInGopath = true
78+
break
79+
}
80+
}
81+
if !cwdInGopath {
7482
log.Fatalf("check current pkg failed: must run from gopath")
7583
}
7684
currPkg := strings.Replace(wd, goSrc+string(filepath.Separator), "", 1)

0 commit comments

Comments
 (0)