@@ -157,28 +157,24 @@ const (
157
157
ModVendor
158
158
)
159
159
160
- func (m ModMode ) String () string {
160
+ func (m ModMode ) argsForGoVersion ( version string ) [] string {
161
161
switch m {
162
162
case ModUnset :
163
- return ""
163
+ return [] string {}
164
164
case ModReadonly :
165
- return "-mod=readonly"
165
+ return [] string { "-mod=readonly" }
166
166
case ModMod :
167
- return "-mod=mod"
167
+ if semver .Compare (getEnvGoVersion (), "1.14" ) < 0 {
168
+ log .Printf ("%s < %s" , getEnvGoVersion (), "1.14" )
169
+ return []string {} // -mod=mod is the default behaviour for go <= 1.13, and is not accepted as an argument
170
+ } else {
171
+ log .Printf ("%s >= %s" , getEnvGoVersion (), "1.14" )
172
+ return []string {"-mod=mod" }
173
+ }
168
174
case ModVendor :
169
- return "-mod=vendor"
170
- }
171
- return ""
172
- }
173
-
174
- // modModIfSupported returns `ModMod` if that flag is supported, or `ModUnset` if it is not, in
175
- // which case the behavior should be identical to `ModMod`.
176
- func modModIfSupported () ModMode {
177
- if semver .Compare (getEnvGoVersion (), "1.14" ) < 0 {
178
- return ModUnset
179
- } else {
180
- return ModMod
175
+ return []string {"-mod=vendor" }
181
176
}
177
+ return nil
182
178
}
183
179
184
180
// addVersionToMod add a go version directive, e.g. `go 1.14` to a `go.mod` file.
@@ -245,7 +241,7 @@ func main() {
245
241
if util .FileExists ("vendor/modules.txt" ) {
246
242
modMode = ModVendor
247
243
} else if util .DirExists ("vendor" ) {
248
- modMode = modModIfSupported ()
244
+ modMode = ModMod
249
245
}
250
246
251
247
if modMode == ModVendor {
@@ -270,7 +266,7 @@ func main() {
270
266
log .Println ("Adding a version directive to the go.mod file as the modules.txt does not have explicit annotations" )
271
267
if ! addVersionToMod (goMod , "1.13" ) {
272
268
log .Println ("Failed to add a version to the go.mod file to fix explicitly required package bug; not using vendored dependencies" )
273
- modMode = modModIfSupported ()
269
+ modMode = ModMod
274
270
}
275
271
}
276
272
}
@@ -435,7 +431,7 @@ func main() {
435
431
// or not set if the go version < 1.14. Note we check this post-build in case the build brings
436
432
// the vendor directory up to date.
437
433
if ! checkVendor () {
438
- modMode = modModIfSupported ()
434
+ modMode = ModMod
439
435
log .Println ("The vendor directory is not consistent with the go.mod; not using vendored dependencies." )
440
436
}
441
437
}
@@ -507,14 +503,14 @@ func main() {
507
503
log .Fatalf ("Unable to determine current directory: %s\n " , err .Error ())
508
504
}
509
505
510
- var cmd * exec.Cmd
511
- if depMode == GoGetWithModules && modMode .String () != "" {
512
- log .Printf ("Running extractor command '%s %s ./...' from directory '%s'.\n " , extractor , modMode , cwd )
513
- cmd = exec .Command (extractor , modMode .String (), "./..." )
514
- } else {
515
- log .Printf ("Running extractor command '%s ./...' from directory '%s'.\n " , extractor , cwd )
516
- cmd = exec .Command (extractor , "./..." )
506
+ extractorArgs := []string {}
507
+ if depMode == GoGetWithModules {
508
+ extractorArgs = append (extractorArgs , modMode .argsForGoVersion (getEnvGoVersion ())... )
517
509
}
510
+ extractorArgs = append (extractorArgs , "./..." )
511
+
512
+ log .Printf ("Running extractor command '%s %v' from directory '%s'.\n " , extractor , extractorArgs , cwd )
513
+ cmd := exec .Command (extractor , extractorArgs ... )
518
514
cmd .Stdout = os .Stdout
519
515
cmd .Stderr = os .Stderr
520
516
err = cmd .Run ()
0 commit comments