1
1
package mage
2
2
3
3
import (
4
+ "bytes"
4
5
"crypto/sha1"
5
6
"errors"
6
7
"flag"
@@ -339,13 +340,17 @@ func Invoke(inv Invocation) int {
339
340
if inv .HashFast {
340
341
debug .Println ("user has set MAGEFILE_HASHFAST, so we'll ignore GOCACHE" )
341
342
} else {
342
- if s , err := internal .OutputDebug (inv .GoCmd , "env" , "GOCACHE" ); err == nil {
343
- // if GOCACHE exists, always rebuild, so we catch transitive
344
- // dependencies that have changed.
345
- if s != "" {
346
- debug .Println ("go build cache exists, will ignore any compiled binary" )
347
- useCache = true
348
- }
343
+ s , err := internal .OutputDebug (inv .GoCmd , "env" , "GOCACHE" )
344
+ if err != nil {
345
+ errlog .Printf ("failed to run %s env GOCACHE: %s" , inv .GoCmd , err )
346
+ return 1
347
+ }
348
+
349
+ // if GOCACHE exists, always rebuild, so we catch transitive
350
+ // dependencies that have changed.
351
+ if s != "" {
352
+ debug .Println ("go build cache exists, will ignore any compiled binary" )
353
+ useCache = true
349
354
}
350
355
}
351
356
@@ -442,17 +447,22 @@ func Magefiles(magePath, goos, goarch, goCmd string, stderr io.Writer, isDebug b
442
447
}
443
448
444
449
debug .Println ("getting all non-mage files in" , magePath )
450
+
445
451
// // first, grab all the files with no build tags specified.. this is actually
446
452
// // our exclude list of things without the mage build tag.
447
453
cmd := exec .Command (goCmd , "list" , "-e" , "-f" , `{{join .GoFiles "||"}}` )
448
454
cmd .Env = env
449
- if isDebug {
450
- cmd .Stderr = stderr
451
- }
455
+ buf := & bytes.Buffer {}
456
+ cmd .Stderr = buf
452
457
cmd .Dir = magePath
453
458
b , err := cmd .Output ()
454
459
if err != nil {
455
- return fail (fmt .Errorf ("failed to list non-mage gofiles: %v" , err ))
460
+ stderr := buf .String ()
461
+ // if the error is "cannot find module", that can mean that there's no
462
+ // non-mage files, which is fine, so ignore it.
463
+ if ! strings .Contains (stderr , "cannot find module for path" ) {
464
+ return fail (fmt .Errorf ("failed to list non-mage gofiles: %v: %s" , err , stderr ))
465
+ }
456
466
}
457
467
list := strings .TrimSpace (string (b ))
458
468
debug .Println ("found non-mage files" , list )
@@ -467,13 +477,11 @@ func Magefiles(magePath, goos, goarch, goCmd string, stderr io.Writer, isDebug b
467
477
cmd = exec .Command (goCmd , "list" , "-tags=mage" , "-e" , "-f" , `{{join .GoFiles "||"}}` )
468
478
cmd .Env = env
469
479
470
- if isDebug {
471
- cmd .Stderr = stderr
472
- }
480
+ buf .Reset ()
473
481
cmd .Dir = magePath
474
482
b , err = cmd .Output ()
475
483
if err != nil {
476
- return fail (fmt .Errorf ("failed to list mage gofiles: %v" , err ))
484
+ return fail (fmt .Errorf ("failed to list mage gofiles: %v: %s " , err , buf . Bytes () ))
477
485
}
478
486
479
487
list = strings .TrimSpace (string (b ))
0 commit comments