Skip to content

Commit a8798a0

Browse files
authored
Merge pull request #491 from TarsCloud/fix/lbbniu/tars2go
fix: The first module of the single-file multi-module is generated multiple times
2 parents b34089b + b4bacbc commit a8798a0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tars/tools/tars2go/gencode/gen_go.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ func (g *GenGo) W(v ...string) {
9696
}
9797

9898
func (g *GenGo) genAll() {
99-
if _, ok := fileMap.Load(g.filepath); ok {
99+
g.module.Rename(g.opt.ModuleUpper)
100+
key := g.module.Source + ":" + g.module.Name
101+
if _, ok := fileMap.Load(key); ok {
100102
// already compiled
101103
return
102104
}
103-
fileMap.Store(g.filepath, struct{}{})
105+
fileMap.Store(key, struct{}{})
104106

105-
g.module.Rename(g.opt.ModuleUpper)
106107
g.genInclude(g.module.IncModule)
107108

108109
g.code.Reset()

tars/tools/tars2go/parse/parse.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ func NewParse(opt *options.Options, filePath string, incChain []string) *ast.Mod
3838
filename := path.Base(filePath)
3939
for _, include := range opt.Includes {
4040
include = strings.TrimRight(include, "/")
41-
filePath = include + "/" + filename
42-
if _, err = os.Stat(filePath); err == nil {
41+
newFilePath := include + "/" + filename
42+
if _, err = os.Stat(newFilePath); err == nil {
43+
filePath = newFilePath
4344
break
4445
}
4546
}

0 commit comments

Comments
 (0)