@@ -10,6 +10,7 @@ import (
10
10
//"github.com/kballard/go-shellquote"
11
11
//"github.com/johnlauer/goserial"
12
12
//"github.com/mikepb/go-serial"
13
+ "github.com/kardianos/osext"
13
14
"go.bug.st/serial"
14
15
"log"
15
16
"os"
@@ -673,22 +674,24 @@ func formatCmdline(cmdline string, boardOptions map[string]string) (string, bool
673
674
return cmdline , true
674
675
}
675
676
676
- func assembleCompilerCommand (boardname string , portname string , filePath string ) (bool , string , string ) {
677
+ func assembleCompilerCommand (boardname string , portname string , filePath string ) (bool , string , [] string ) {
677
678
// walk across the local filesystem, find boards.txt files, search for the board in it
678
679
680
+ execPath , _ := osext .Executable ()
681
+
679
682
boardFields := strings .Split (boardname , ":" )
680
683
if len (boardFields ) != 3 {
681
684
h .broadcastSys <- []byte ("Board need to be specified in core:architecture:name format" )
682
- return false , "" , ""
685
+ return false , "" , nil
683
686
}
684
- file , err := os .Open (boardFields [0 ] + "/hardware/" + boardFields [1 ] + "/boards.txt" )
687
+ tempPath := (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/hardware/" + boardFields [1 ] + "/boards.txt" )
688
+ file , err := os .Open (tempPath )
685
689
if err != nil {
686
690
h .broadcastSys <- []byte ("Could not find board: " + boardname )
687
691
fmt .Println ("Error:" , err )
688
- return false , "" , ""
692
+ return false , "" , nil
689
693
}
690
694
scanner := bufio .NewScanner (file )
691
- cmdline := ""
692
695
//ide_tools_dir := "./" + boardFields[0] + "/tools"
693
696
694
697
boardOptions := make (map [string ]string )
@@ -704,16 +707,20 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
704
707
}
705
708
706
709
boardOptions ["serial.port" ] = portname
707
- boardOptions ["build.project_name" ] = strings .Trim (filePath , "\n " )
710
+
711
+ filePath = strings .Trim (filePath , "\n " )
712
+ boardOptions ["build.path" ] = filepath .Dir (filePath )
713
+ boardOptions ["build.project_name" ] = filepath .Base (filePath )
708
714
709
715
//fmt.Printf("boardOptions %v %T", boardOptions, boardOptions)
710
716
711
717
file .Close ()
712
- file , err = os .Open (boardFields [0 ] + "/hardware/" + boardFields [1 ] + "/platform.txt" )
718
+ tempPath = (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/hardware/" + boardFields [1 ] + "/platform.txt" )
719
+ file , err = os .Open (tempPath )
713
720
if err != nil {
714
721
h .broadcastSys <- []byte ("Could not find board: " + boardname )
715
722
fmt .Println ("Error:" , err )
716
- return false , "" , ""
723
+ return false , "" , nil
717
724
}
718
725
scanner = bufio .NewScanner (file )
719
726
@@ -732,27 +739,30 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
732
739
file .Close ()
733
740
734
741
version := uploadOptions ["runtime.tools." + tool + ".version" ]
735
- path , err := filepath .Abs ( boardFields [0 ] + "/tools/" + tool + "/" + version )
742
+ path := ( filepath .Dir ( execPath ) + "/" + boardFields [0 ] + "/tools/" + tool + "/" + version )
736
743
if err != nil {
737
744
h .broadcastSys <- []byte ("Could not find board: " + boardname )
738
745
fmt .Println ("Error:" , err )
739
- return false , "" , ""
746
+ return false , "" , nil
740
747
}
741
748
742
749
boardOptions ["runtime.tools.avrdude.path" ] = path
743
750
744
751
//boardOptions["config.path"] = uploadOptions["tools."+tool+".config.path"]
745
752
//boardOptions["path"] = uploadOptions["tools."+tool+".path"]
746
753
747
- var winded = true
748
-
749
- cmdline = uploadOptions ["tools." + tool + ".upload.pattern" ]
754
+ cmdline := uploadOptions ["tools." + tool + ".upload.pattern" ]
750
755
// remove cmd.path as it is handles differently
751
756
cmdline = strings .Replace (cmdline , "\" {cmd.path}\" " , " " , 1 )
752
757
cmdline = strings .Replace (cmdline , "\" " , "" , - 1 )
753
758
754
- for winded != false {
755
- cmdline , winded = formatCmdline (cmdline , boardOptions )
759
+ cmdlineSlice := strings .Split (cmdline , " " )
760
+ var winded = true
761
+ for index , _ := range cmdlineSlice {
762
+ winded = true
763
+ for winded != false {
764
+ cmdlineSlice [index ], winded = formatCmdline (cmdlineSlice [index ], boardOptions )
765
+ }
756
766
}
757
767
758
768
// cmdline := "-C" + ide_tools_dir + "etc/avrdude.conf" +
@@ -774,14 +784,22 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
774
784
port , err := serial .OpenPort (portname , mode )
775
785
if err != nil {
776
786
log .Println (err )
777
- return false , "" , ""
787
+ return false , "" , nil
778
788
}
779
789
time .Sleep (time .Second / 2 )
780
790
port .Close ()
781
791
time .Sleep (time .Second * 2 )
782
792
}
783
793
784
- return (tool != "" ), tool , cmdline
794
+ tool = (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/tools/" + tool + "/bin/" + tool )
795
+ // the file doesn't exist, we are on windows
796
+ if _ , err := os .Stat (tool ); err != nil {
797
+ tool = tool + ".exe"
798
+ // convert all "/" to "\"
799
+ tool = strings .Replace (tool , "/" , "\\ " , - 1 )
800
+ }
801
+
802
+ return (tool != "" ), tool , cmdlineSlice
785
803
}
786
804
787
805
func findPortByName (portname string ) (* serport , bool ) {
0 commit comments