Skip to content

Commit

Permalink
fix duplicate import of global var path in symlink file
Browse files Browse the repository at this point in the history
eg. main.go -> cmd/myproject/run.go
When run `goc build .`, redeclared error will be reported.
In main.go, the global var path is duplicated imported as follows:
`package main; import . "myproject/src/gocbuild235e80d276dc"; import . "myproject/src/gocbuild234e80d276dc"`
  • Loading branch information
IfanTsai committed Sep 27, 2023
1 parent 46eb9e6 commit bccdb98
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/cover/internal/tool/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package tool

import (
"bytes"
"strings"

// "flag"
"fmt"
"go/ast"
Expand Down Expand Up @@ -342,6 +344,8 @@ func Annotate(name string, mode string, varVar string, globalCoverVarImportPath

if bytes.Equal(content, newContent) {
log.Info("no cover var injected for: ", name)
} else if strings.Contains(string(file.content), globalCoverVarImportPath) {
log.Info("global cover var already imported for: ", name)
} else {
// reback to the beginning
file.astFile, _ = parser.ParseFile(fset, name, content, parser.ParseComments)
Expand Down

0 comments on commit bccdb98

Please sign in to comment.