Skip to content

Commit

Permalink
Changed the local code walker to include all go files in the base pat…
Browse files Browse the repository at this point in the history
…h, and not just the app path
  • Loading branch information
[email protected] committed Jul 14, 2020
1 parent ebc9c73 commit c7f4307
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion harness/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func newCompileError(paths *model.RevelContainer, output []byte) *utils.SourceEr
return compileError
}

// RevelMainTemplate template for app/tmp/main.go
// RevelMainTemplate template for app/tmp/run/run.go
const RevelRunTemplate = `// GENERATED CODE - DO NOT EDIT
// This file is the run file for Revel.
// It registers all the controllers and provides details for the Revel server engine to
Expand Down
21 changes: 11 additions & 10 deletions parser2/source_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"go/ast"
"go/token"
"go/scanner"

)

type (
Expand Down Expand Up @@ -111,9 +110,8 @@ func (s *SourceProcessor) addPackages() (err error) {
s.packageList, err = packages.Load(config, allPackages...)
s.log.Info("Loaded modules ", "len results", len(s.packageList), "error", err)


// Now process the files in the aap source folder s.revelContainer.ImportPath + "/...",
err = utils.Walk(s.revelContainer.AppPath, s.processPath)
err = utils.Walk(s.revelContainer.BasePath, s.processPath)
s.log.Info("Loaded apps and modules ", "len results", len(s.packageList), "error", err)
return
}
Expand All @@ -136,8 +134,10 @@ func (s *SourceProcessor) processPath(path string, info os.FileInfo, err error)
pkgImportPath := s.revelContainer.ImportPath
appPath := s.revelContainer.BasePath
if appPath != path {
pkgImportPath = s.revelContainer.ImportPath + "/" + filepath.ToSlash(path[len(appPath)+1:])
pkgImportPath = s.revelContainer.ImportPath + "/" + filepath.ToSlash(path[len(appPath) + 1:])
}
s.log.Info("Processing source package folder", "package", pkgImportPath, "path", path)

// Parse files within the path.
var pkgMap map[string]*ast.Package
fset := token.NewFileSet()
Expand Down Expand Up @@ -173,14 +173,15 @@ func (s *SourceProcessor) processPath(path string, info os.FileInfo, err error)
ast.Print(nil, err)
s.log.Fatal("Failed to parse dir", "error", err)
}

// Skip "main" packages.
delete(pkgMap, "main")

// Ignore packages that end with _test
// These cannot be included in source code that is not generated specifically as a test
for i := range pkgMap {
if len(i) > 6 {
if string(i[len(i)-5:]) == "_test" {
if string(i[len(i) - 5:]) == "_test" {
delete(pkgMap, i)
}
}
Expand All @@ -194,7 +195,7 @@ func (s *SourceProcessor) processPath(path string, info os.FileInfo, err error)
// There should be only one package in this directory.
if len(pkgMap) > 1 {
for i := range pkgMap {
println("Found package ", i)
println("Found duplicate packages in single directory ", i)
}
utils.Logger.Fatal("Most unexpected! Multiple packages in a single directory:", "packages", pkgMap)
}
Expand All @@ -205,10 +206,10 @@ func (s *SourceProcessor) processPath(path string, info os.FileInfo, err error)
p.Fset = fset
for _, pkg := range pkgMap {
p.Name = pkg.Name
s.log.Info("Found package","pkg.Name", pkg.Name,"p.Name", p.PkgPath)
for filename,astFile := range pkg.Files {
p.Syntax = append(p.Syntax,astFile)
p.GoFiles = append(p.GoFiles,filename)
s.log.Info("Found package", "pkg.Name", pkg.Name, "p.Name", p.PkgPath)
for filename, astFile := range pkg.Files {
p.Syntax = append(p.Syntax, astFile)
p.GoFiles = append(p.GoFiles, filename)
}
}
s.packageList = append(s.packageList, p)
Expand Down

0 comments on commit c7f4307

Please sign in to comment.