From d8cd308ce1e60a5e8caaf1a24c2ca40bdffa2782 Mon Sep 17 00:00:00 2001 From: tongjingran Date: Mon, 14 Dec 2020 10:05:59 +0800 Subject: [PATCH 1/4] optmise the copy stratgy --- pkg/build/gomodules.go | 18 ---------- pkg/build/gomodules_test.go | 3 +- pkg/build/legacy.go | 65 +++++++++++++++++++++++++++++-------- pkg/build/legacy_test.go | 21 +++++++++--- pkg/build/tmpfolder.go | 4 +-- pkg/cover/cover.go | 15 +++++++-- 6 files changed, 85 insertions(+), 41 deletions(-) diff --git a/pkg/build/gomodules.go b/pkg/build/gomodules.go index 32c9b79..ac9c07c 100644 --- a/pkg/build/gomodules.go +++ b/pkg/build/gomodules.go @@ -20,27 +20,9 @@ import ( "io/ioutil" "path/filepath" - "github.com/otiai10/copy" - log "github.com/sirupsen/logrus" "golang.org/x/mod/modfile" ) -func (b *Build) cpGoModulesProject() { - for _, v := range b.Pkgs { - if v.Name == "main" { - dst := b.TmpDir - src := v.Module.Dir - - if err := copy.Copy(src, dst); err != nil { - log.Errorf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) - } - break - } else { - continue - } - } -} - // updateGoModFile rewrites the go.mod file in the temporary directory, // if it has a 'replace' directive, and the directive has a relative local path // it will be rewritten with a absolute path. diff --git a/pkg/build/gomodules_test.go b/pkg/build/gomodules_test.go index e0e6a6d..c629ec3 100644 --- a/pkg/build/gomodules_test.go +++ b/pkg/build/gomodules_test.go @@ -45,6 +45,7 @@ func TestModProjectCopyWithUnexistedDir(t *testing.T) { Module: &cover.ModulePublic{ Dir: "not exied, ia mas duser", // not real one, should fail copy }, + GoFiles: []string{"empty.go"}, } pkgs["another"] = &cover.Package{} b := &Build{ @@ -52,7 +53,7 @@ func TestModProjectCopyWithUnexistedDir(t *testing.T) { Pkgs: pkgs, } - output := captureOutput(b.cpGoModulesProject) + output := captureOutput(b.cpLegacyProject) assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } diff --git a/pkg/build/legacy.go b/pkg/build/legacy.go index 72f5c55..8583895 100644 --- a/pkg/build/legacy.go +++ b/pkg/build/legacy.go @@ -24,6 +24,7 @@ import ( "github.com/otiai10/copy" "github.com/qiniu/goc/pkg/cover" + "strings" ) func (b *Build) cpLegacyProject() { @@ -37,18 +38,39 @@ func (b *Build) cpLegacyProject() { continue } - if err := copy.Copy(src, dst); err != nil { + if err := b.copyDir(v, b.TmpDir); err != nil { log.Errorf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) } visited[src] = true - b.cpDepPackages(v, visited) + //b.cpDepPackages(v, visited) + } + if b.IsMod { + for _, v := range b.Pkgs { + if v.Name == "main" { + dst := filepath.Join(b.TmpDir, "go.mod") + src := filepath.Join(v.Module.Dir, "go.mod") + if err := copy.Copy(src, dst); err != nil { + log.Errorf("Failed to Copy the go mod file from %v to %v, the error is: %v ", src, dst, err) + } + + dst = filepath.Join(b.TmpDir, "go.sum") + src = filepath.Join(v.Module.Dir, "go.sum") + if err := copy.Copy(src, dst); err != nil && !strings.Contains(err.Error(), "no such file or directory") { + log.Errorf("Failed to Copy the go mod file from %v to %v, the error is: %v ", src, dst, err) + } + break + } else { + continue + } + } } } // only cp dependency in root(current gopath), // skip deps in other GOPATHs +// only used for version before go 1.11.4 func (b *Build) cpDepPackages(pkg *cover.Package, visited map[string]bool) { gopath := pkg.Root for _, dep := range pkg.Deps { @@ -74,18 +96,35 @@ func (b *Build) cpDepPackages(pkg *cover.Package, visited map[string]bool) { } } -func (b *Build) cpNonStandardLegacy() { - for _, v := range b.Pkgs { - if v.Name == "main" { - dst := b.TmpDir - src := v.Dir - - if err := copy.Copy(src, dst); err != nil { - log.Printf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) - } - break +func (b *Build) copyDir(pkg *cover.Package, tmpDir string) error { + fileList := []string{} + dir := pkg.Dir + fileList = append(fileList, pkg.GoFiles...) + fileList = append(fileList, pkg.CompiledGoFiles...) + fileList = append(fileList, pkg.IgnoredGoFiles...) + fileList = append(fileList, pkg.CFiles...) + fileList = append(fileList, pkg.CXXFiles...) + fileList = append(fileList, pkg.MFiles...) + fileList = append(fileList, pkg.HFiles...) + fileList = append(fileList, pkg.FFiles...) + fileList = append(fileList, pkg.SFiles...) + fileList = append(fileList, pkg.SwigCXXFiles...) + fileList = append(fileList, pkg.SwigFiles...) + fileList = append(fileList, pkg.SysoFiles...) + for _, file := range fileList { + p := filepath.Join(dir, file) + var src, root string + if pkg.Root == "" { + root = b.WorkingDir // use workingDir instead when the root is empty. } else { - continue + root = pkg.Root + } + src = strings.TrimPrefix(pkg.Dir, root) // get the relative path of the files + dst := filepath.Join(tmpDir, src, file) // it will adapt the case where src is "" + if err := copy.Copy(p, dst); err != nil { + log.Errorf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) + return err } } + return nil } diff --git a/pkg/build/legacy_test.go b/pkg/build/legacy_test.go index 53f9cc1..1c5f6c6 100644 --- a/pkg/build/legacy_test.go +++ b/pkg/build/legacy_test.go @@ -23,6 +23,7 @@ import ( "github.com/qiniu/goc/pkg/cover" "github.com/stretchr/testify/assert" + "os" ) // copy in cpLegacyProject/cpNonStandardLegacy of invalid src, dst name @@ -32,8 +33,9 @@ func TestLegacyProjectCopyWithUnexistedDir(t *testing.T) { Module: &cover.ModulePublic{ Dir: "not exied, ia mas duser", // not real one, should fail copy }, - Dir: "not exit, iasdfs", - Name: "main", + Dir: "not exit, iasdfs", + Name: "main", + GoFiles: []string{"not_exist.go"}, } pkgs["another"] = &cover.Package{} b := &Build{ @@ -43,9 +45,6 @@ func TestLegacyProjectCopyWithUnexistedDir(t *testing.T) { output := captureOutput(b.cpLegacyProject) assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) - - output = captureOutput(b.cpNonStandardLegacy) - assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } // copy in cpDepPackages of invalid dst name @@ -69,3 +68,15 @@ func TestDepPackagesCopyWithInvalidDir(t *testing.T) { }) assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } + +func TestCopyDir(t *testing.T) { + wd, _ := os.Getwd() + pkg := &cover.Package{Dir: wd, Root: wd, GoFiles: []string{"build.go", "legacy.go"}, CgoFiles: []string{"run.go"}} + tmpDir := "/tmp/test/" + b := &Build{ + WorkingDir: "empty", + } + assert.NoError(t, os.MkdirAll(tmpDir, os.ModePerm)) + defer os.RemoveAll(tmpDir) + assert.NoError(t, b.copyDir(pkg, tmpDir)) +} diff --git a/pkg/build/tmpfolder.go b/pkg/build/tmpfolder.go index 9cc8fbe..e4687ef 100644 --- a/pkg/build/tmpfolder.go +++ b/pkg/build/tmpfolder.go @@ -99,7 +99,7 @@ func (b *Build) mvProjectsToTmp() error { if b.IsMod == false && b.Root != "" { b.cpLegacyProject() } else if b.IsMod == true { // go 1.11, 1.12 has no Build.Root - b.cpGoModulesProject() + b.cpLegacyProject() updated, newGoModContent, err := b.updateGoModFile() if err != nil { return fmt.Errorf("fail to generate new go.mod: %v", err) @@ -114,7 +114,7 @@ func (b *Build) mvProjectsToTmp() error { } } else if b.IsMod == false && b.Root == "" { b.TmpWorkingDir = b.TmpDir - b.cpNonStandardLegacy() + b.cpLegacyProject() } else { return fmt.Errorf("unknown project type: %w", ErrShouldNotReached) } diff --git a/pkg/cover/cover.go b/pkg/cover/cover.go index 742e352..f9fa12d 100644 --- a/pkg/cover/cover.go +++ b/pkg/cover/cover.go @@ -85,8 +85,19 @@ type Package struct { DepOnly bool `json:"DepOnly,omitempty"` // package is only a dependency, not explicitly listed // Source files - GoFiles []string `json:"GoFiles,omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) - CgoFiles []string `json:"CgoFiles,omitempty"` // .go source files that import "C" + GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) + CgoFiles []string `json:",omitempty"` // .go source files that import "C" + CompiledGoFiles []string `json:",omitempty"` // .go output from running cgo on CgoFiles + IgnoredGoFiles []string `json:",omitempty"` // .go source files ignored due to build constraints + CFiles []string `json:",omitempty"` // .c source files + CXXFiles []string `json:",omitempty"` // .cc, .cpp and .cxx source files + MFiles []string `json:",omitempty"` // .m source files + HFiles []string `json:",omitempty"` // .h, .hh, .hpp and .hxx source files + FFiles []string `json:",omitempty"` // .f, .F, .for and .f90 Fortran source files + SFiles []string `json:",omitempty"` // .s source files + SwigFiles []string `json:",omitempty"` // .swig files + SwigCXXFiles []string `json:",omitempty"` // .swigcxx files + SysoFiles []string `json:",omitempty"` // .syso system object files added to package // Dependency information Deps []string `json:"Deps,omitempty"` // all (recursively) imported dependencies From 1fb530c9abd4abe7c8f7fdb87f9bd0a4bc93ebdf Mon Sep 17 00:00:00 2001 From: tongjingran Date: Mon, 14 Dec 2020 20:16:01 +0800 Subject: [PATCH 2/4] fix newGopath set & target name --- pkg/build/build.go | 7 +++++-- pkg/build/legacy.go | 41 +++++-------------------------------- pkg/build/legacy_test.go | 26 ++--------------------- pkg/build/tmpfolder.go | 7 ------- pkg/build/tmpfolder_test.go | 2 +- 5 files changed, 13 insertions(+), 70 deletions(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index 052c00d..f4edb55 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -133,8 +133,11 @@ func (b *Build) determineOutputDir(outputDir string) (string, error) { targetName := "" for _, pkg := range b.Pkgs { if pkg.Name == "main" { - _, file := filepath.Split(pkg.Target) - targetName = file + if pkg.Target != ""{ + targetName = filepath.Base(pkg.Target) + }else { + targetName = filepath.Base(pkg.Dir) + } break } } diff --git a/pkg/build/legacy.go b/pkg/build/legacy.go index 8583895..6eca135 100644 --- a/pkg/build/legacy.go +++ b/pkg/build/legacy.go @@ -17,14 +17,13 @@ package build import ( - "os" "path/filepath" + "strings" log "github.com/sirupsen/logrus" "github.com/otiai10/copy" "github.com/qiniu/goc/pkg/cover" - "strings" ) func (b *Build) cpLegacyProject() { @@ -38,13 +37,11 @@ func (b *Build) cpLegacyProject() { continue } - if err := b.copyDir(v, b.TmpDir); err != nil { + if err := b.copyDir(v); err != nil { log.Errorf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) } visited[src] = true - - //b.cpDepPackages(v, visited) } if b.IsMod { for _, v := range b.Pkgs { @@ -68,35 +65,7 @@ func (b *Build) cpLegacyProject() { } } -// only cp dependency in root(current gopath), -// skip deps in other GOPATHs -// only used for version before go 1.11.4 -func (b *Build) cpDepPackages(pkg *cover.Package, visited map[string]bool) { - gopath := pkg.Root - for _, dep := range pkg.Deps { - src := filepath.Join(gopath, "src", dep) - // Check if copied - if _, ok := visited[src]; ok { - // Skip if already copied - continue - } - // Check if we can found in the root gopath - _, err := os.Stat(src) - if err != nil { - continue - } - - dst := filepath.Join(b.TmpDir, "src", dep) - - if err := copy.Copy(src, dst); err != nil { - log.Errorf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) - } - - visited[src] = true - } -} - -func (b *Build) copyDir(pkg *cover.Package, tmpDir string) error { +func (b *Build) copyDir(pkg *cover.Package) error { fileList := []string{} dir := pkg.Dir fileList = append(fileList, pkg.GoFiles...) @@ -119,8 +88,8 @@ func (b *Build) copyDir(pkg *cover.Package, tmpDir string) error { } else { root = pkg.Root } - src = strings.TrimPrefix(pkg.Dir, root) // get the relative path of the files - dst := filepath.Join(tmpDir, src, file) // it will adapt the case where src is "" + src = strings.TrimPrefix(pkg.Dir, root) // get the relative path of the files + dst := filepath.Join(b.TmpDir, src, file) // it will adapt the case where src is "" if err := copy.Copy(p, dst); err != nil { log.Errorf("Failed to Copy the folder from %v to %v, the error is: %v ", src, dst, err) return err diff --git a/pkg/build/legacy_test.go b/pkg/build/legacy_test.go index 1c5f6c6..cb786ed 100644 --- a/pkg/build/legacy_test.go +++ b/pkg/build/legacy_test.go @@ -17,7 +17,6 @@ package build import ( - "path/filepath" "strings" "testing" @@ -47,36 +46,15 @@ func TestLegacyProjectCopyWithUnexistedDir(t *testing.T) { assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } -// copy in cpDepPackages of invalid dst name -func TestDepPackagesCopyWithInvalidDir(t *testing.T) { - gopath := filepath.Join(baseDir, "../../tests/samples/simple_gopath_project") - pkg := &cover.Package{ - Module: &cover.ModulePublic{ - Dir: "not exied, ia mas duser", - }, - Root: gopath, - Deps: []string{"qiniu.com", "ddfee 2344234"}, - } - b := &Build{ - TmpDir: "/", // "/" is invalid dst in Linux, it should fail - } - - output := captureOutput(func() { - visited := make(map[string]bool) - - b.cpDepPackages(pkg, visited) - }) - assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) -} - func TestCopyDir(t *testing.T) { wd, _ := os.Getwd() pkg := &cover.Package{Dir: wd, Root: wd, GoFiles: []string{"build.go", "legacy.go"}, CgoFiles: []string{"run.go"}} tmpDir := "/tmp/test/" b := &Build{ WorkingDir: "empty", + TmpDir: tmpDir, } assert.NoError(t, os.MkdirAll(tmpDir, os.ModePerm)) defer os.RemoveAll(tmpDir) - assert.NoError(t, b.copyDir(pkg, tmpDir)) + assert.NoError(t, b.copyDir(pkg)) } diff --git a/pkg/build/tmpfolder.go b/pkg/build/tmpfolder.go index e4687ef..95b9cf5 100644 --- a/pkg/build/tmpfolder.go +++ b/pkg/build/tmpfolder.go @@ -57,13 +57,6 @@ func (b *Build) MvProjectsToTmp() error { } 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 - // 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 - } log.Infof("New GOPATH: %v", b.NewGOPATH) return nil } diff --git a/pkg/build/tmpfolder_test.go b/pkg/build/tmpfolder_test.go index 2183280..cf311e6 100644 --- a/pkg/build/tmpfolder_test.go +++ b/pkg/build/tmpfolder_test.go @@ -95,7 +95,7 @@ func TestLegacyProjectNotInGoPATH(t *testing.T) { os.Setenv("GO111MODULE", "off") b, _ := NewBuild("", []string{"."}, workingDir, "") - if b.OriGOPATH != b.NewGOPATH { + if !strings.Contains(b.NewGOPATH,b.OriGOPATH) { t.Fatalf("New GOPATH should be same with old GOPATH, for this kind of project. New: %v, old: %v", b.NewGOPATH, b.OriGOPATH) } From 24938476615c034edfdbf5d57ee9c45b89ea75ab Mon Sep 17 00:00:00 2001 From: tongjingran Date: Tue, 15 Dec 2020 20:38:18 +0800 Subject: [PATCH 3/4] add ut --- pkg/build/build.go | 4 ++-- pkg/build/legacy_test.go | 22 ++++++++++++++++++++++ pkg/build/tmpfolder.go | 2 -- pkg/build/tmpfolder_test.go | 35 ++++++++++++++++++++++++++++++----- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index f4edb55..4fcbe40 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -133,9 +133,9 @@ func (b *Build) determineOutputDir(outputDir string) (string, error) { targetName := "" for _, pkg := range b.Pkgs { if pkg.Name == "main" { - if pkg.Target != ""{ + if pkg.Target != "" { targetName = filepath.Base(pkg.Target) - }else { + } else { targetName = filepath.Base(pkg.Dir) } break diff --git a/pkg/build/legacy_test.go b/pkg/build/legacy_test.go index cb786ed..a6a01dd 100644 --- a/pkg/build/legacy_test.go +++ b/pkg/build/legacy_test.go @@ -46,6 +46,28 @@ func TestLegacyProjectCopyWithUnexistedDir(t *testing.T) { assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } +// copy goMod project without go.mod +func TestGoModProjectCopyWithUnexistedModFile(t *testing.T) { + pkgs := make(map[string]*cover.Package) + pkgs["main"] = &cover.Package{ + Module: &cover.ModulePublic{ + Dir: "not exied, ia mas duser", // not real one, should fail copy + }, + Dir: "not exit, iasdfs", + Name: "main", + } + pkgs["another"] = &cover.Package{} + b := &Build{ + TmpDir: "sdfsfev2234444", // not real one, should fail copy + Pkgs: pkgs, + IsMod: true, + } + + output := captureOutput(b.cpLegacyProject) + assert.Equal(t, strings.Contains(output, "Failed to Copy the go mod file"), true) +} + +// copy needed files to tmpDir func TestCopyDir(t *testing.T) { wd, _ := os.Getwd() pkg := &cover.Package{Dir: wd, Root: wd, GoFiles: []string{"build.go", "legacy.go"}, CgoFiles: []string{"run.go"}} diff --git a/pkg/build/tmpfolder.go b/pkg/build/tmpfolder.go index 95b9cf5..3c6a8f1 100644 --- a/pkg/build/tmpfolder.go +++ b/pkg/build/tmpfolder.go @@ -108,8 +108,6 @@ func (b *Build) mvProjectsToTmp() error { } else if b.IsMod == false && b.Root == "" { b.TmpWorkingDir = b.TmpDir b.cpLegacyProject() - } else { - return fmt.Errorf("unknown project type: %w", ErrShouldNotReached) } log.Infof("New workingdir in tmp directory in: %v", b.TmpWorkingDir) diff --git a/pkg/build/tmpfolder_test.go b/pkg/build/tmpfolder_test.go index cf311e6..a837366 100644 --- a/pkg/build/tmpfolder_test.go +++ b/pkg/build/tmpfolder_test.go @@ -23,6 +23,7 @@ import ( "strings" "testing" + "github.com/qiniu/goc/pkg/cover" "github.com/stretchr/testify/assert" ) @@ -95,7 +96,7 @@ func TestLegacyProjectNotInGoPATH(t *testing.T) { os.Setenv("GO111MODULE", "off") b, _ := NewBuild("", []string{"."}, workingDir, "") - if !strings.Contains(b.NewGOPATH,b.OriGOPATH) { + if !strings.Contains(b.NewGOPATH, b.OriGOPATH) { t.Fatalf("New GOPATH should be same with old GOPATH, for this kind of project. New: %v, old: %v", b.NewGOPATH, b.OriGOPATH) } @@ -105,13 +106,32 @@ func TestLegacyProjectNotInGoPATH(t *testing.T) { } } -// test traversePkgsList error case -func TestTraversePkgsList(t *testing.T) { +// test mvProjectsToTmp failed by traversePkgsList error +func TestMvProjectsToTmpFailByTraversePkgsList(t *testing.T) { b := &Build{ Pkgs: nil, } - _, _, err := b.traversePkgsList() - assert.EqualError(t, err, ErrShouldNotReached.Error()) + err := b.mvProjectsToTmp() + assert.Contains(t, err.Error(), ErrShouldNotReached.Error()) +} + +// test mvProjectsToTmp failed by getTmpwd error +func TestMvProjectsToTmpFailByGetTmpwd(t *testing.T) { + pkgs := make(map[string]*cover.Package) + pkgs["main"] = &cover.Package{ + Module: &cover.ModulePublic{ + Dir: "just for test", + Path: "just for test", + }, + Dir: "not exist", + Name: "main", + } + b := &Build{ + Pkgs: pkgs, + WorkingDir: "not exist", + } + err := b.mvProjectsToTmp() + assert.Contains(t, err.Error(), ErrGocShouldExecInProject.Error()) } // test getTmpwd error case @@ -148,3 +168,8 @@ func TestFindWhereToInstall(t *testing.T) { expectedPlace := filepath.Join(os.Getenv("HOME"), "go", "bin") assert.Equal(t, placeToInstall, expectedPlace) } + +func TestMvProjectsToTmp(t *testing.T) { + b := &Build{TmpDir: "/tmp/test"} + fmt.Println(b.MvProjectsToTmp()) +} From a72ede39bd169fe25aa5db2ca708897a2ea892a9 Mon Sep 17 00:00:00 2001 From: tongjingran Date: Fri, 18 Dec 2020 19:54:46 +0800 Subject: [PATCH 4/4] change copy function name --- pkg/build/gomodules_test.go | 2 +- pkg/build/legacy.go | 2 +- pkg/build/legacy_test.go | 6 +++--- pkg/build/tmpfolder.go | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/build/gomodules_test.go b/pkg/build/gomodules_test.go index c629ec3..38d7e05 100644 --- a/pkg/build/gomodules_test.go +++ b/pkg/build/gomodules_test.go @@ -53,7 +53,7 @@ func TestModProjectCopyWithUnexistedDir(t *testing.T) { Pkgs: pkgs, } - output := captureOutput(b.cpLegacyProject) + output := captureOutput(b.cpProject) assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } diff --git a/pkg/build/legacy.go b/pkg/build/legacy.go index 6eca135..4b47fda 100644 --- a/pkg/build/legacy.go +++ b/pkg/build/legacy.go @@ -26,7 +26,7 @@ import ( "github.com/qiniu/goc/pkg/cover" ) -func (b *Build) cpLegacyProject() { +func (b *Build) cpProject() { visited := make(map[string]bool) for k, v := range b.Pkgs { dst := filepath.Join(b.TmpDir, "src", k) diff --git a/pkg/build/legacy_test.go b/pkg/build/legacy_test.go index a6a01dd..48bfd6d 100644 --- a/pkg/build/legacy_test.go +++ b/pkg/build/legacy_test.go @@ -25,7 +25,7 @@ import ( "os" ) -// copy in cpLegacyProject/cpNonStandardLegacy of invalid src, dst name +// copy in cpProject of invalid src, dst name func TestLegacyProjectCopyWithUnexistedDir(t *testing.T) { pkgs := make(map[string]*cover.Package) pkgs["main"] = &cover.Package{ @@ -42,7 +42,7 @@ func TestLegacyProjectCopyWithUnexistedDir(t *testing.T) { Pkgs: pkgs, } - output := captureOutput(b.cpLegacyProject) + output := captureOutput(b.cpProject) assert.Equal(t, strings.Contains(output, "Failed to Copy"), true) } @@ -63,7 +63,7 @@ func TestGoModProjectCopyWithUnexistedModFile(t *testing.T) { IsMod: true, } - output := captureOutput(b.cpLegacyProject) + output := captureOutput(b.cpProject) assert.Equal(t, strings.Contains(output, "Failed to Copy the go mod file"), true) } diff --git a/pkg/build/tmpfolder.go b/pkg/build/tmpfolder.go index 3c6a8f1..ee76c9d 100644 --- a/pkg/build/tmpfolder.go +++ b/pkg/build/tmpfolder.go @@ -90,9 +90,9 @@ func (b *Build) mvProjectsToTmp() error { // known cases: // 1. a legacy project, but not in any GOPATH, will cause the b.Root == "" if b.IsMod == false && b.Root != "" { - b.cpLegacyProject() + b.cpProject() } else if b.IsMod == true { // go 1.11, 1.12 has no Build.Root - b.cpLegacyProject() + b.cpProject() updated, newGoModContent, err := b.updateGoModFile() if err != nil { return fmt.Errorf("fail to generate new go.mod: %v", err) @@ -107,7 +107,7 @@ func (b *Build) mvProjectsToTmp() error { } } else if b.IsMod == false && b.Root == "" { b.TmpWorkingDir = b.TmpDir - b.cpLegacyProject() + b.cpProject() } log.Infof("New workingdir in tmp directory in: %v", b.TmpWorkingDir)