@@ -32,15 +32,10 @@ func Extract(patterns []string) error {
32
32
33
33
// ExtractWithFlags extracts the packages specified by the given patterns and build flags
34
34
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." )
42
38
}
43
- pkgs , err := packages .Load (cfg , patterns ... )
44
39
45
40
modFlags := make ([]string , 0 , 1 )
46
41
for _ , flag := range buildFlags {
@@ -49,15 +44,28 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
49
44
}
50
45
}
51
46
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 ... )
52
57
if err != nil {
53
58
return err
54
59
}
60
+ log .Println ("Done running packages.Load." )
55
61
56
62
if len (pkgs ) == 0 {
57
- log .Printf ("No packages found." )
63
+ log .Println ("No packages found." )
58
64
}
59
65
66
+ log .Println ("Extracting universe scope." )
60
67
extractUniverseScope ()
68
+ log .Println ("Done extracting universe scope." )
61
69
62
70
// a map of package path to package root directory (currently the module root or the source directory)
63
71
pkgRoots := make (map [string ]string )
@@ -72,6 +80,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
72
80
packages .Visit (pkgs , func (pkg * packages.Package ) bool {
73
81
return true
74
82
}, func (pkg * packages.Package ) {
83
+ log .Printf ("Processing package %s." , pkg .PkgPath )
84
+
75
85
if _ , ok := pkgRoots [pkg .PkgPath ]; ! ok {
76
86
mdir := util .GetModDir (pkg .PkgPath , modFlags ... )
77
87
pdir := util .GetPkgDir (pkg .PkgPath , modFlags ... )
@@ -84,6 +94,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
84
94
pkgDirs [pkg .PkgPath ] = pdir
85
95
}
86
96
97
+ log .Printf ("Extracting types for package %s." , pkg .PkgPath )
98
+
87
99
tw , err := trap .NewWriter (pkg .PkgPath , pkg )
88
100
if err != nil {
89
101
log .Fatal (err )
@@ -102,6 +114,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
102
114
extractError (tw , err , lbl , i )
103
115
}
104
116
}
117
+ log .Printf ("Done extracting types for package %s." , pkg .PkgPath )
105
118
})
106
119
107
120
for _ , pkg := range pkgs {
@@ -111,6 +124,10 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
111
124
wantedRoots [pkgRoots [pkg.PkgPath ]] = true
112
125
}
113
126
127
+ log .Println ("Done processing dependencies." )
128
+
129
+ log .Println ("Starting to extract packages." )
130
+
114
131
// this sets the number of threads that the Go runtime will spawn; this is separate
115
132
// from the number of goroutines that the program spawns, which are scheduled into
116
133
// the system threads by the Go runtime scheduler
@@ -163,10 +180,15 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
163
180
extractPackage (pkg , & wg , goroutineSem , fdSem )
164
181
return
165
182
}
183
+
184
+ log .Printf ("Skipping dependency package %s." , pkg .PkgPath )
166
185
})
167
186
168
187
wg .Wait ()
169
188
189
+ log .Println ("Done extracting packages." )
190
+ log .Println ("Starting to extract go.mod files." )
191
+
170
192
cwd , err := os .Getwd ()
171
193
if err != nil {
172
194
log .Printf ("Warning: unable to get working directory: %s" , err .Error ())
@@ -204,6 +226,8 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
204
226
log .Printf ("Done extracting %s (%dms)" , path , end .Nanoseconds ()/ 1000000 )
205
227
}
206
228
229
+ log .Println ("Done extracting go.mod files." )
230
+
207
231
return nil
208
232
}
209
233
0 commit comments