@@ -350,7 +350,7 @@ func (c compile) run(name string, count int) error {
350
350
return err
351
351
}
352
352
353
- importcfg , err := genImportcfgFile (c .dir , false )
353
+ importcfg , err := genImportcfgFile (c .dir , "" , false ) // TODO: pass compiler flags?
354
354
if err != nil {
355
355
return err
356
356
}
@@ -418,12 +418,19 @@ func (r link) run(name string, count int) error {
418
418
}
419
419
420
420
// Build dependencies.
421
- out , err := exec .Command (* flagGoCmd , "build" , "-o" , "/dev/null" , r .dir ).CombinedOutput ()
421
+ ldflags := * flagLinkerFlags
422
+ if r .flags != "" {
423
+ if ldflags != "" {
424
+ ldflags += " "
425
+ }
426
+ ldflags += r .flags
427
+ }
428
+ out , err := exec .Command (* flagGoCmd , "build" , "-o" , "/dev/null" , "-ldflags=" + ldflags , r .dir ).CombinedOutput ()
422
429
if err != nil {
423
430
return fmt .Errorf ("go build -a %s: %v\n %s" , r .dir , err , out )
424
431
}
425
432
426
- importcfg , err := genImportcfgFile (r .dir , true )
433
+ importcfg , err := genImportcfgFile (r .dir , "-ldflags=" + ldflags , true )
427
434
if err != nil {
428
435
return err
429
436
}
@@ -643,15 +650,19 @@ func genSymAbisFile(pkg *Pkg, symAbisFile, incdir string) error {
643
650
// genImportcfgFile generates an importcfg file for building package
644
651
// dir. Returns the generated importcfg file path (or empty string
645
652
// if the package has no dependency).
646
- func genImportcfgFile (dir string , full bool ) (string , error ) {
653
+ func genImportcfgFile (dir string , flags string , full bool ) (string , error ) {
647
654
need := "{{.Imports}}"
648
655
if full {
649
656
// for linking, we need transitive dependencies
650
657
need = "{{.Deps}}"
651
658
}
652
659
660
+ if flags == "" {
661
+ flags = "--" // passing "" to go list, it will match to the current directory
662
+ }
663
+
653
664
// find imported/dependent packages
654
- cmd := exec .Command (* flagGoCmd , "list" , "-f" , need , dir )
665
+ cmd := exec .Command (* flagGoCmd , "list" , "-f" , need , flags , dir )
655
666
cmd .Stderr = os .Stderr
656
667
out , err := cmd .Output ()
657
668
if err != nil {
@@ -667,7 +678,7 @@ func genImportcfgFile(dir string, full bool) (string, error) {
667
678
}
668
679
669
680
// build importcfg for imported packages
670
- cmd = exec .Command (* flagGoCmd , "list" , "-export" , "-f" , "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}" )
681
+ cmd = exec .Command (* flagGoCmd , "list" , "-export" , "-f" , "{{if .Export}}packagefile {{.ImportPath}}={{.Export}}{{end}}" , flags )
671
682
cmd .Args = append (cmd .Args , strings .Fields (string (out ))... )
672
683
cmd .Stderr = os .Stderr
673
684
out , err = cmd .Output ()
0 commit comments