@@ -675,8 +675,8 @@ func formatCmdline(cmdline string, boardOptions map[string]string) (string, bool
675
675
}
676
676
677
677
func assembleCompilerCommand (boardname string , portname string , filePath string ) (bool , string , []string ) {
678
- // walk across the local filesystem, find boards.txt files, search for the board in it
679
678
679
+ // get executable (self)path and use it as base for all other paths
680
680
execPath , _ := osext .Executable ()
681
681
682
682
boardFields := strings .Split (boardname , ":" )
@@ -692,7 +692,6 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
692
692
return false , "" , nil
693
693
}
694
694
scanner := bufio .NewScanner (file )
695
- //ide_tools_dir := "./" + boardFields[0] + "/tools"
696
695
697
696
boardOptions := make (map [string ]string )
698
697
uploadOptions := make (map [string ]string )
@@ -708,13 +707,15 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
708
707
709
708
boardOptions ["serial.port" ] = portname
710
709
710
+ // filepath need special care; the project_name var is the filename minus its extension (hex or bin)
711
+ // if we are going to modify standard IDE files we also could pass ALL filename
711
712
filePath = strings .Trim (filePath , "\n " )
712
713
boardOptions ["build.path" ] = filepath .Dir (filePath )
713
714
boardOptions ["build.project_name" ] = filepath .Base (filePath )
714
715
715
- //fmt.Printf("boardOptions %v %T", boardOptions, boardOptions)
716
-
717
716
file .Close ()
717
+
718
+ // get infos about the programmer
718
719
tempPath = (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/hardware/" + boardFields [1 ] + "/platform.txt" )
719
720
file , err = os .Open (tempPath )
720
721
if err != nil {
@@ -727,7 +728,6 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
727
728
tool := boardOptions ["upload.tool" ]
728
729
729
730
for scanner .Scan () {
730
- //fmt.Println(scanner.Text());
731
731
// map everything matching with upload
732
732
if strings .Contains (scanner .Text (), tool ) {
733
733
arr := strings .Split (scanner .Text (), "=" )
@@ -738,6 +738,7 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
738
738
}
739
739
file .Close ()
740
740
741
+ // multiple verisons of the same programmer can be handled if "version" is specified
741
742
version := uploadOptions ["runtime.tools." + tool + ".version" ]
742
743
path := (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/tools/" + tool + "/" + version )
743
744
if err != nil {
@@ -748,14 +749,12 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
748
749
749
750
boardOptions ["runtime.tools.avrdude.path" ] = path
750
751
751
- //boardOptions["config.path"] = uploadOptions["tools."+tool+".config.path"]
752
- //boardOptions["path"] = uploadOptions["tools."+tool+".path"]
753
-
754
752
cmdline := uploadOptions ["tools." + tool + ".upload.pattern" ]
755
- // remove cmd.path as it is handles differently
753
+ // remove cmd.path as it is handled differently
756
754
cmdline = strings .Replace (cmdline , "\" {cmd.path}\" " , " " , 1 )
757
755
cmdline = strings .Replace (cmdline , "\" " , "" , - 1 )
758
756
757
+ // split the commandline in substrings and recursively replace mapped strings
759
758
cmdlineSlice := strings .Split (cmdline , " " )
760
759
var winded = true
761
760
for index , _ := range cmdlineSlice {
@@ -765,14 +764,7 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
765
764
}
766
765
}
767
766
768
- // cmdline := "-C" + ide_tools_dir + "etc/avrdude.conf" +
769
- // " -c" + protocol +
770
- // " -b" + speed +
771
- // " -p" + mcu +
772
- // " -P" + portname +
773
- // " -D" +
774
- // " -Uflash:w:" + filePath + ":i "
775
-
767
+ // some boards (eg. Leonardo, Yun) need a special procedure to enter bootloader
776
768
if boardOptions ["upload.use_1200bps_touch" ] == "true" {
777
769
// triggers bootloader mode
778
770
// the portname could change in this occasion, so fail gently
0 commit comments