Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lang/golang/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (p *GoParser) collectGoMods(startDir string) error {
p.repo.Modules[name] = newModule(name, rel)
p.modules = append(p.modules, newModuleInfo(name, rel, name))

deps, cgoPkgs, err = getDeps(filepath.Dir(path), p.workDirs)
deps, cgoPkgs, err = getDeps(filepath.Dir(path), p.homePageDir, p.workDirs)
if err != nil {
return err
}
Expand Down Expand Up @@ -192,7 +192,7 @@ type dep struct {
CgoFiles []string `json:"CgoFiles"`
}

func getDeps(dir string, workDirs map[string]bool) (a map[string]string, cgoPkgs map[string]bool, err error) {
func getDeps(dir string, homePageDir string, workDirs map[string]bool) (a map[string]string, cgoPkgs map[string]bool, err error) {
cgoPkgs = make(map[string]bool)
absDir, err := filepath.Abs(dir)
if err != nil {
Expand Down Expand Up @@ -268,9 +268,20 @@ func getDeps(dir string, workDirs map[string]bool) (a map[string]string, cgoPkgs
if strings.HasPrefix(module.Replace.Path, "./") ||
strings.HasPrefix(module.Replace.Path, "../") ||
strings.HasPrefix(module.Replace.Path, "/") {
// local replace
deps[module.Path] = module.Path
// local replace: only treat as a parseable module when the
// target lives inside the repo root. Out-of-repo replace
// targets cannot be walked by collectGoMods, so skip them
// here to avoid downstream nil-module lookups.
replaceAbs := module.Replace.Path
if !filepath.IsAbs(replaceAbs) {
replaceAbs = filepath.Join(dir, replaceAbs)
}
replaceAbs = filepath.Clean(replaceAbs)

rel, relErr := filepath.Rel(homePageDir, replaceAbs)
if relErr == nil && !strings.HasPrefix(rel, "..") {
deps[module.Path] = module.Path
}
} else {
deps[module.Path] = module.Replace.Path + "@" + module.Replace.Version
}
Expand Down Expand Up @@ -298,6 +309,11 @@ func (p *GoParser) ParseRepo() (Repository, error) {
continue
}
mod := p.repo.Modules[lib.name]
if mod == nil {
// Out-of-repo local replace target — collectGoMods didn't
// register it; skip to avoid nil deref.
continue
}
if err := p.ParseModule(mod, filepath.Join(p.homePageDir, mod.Dir)); err != nil {
return p.getRepo(), err
}
Expand Down
Loading