@@ -675,8 +675,8 @@ func formatCmdline(cmdline string, boardOptions map[string]string) (string, bool
675675}
676676
677677func 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
679678
679+ // get executable (self)path and use it as base for all other paths
680680 execPath , _ := osext .Executable ()
681681
682682 boardFields := strings .Split (boardname , ":" )
@@ -692,7 +692,6 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
692692 return false , "" , nil
693693 }
694694 scanner := bufio .NewScanner (file )
695- //ide_tools_dir := "./" + boardFields[0] + "/tools"
696695
697696 boardOptions := make (map [string ]string )
698697 uploadOptions := make (map [string ]string )
@@ -708,13 +707,15 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
708707
709708 boardOptions ["serial.port" ] = portname
710709
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
711712 filePath = strings .Trim (filePath , "\n " )
712713 boardOptions ["build.path" ] = filepath .Dir (filePath )
713714 boardOptions ["build.project_name" ] = filepath .Base (filePath )
714715
715- //fmt.Printf("boardOptions %v %T", boardOptions, boardOptions)
716-
717716 file .Close ()
717+
718+ // get infos about the programmer
718719 tempPath = (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/hardware/" + boardFields [1 ] + "/platform.txt" )
719720 file , err = os .Open (tempPath )
720721 if err != nil {
@@ -727,7 +728,6 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
727728 tool := boardOptions ["upload.tool" ]
728729
729730 for scanner .Scan () {
730- //fmt.Println(scanner.Text());
731731 // map everything matching with upload
732732 if strings .Contains (scanner .Text (), tool ) {
733733 arr := strings .Split (scanner .Text (), "=" )
@@ -738,6 +738,7 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
738738 }
739739 file .Close ()
740740
741+ // multiple verisons of the same programmer can be handled if "version" is specified
741742 version := uploadOptions ["runtime.tools." + tool + ".version" ]
742743 path := (filepath .Dir (execPath ) + "/" + boardFields [0 ] + "/tools/" + tool + "/" + version )
743744 if err != nil {
@@ -748,14 +749,12 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
748749
749750 boardOptions ["runtime.tools.avrdude.path" ] = path
750751
751- //boardOptions["config.path"] = uploadOptions["tools."+tool+".config.path"]
752- //boardOptions["path"] = uploadOptions["tools."+tool+".path"]
753-
754752 cmdline := uploadOptions ["tools." + tool + ".upload.pattern" ]
755- // remove cmd.path as it is handles differently
753+ // remove cmd.path as it is handled differently
756754 cmdline = strings .Replace (cmdline , "\" {cmd.path}\" " , " " , 1 )
757755 cmdline = strings .Replace (cmdline , "\" " , "" , - 1 )
758756
757+ // split the commandline in substrings and recursively replace mapped strings
759758 cmdlineSlice := strings .Split (cmdline , " " )
760759 var winded = true
761760 for index , _ := range cmdlineSlice {
@@ -765,14 +764,7 @@ func assembleCompilerCommand(boardname string, portname string, filePath string)
765764 }
766765 }
767766
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
776768 if boardOptions ["upload.use_1200bps_touch" ] == "true" {
777769 // triggers bootloader mode
778770 // the portname could change in this occasion, so fail gently
0 commit comments