fix go1.11 go1.12 pkg.Root issue

This commit is contained in:
lyyyuna 2020-06-16 14:59:01 +08:00
parent 272e4a858b
commit 40bdcf21d4
2 changed files with 5 additions and 2 deletions

View File

@ -36,6 +36,7 @@ type Build struct {
TmpWorkingDir string // the working directory in the temporary directory, which is corresponding to the current directory in the project directory TmpWorkingDir string // the working directory in the temporary directory, which is corresponding to the current directory in the project directory
IsMod bool // determine whether it is a Mod project IsMod bool // determine whether it is a Mod project
Root string Root string
// go 1.11, go 1.12 has no Root
// Project Root: // Project Root:
// 1. legacy, root == GOPATH // 1. legacy, root == GOPATH
// 2. mod, root == go.mod Dir // 2. mod, root == go.mod Dir

View File

@ -48,7 +48,9 @@ func (b *Build) MvProjectsToTmp() {
} }
// fix #14: unable to build project not in GOPATH in legacy mode // fix #14: unable to build project not in GOPATH in legacy mode
// this kind of project does not have a pkg.Root value // this kind of project does not have a pkg.Root value
if b.Root == "" { // go 1.11, 1.12 has no pkg.Root,
// so add b.IsMod == false as secondary judgement
if b.Root == "" && b.IsMod == false {
b.NewGOPATH = b.OriGOPATH b.NewGOPATH = b.OriGOPATH
} }
log.Printf("New GOPATH: %v", b.NewGOPATH) log.Printf("New GOPATH: %v", b.NewGOPATH)
@ -90,7 +92,7 @@ func (b *Build) mvProjectsToTmp() error {
// 1. a legacy project, but not in any GOPATH, will cause the b.Root == "" // 1. a legacy project, but not in any GOPATH, will cause the b.Root == ""
if b.IsMod == false && b.Root != "" { if b.IsMod == false && b.Root != "" {
b.cpLegacyProject() b.cpLegacyProject()
} else if b.IsMod == true && b.Root != "" { } else if b.IsMod == true { // go 1.11, 1.12 has no Build.Root
b.cpGoModulesProject() b.cpGoModulesProject()
} else if b.IsMod == false && b.Root == "" { } else if b.IsMod == false && b.Root == "" {
b.TmpWorkingDir = b.TmpDir b.TmpWorkingDir = b.TmpDir