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

Commit 2ba9bbf

Browse files
author
Sauyon Lee
authored
Merge pull request #355 from sauyon/moddir-fix
Improve extractor logging and a minor readability fix
2 parents 88c740b + 7ea3b34 commit 2ba9bbf

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

extractor/extractor.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,10 @@ func Extract(patterns []string) error {
3232

3333
// ExtractWithFlags extracts the packages specified by the given patterns and build flags
3434
func ExtractWithFlags(buildFlags []string, patterns []string) error {
35-
cfg := &packages.Config{
36-
Mode: packages.NeedName | packages.NeedFiles |
37-
packages.NeedCompiledGoFiles |
38-
packages.NeedImports | packages.NeedDeps |
39-
packages.NeedTypes | packages.NeedTypesSizes |
40-
packages.NeedTypesInfo | packages.NeedSyntax,
41-
BuildFlags: buildFlags,
35+
modEnabled := os.Getenv("GO111MODULE") != "off"
36+
if !modEnabled {
37+
log.Println("Go module mode disabled.")
4238
}
43-
pkgs, err := packages.Load(cfg, patterns...)
4439

4540
modFlags := make([]string, 0, 1)
4641
for _, flag := range buildFlags {
@@ -49,15 +44,28 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
4944
}
5045
}
5146

47+
log.Println("Running packages.Load.")
48+
cfg := &packages.Config{
49+
Mode: packages.NeedName | packages.NeedFiles |
50+
packages.NeedCompiledGoFiles |
51+
packages.NeedImports | packages.NeedDeps |
52+
packages.NeedTypes | packages.NeedTypesSizes |
53+
packages.NeedTypesInfo | packages.NeedSyntax,
54+
BuildFlags: buildFlags,
55+
}
56+
pkgs, err := packages.Load(cfg, patterns...)
5257
if err != nil {
5358
return err
5459
}
60+
log.Println("Done running packages.Load.")
5561

5662
if len(pkgs) == 0 {
57-
log.Printf("No packages found.")
63+
log.Println("No packages found.")
5864
}
5965

66+
log.Println("Extracting universe scope.")
6067
extractUniverseScope()
68+
log.Println("Done extracting universe scope.")
6169

6270
// a map of package path to package root directory (currently the module root or the source directory)
6371
pkgRoots := make(map[string]string)
@@ -72,6 +80,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
7280
packages.Visit(pkgs, func(pkg *packages.Package) bool {
7381
return true
7482
}, func(pkg *packages.Package) {
83+
log.Printf("Processing package %s.", pkg.PkgPath)
84+
7585
if _, ok := pkgRoots[pkg.PkgPath]; !ok {
7686
mdir := util.GetModDir(pkg.PkgPath, modFlags...)
7787
pdir := util.GetPkgDir(pkg.PkgPath, modFlags...)
@@ -84,6 +94,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
8494
pkgDirs[pkg.PkgPath] = pdir
8595
}
8696

97+
log.Printf("Extracting types for package %s.", pkg.PkgPath)
98+
8799
tw, err := trap.NewWriter(pkg.PkgPath, pkg)
88100
if err != nil {
89101
log.Fatal(err)
@@ -102,6 +114,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
102114
extractError(tw, err, lbl, i)
103115
}
104116
}
117+
log.Printf("Done extracting types for package %s.", pkg.PkgPath)
105118
})
106119

107120
for _, pkg := range pkgs {
@@ -111,6 +124,10 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
111124
wantedRoots[pkgRoots[pkg.PkgPath]] = true
112125
}
113126

127+
log.Println("Done processing dependencies.")
128+
129+
log.Println("Starting to extract packages.")
130+
114131
// this sets the number of threads that the Go runtime will spawn; this is separate
115132
// from the number of goroutines that the program spawns, which are scheduled into
116133
// the system threads by the Go runtime scheduler
@@ -163,10 +180,15 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
163180
extractPackage(pkg, &wg, goroutineSem, fdSem)
164181
return
165182
}
183+
184+
log.Printf("Skipping dependency package %s.", pkg.PkgPath)
166185
})
167186

168187
wg.Wait()
169188

189+
log.Println("Done extracting packages.")
190+
log.Println("Starting to extract go.mod files.")
191+
170192
cwd, err := os.Getwd()
171193
if err != nil {
172194
log.Printf("Warning: unable to get working directory: %s", err.Error())
@@ -204,6 +226,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
204226
log.Printf("Done extracting %s (%dms)", path, end.Nanoseconds()/1000000)
205227
}
206228

229+
log.Println("Done extracting go.mod files.")
230+
207231
return nil
208232
}
209233

0 commit comments

Comments
 (0)