Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 3242df4

Browse files
author
Sauyon Lee
committed
Use package root directory to find go.mod files
1 parent b2fef01 commit 3242df4

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

extractor/extractor.go

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -178,55 +178,32 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
178178
}
179179

180180
extractPackage(pkg, &wg, goroutineSem, fdSem)
181-
return
182-
}
183181

184-
log.Printf("Skipping dependency package %s.", pkg.PkgPath)
185-
})
182+
if pkgRoots[pkg.PkgPath] != "" {
183+
modPath := filepath.Join(pkgRoots[pkg.PkgPath], "go.mod")
184+
if util.FileExists(modPath) {
185+
log.Printf("Extracting %s", modPath)
186+
start := time.Now()
186187

187-
wg.Wait()
188-
189-
log.Println("Done extracting packages.")
190-
log.Println("Starting to extract go.mod files.")
191-
192-
cwd, err := os.Getwd()
193-
if err != nil {
194-
log.Printf("Warning: unable to get working directory: %s", err.Error())
195-
log.Println("Skipping go.mod extraction")
196-
}
197-
rcwd, err := filepath.EvalSymlinks(cwd)
198-
if err == nil {
199-
cwd = rcwd
200-
}
201-
202-
goModPaths := make([]string, 0, 10)
188+
err := extractGoMod(modPath)
189+
if err != nil {
190+
log.Printf("Failed to extract go.mod: %s", err.Error())
191+
}
203192

204-
filepath.Walk(cwd, func(path string, info os.FileInfo, err error) error {
205-
if filepath.Base(path) == "go.mod" && info != nil && info.Mode().IsRegular() {
206-
if err != nil {
207-
log.Printf("Found go.mod with path %s, but encountered error %s", path, err.Error())
193+
end := time.Since(start)
194+
log.Printf("Done extracting %s (%dms)", modPath, end.Nanoseconds()/1000000)
195+
}
208196
}
209197

210-
goModPaths = append(goModPaths, path)
198+
return
211199
}
212200

213-
return nil
201+
log.Printf("Skipping dependency package %s.", pkg.PkgPath)
214202
})
215203

216-
for _, path := range goModPaths {
217-
log.Printf("Extracting %s", path)
218-
start := time.Now()
219-
220-
err := extractGoMod(path)
221-
if err != nil {
222-
log.Printf("Failed to extract go.mod: %s", err.Error())
223-
}
224-
225-
end := time.Since(start)
226-
log.Printf("Done extracting %s (%dms)", path, end.Nanoseconds()/1000000)
227-
}
204+
wg.Wait()
228205

229-
log.Println("Done extracting go.mod files.")
206+
log.Println("Done extracting packages.")
230207

231208
return nil
232209
}

0 commit comments

Comments
 (0)