@@ -239,8 +239,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
239
239
cmd .Dir = result .MainDir
240
240
241
241
// Wasmtime needs a few extra flags to work.
242
- emulator := config .Emulator ()
243
- if len (emulator ) != 0 && emulator [0 ] == "wasmtime" {
242
+ if config .EmulatorName () == "wasmtime" {
244
243
// Add directories to the module root, but skip the current working
245
244
// directory which is already added by buildAndRun.
246
245
dirs := dirsToModuleRoot (result .MainDir , result .ModuleRoot )
@@ -484,18 +483,19 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option
484
483
return err
485
484
}
486
485
487
- return builder .Build (pkgName , "" , config , func (result builder.BuildResult ) error {
486
+ format , fileExt := config .EmulatorFormat ()
487
+ return builder .Build (pkgName , fileExt , config , func (result builder.BuildResult ) error {
488
488
// Find a good way to run GDB.
489
489
gdbInterface , openocdInterface := config .Programmer ()
490
490
switch gdbInterface {
491
491
case "msd" , "command" , "" :
492
- emulator := config .Emulator ()
493
- if len ( emulator ) != 0 {
494
- if emulator [ 0 ] == "mgba" {
492
+ emulator := config .EmulatorName ()
493
+ if emulator != "" {
494
+ if emulator == "mgba" {
495
495
gdbInterface = "mgba"
496
- } else if emulator [ 0 ] == "simavr" {
496
+ } else if emulator == "simavr" {
497
497
gdbInterface = "simavr"
498
- } else if strings .HasPrefix (emulator [ 0 ] , "qemu-system-" ) {
498
+ } else if strings .HasPrefix (emulator , "qemu-system-" ) {
499
499
gdbInterface = "qemu"
500
500
} else {
501
501
// Assume QEMU as an emulator.
@@ -514,6 +514,10 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option
514
514
port := ""
515
515
var gdbCommands []string
516
516
var daemon * exec.Cmd
517
+ emulator , err := config .Emulator (format , result .Binary )
518
+ if err != nil {
519
+ return err
520
+ }
517
521
switch gdbInterface {
518
522
case "native" :
519
523
// Run GDB directly.
@@ -563,33 +567,29 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option
563
567
}
564
568
case "qemu" :
565
569
port = ":1234"
566
- emulator := config .Emulator ()
567
570
// Run in an emulator.
568
- args := append (emulator [1 :], result . Binary , "-s" , "-S" )
571
+ args := append (emulator [1 :], "-s" , "-S" )
569
572
daemon = executeCommand (config .Options , emulator [0 ], args ... )
570
573
daemon .Stdout = os .Stdout
571
574
daemon .Stderr = os .Stderr
572
575
case "qemu-user" :
573
576
port = ":1234"
574
- emulator := config .Emulator ()
575
577
// Run in an emulator.
576
- args := append (emulator [1 :], "-g" , "1234" , result . Binary )
578
+ args := append (emulator [1 :], "-g" , "1234" )
577
579
daemon = executeCommand (config .Options , emulator [0 ], args ... )
578
580
daemon .Stdout = os .Stdout
579
581
daemon .Stderr = os .Stderr
580
582
case "mgba" :
581
583
port = ":2345"
582
- emulator := config .Emulator ()
583
584
// Run in an emulator.
584
- args := append (emulator [1 :], result . Binary , "-g" )
585
+ args := append (emulator [1 :], "-g" )
585
586
daemon = executeCommand (config .Options , emulator [0 ], args ... )
586
587
daemon .Stdout = os .Stdout
587
588
daemon .Stderr = os .Stderr
588
589
case "simavr" :
589
590
port = ":1234"
590
- emulator := config .Emulator ()
591
591
// Run in an emulator.
592
- args := append (emulator [1 :], "-g" , result . Binary )
592
+ args := append (emulator [1 :], "-g" )
593
593
daemon = executeCommand (config .Options , emulator [0 ], args ... )
594
594
daemon .Stdout = os .Stdout
595
595
daemon .Stderr = os .Stderr
@@ -666,7 +666,7 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option
666
666
cmd .Stdin = os .Stdin
667
667
cmd .Stdout = os .Stdout
668
668
cmd .Stderr = os .Stderr
669
- err : = cmd .Run ()
669
+ err = cmd .Run ()
670
670
if err != nil {
671
671
return & commandError {"failed to run " + cmdName + " with" , result .Binary , err }
672
672
}
@@ -694,9 +694,6 @@ func Run(pkgName string, options *compileopts.Options, cmdArgs []string) error {
694
694
// passes command line arguments and evironment variables in a way appropriate
695
695
// for the given emulator.
696
696
func buildAndRun (pkgName string , config * compileopts.Config , stdout io.Writer , cmdArgs , environmentVars []string , timeout time.Duration , run func (cmd * exec.Cmd , result builder.BuildResult ) error ) error {
697
- // make sure any special vars in the emulator definition are rewritten
698
- emulator := config .Emulator ()
699
-
700
697
// Determine whether we're on a system that supports environment variables
701
698
// and command line parameters (operating systems, WASI) or not (baremetal,
702
699
// WebAssembly in the browser). If we're on a system without an environment,
@@ -728,7 +725,7 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c
728
725
"runtime" : runtimeGlobals ,
729
726
}
730
727
}
731
- } else if len ( emulator ) != 0 && emulator [ 0 ] == "wasmtime" {
728
+ } else if config . EmulatorName () == "wasmtime" {
732
729
// Wasmtime needs some special flags to pass environment variables
733
730
// and allow reading from the current directory.
734
731
args = append (args , "--dir=." )
@@ -747,7 +744,8 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c
747
744
env = environmentVars
748
745
}
749
746
750
- return builder .Build (pkgName , "" , config , func (result builder.BuildResult ) error {
747
+ format , fileExt := config .EmulatorFormat ()
748
+ return builder .Build (pkgName , fileExt , config , func (result builder.BuildResult ) error {
751
749
// If needed, set a timeout on the command. This is done in tests so
752
750
// they don't waste resources on a stalled test.
753
751
var ctx context.Context
@@ -759,12 +757,15 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c
759
757
760
758
// Set up the command.
761
759
var name string
762
- if len ( emulator ) == 0 {
760
+ if config . Target . Emulator == "" {
763
761
name = result .Binary
764
762
} else {
763
+ emulator , err := config .Emulator (format , result .Binary )
764
+ if err != nil {
765
+ return err
766
+ }
765
767
name = emulator [0 ]
766
768
emuArgs := append ([]string (nil ), emulator [1 :]... )
767
- emuArgs = append (emuArgs , result .Binary )
768
769
args = append (emuArgs , args ... )
769
770
}
770
771
var cmd * exec.Cmd
@@ -779,7 +780,7 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c
779
780
// stdout.
780
781
cmd .Stdout = stdout
781
782
cmd .Stderr = os .Stderr
782
- if len ( emulator ) != 0 && emulator [ 0 ] == "simavr" {
783
+ if config . EmulatorName () == "simavr" {
783
784
cmd .Stdout = nil // don't print initial load commands
784
785
cmd .Stderr = stdout
785
786
}
@@ -1572,7 +1573,7 @@ func main() {
1572
1573
os .Exit (1 )
1573
1574
return
1574
1575
}
1575
- if spec .FlashMethod == "" && spec .FlashCommand == "" && spec .Emulator == nil {
1576
+ if spec .FlashMethod == "" && spec .FlashCommand == "" && spec .Emulator == "" {
1576
1577
// This doesn't look like a regular target file, but rather like
1577
1578
// a parent target (such as targets/cortex-m.json).
1578
1579
continue
0 commit comments