Skip to content

Commit

Permalink
only change gopath when newGopath not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJi authored and lyyyuna committed Nov 22, 2021
1 parent e30041d commit 1537615
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/build/tmpfolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (b *Build) MvProjectsToTmp() error {
return err
}
b.OriGOPATH = os.Getenv("GOPATH")
if b.IsMod == true {
if b.IsMod {
b.NewGOPATH = ""
} else if b.OriGOPATH == "" {
b.NewGOPATH = b.TmpDir
Expand All @@ -61,7 +61,7 @@ func (b *Build) MvProjectsToTmp() error {
// this kind of project does not have a pkg.Root value
// go 1.11, 1.12 has no pkg.Root,
// so add b.IsMod == false as secondary judgement
if b.Root == "" && b.IsMod == false {
if b.NewGOPATH == "" && b.Root == "" && !b.IsMod {
b.NewGOPATH = b.OriGOPATH
}
log.Infof("New GOPATH: %v", b.NewGOPATH)
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/tmpfolder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ func TestNewDirParseInModProject(t *testing.T) {
// Test #14
func TestLegacyProjectNotInGoPATH(t *testing.T) {
workingDir := filepath.Join(baseDir, "../../tests/samples/simple_gopath_project/src/qiniu.com/simple_gopath_project")
gopath := ""
gopath := "/abc"

fmt.Println(gopath)
os.Setenv("GOPATH", gopath)
os.Setenv("GO111MODULE", "off")

b, _ := NewBuild("", []string{"."}, workingDir, "")
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)
if !strings.HasSuffix(b.NewGOPATH, b.OriGOPATH) {
t.Fatalf("New GOPATH should contains old GOPATH for this kind of project. New: %v, old: %v", b.NewGOPATH, b.OriGOPATH)
}

_, err := os.Stat(filepath.Join(b.TmpDir, "main.go"))
Expand Down

0 comments on commit 1537615

Please sign in to comment.