This commit is contained in:
lyyyuna 2020-06-14 09:15:48 +08:00
parent 13c7b6ba8c
commit dac858ef07
2 changed files with 20 additions and 0 deletions

View File

@ -45,6 +45,11 @@ func (b *Build) MvProjectsToTmp() {
} else {
b.NewGOPATH = fmt.Sprintf("%v:%v", b.TmpDir, b.OriGOPATH)
}
// fix #14: unable to build project not in GOPATH in legacy mode
// this kind of project does not have a pkg.Root value
if b.Root == "" {
b.NewGOPATH = b.OriGOPATH
}
log.Printf("New GOPATH: %v", b.NewGOPATH)
return
}

View File

@ -79,3 +79,18 @@ func TestNewDirParseInModProject(t *testing.T) {
t.Fatalf("The New GOPATH is wrong. newgopath: %v, tmpdir: %v", b.NewGOPATH, b.TmpDir)
}
}
// Test #14
func TestLegacyProjectNotInGoPATH(t *testing.T) {
workingDir := "../../tests/samples/simple_gopath_project/src/qiniu.com/simple_gopath_project"
gopath := ""
os.Chdir(workingDir)
fmt.Println(gopath)
os.Setenv("GOPATH", gopath)
os.Setenv("GO111MODULE", "off")
b := NewBuild("", ".", "")
if b.OriGOPATH != b.NewGOPATH {
t.Fatalf("New GOPATH should be same with old GOPATH, for this kind of project. New: %v, old: %v", b.NewGOPATH, b.OriGOPATH)
}
}