Skip to content

Commit

Permalink
fix: The first module of the single-file multi-module is generated mu…
Browse files Browse the repository at this point in the history
…ltiple times
  • Loading branch information
lbbniu committed Jun 25, 2023
1 parent b34089b commit b4bacbc
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions tars/tools/tars2go/gencode/gen_go.go
Original file line number Diff line number Diff line change
@@ -96,13 +96,14 @@ func (g *GenGo) W(v ...string) {
}

func (g *GenGo) genAll() {
if _, ok := fileMap.Load(g.filepath); ok {
g.module.Rename(g.opt.ModuleUpper)
key := g.module.Source + ":" + g.module.Name
if _, ok := fileMap.Load(key); ok {
// already compiled
return
}
fileMap.Store(g.filepath, struct{}{})
fileMap.Store(key, struct{}{})

g.module.Rename(g.opt.ModuleUpper)
g.genInclude(g.module.IncModule)

g.code.Reset()
5 changes: 3 additions & 2 deletions tars/tools/tars2go/parse/parse.go
Original file line number Diff line number Diff line change
@@ -38,8 +38,9 @@ func NewParse(opt *options.Options, filePath string, incChain []string) *ast.Mod
filename := path.Base(filePath)
for _, include := range opt.Includes {
include = strings.TrimRight(include, "/")
filePath = include + "/" + filename
if _, err = os.Stat(filePath); err == nil {
newFilePath := include + "/" + filename
if _, err = os.Stat(newFilePath); err == nil {
filePath = newFilePath
break
}
}

0 comments on commit b4bacbc

Please sign in to comment.