Skip to content

Commit b4e0d43

Browse files
committed
remove outdated assembleCompilerCommand function
1 parent d56ff47 commit b4e0d43

File tree

1 file changed

+0
-185
lines changed

1 file changed

+0
-185
lines changed

programmer.go

Lines changed: 0 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
log "github.com/Sirupsen/logrus"
99
"github.com/facchinm/go-serial"
10-
"github.com/kardianos/osext"
1110
"github.com/mattn/go-shellwords"
1211
"io"
1312
"mime/multipart"
@@ -389,187 +388,3 @@ func touch_port_1200bps(portname string, wait_for_upload_port bool) (string, err
389388
}
390389
return portname, nil
391390
}
392-
393-
func assembleCompilerCommand(boardname string, portname string, filePath string) (bool, string, []string) {
394-
395-
// get executable (self)path and use it as base for all other paths
396-
execPath, _ := osext.Executable()
397-
398-
boardFields := strings.Split(boardname, ":")
399-
if len(boardFields) != 3 {
400-
mapD := map[string]string{"Err": "Board need to be specified in core:architecture:name format"}
401-
mapB, _ := json.Marshal(mapD)
402-
h.broadcastSys <- mapB
403-
return false, "", nil
404-
}
405-
tempPath := (filepath.Dir(execPath) + "/" + boardFields[0] + "/hardware/" + boardFields[1] + "/boards.txt")
406-
file, err := os.Open(tempPath)
407-
if err != nil {
408-
mapD := map[string]string{"Err": "Could not find board: " + boardname}
409-
mapB, _ := json.Marshal(mapD)
410-
h.broadcastSys <- mapB
411-
log.Println("Error:", err)
412-
return false, "", nil
413-
}
414-
scanner := bufio.NewScanner(file)
415-
416-
boardOptions := make(map[string]string)
417-
uploadOptions := make(map[string]string)
418-
419-
for scanner.Scan() {
420-
// map everything matching with boardname
421-
if strings.Contains(scanner.Text(), boardFields[2]) {
422-
arr := strings.Split(scanner.Text(), "=")
423-
arr[0] = strings.Replace(arr[0], boardFields[2]+".", "", 1)
424-
boardOptions[arr[0]] = arr[1]
425-
}
426-
}
427-
428-
if len(boardOptions) == 0 {
429-
mapD := map[string]string{"Err": "Board " + boardFields[2] + " is not part of " + boardFields[0] + ":" + boardFields[1]}
430-
mapB, _ := json.Marshal(mapD)
431-
h.broadcastSys <- mapB
432-
return false, "", nil
433-
}
434-
435-
// filepath need special care; the project_name var is the filename minus its extension (hex or bin)
436-
// if we are going to modify standard IDE files we also could pass ALL filename
437-
filePath = strings.Trim(filePath, "\n")
438-
boardOptions["build.path"] = filepath.Dir(filePath)
439-
boardOptions["build.project_name"] = strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filepath.Base(filePath)))
440-
441-
file.Close()
442-
443-
// get infos about the programmer
444-
tempPath = (filepath.Dir(execPath) + "/" + boardFields[0] + "/hardware/" + boardFields[1] + "/platform.txt")
445-
file, err = os.Open(tempPath)
446-
if err != nil {
447-
mapD := map[string]string{"Err": "Could not find board: " + boardname}
448-
mapB, _ := json.Marshal(mapD)
449-
h.broadcastSys <- mapB
450-
log.Println("Error:", err)
451-
return false, "", nil
452-
}
453-
scanner = bufio.NewScanner(file)
454-
455-
tool := boardOptions["upload.tool"]
456-
457-
for scanner.Scan() {
458-
// map everything matching with upload
459-
if strings.Contains(scanner.Text(), tool) {
460-
arr := strings.Split(scanner.Text(), "=")
461-
uploadOptions[arr[0]] = arr[1]
462-
arr[0] = strings.Replace(arr[0], "tools."+tool+".", "", 1)
463-
boardOptions[arr[0]] = arr[1]
464-
// we have a "=" in command line
465-
if len(arr) > 2 {
466-
boardOptions[arr[0]] = arr[1] + "=" + arr[2]
467-
}
468-
}
469-
}
470-
file.Close()
471-
472-
// multiple verisons of the same programmer can be handled if "version" is specified
473-
version := uploadOptions["runtime.tools."+tool+".version"]
474-
path := (filepath.Dir(execPath) + "/" + boardFields[0] + "/tools/" + tool + "/" + version)
475-
if err != nil {
476-
mapD := map[string]string{"Err": "Could not find board: " + boardname}
477-
mapB, _ := json.Marshal(mapD)
478-
h.broadcastSys <- mapB
479-
log.Println("Error:", err)
480-
return false, "", nil
481-
}
482-
483-
boardOptions["runtime.tools."+tool+".path"] = path
484-
485-
cmdline := boardOptions["upload.pattern"]
486-
// remove cmd.path as it is handled differently
487-
cmdline = strings.Replace(cmdline, "\"{cmd.path}\"", " ", 1)
488-
cmdline = strings.Replace(cmdline, "\"{path}/{cmd}\"", " ", 1)
489-
cmdline = strings.Replace(cmdline, "\"", "", -1)
490-
491-
initialPortName := portname
492-
493-
// some boards (eg. Leonardo, Yun) need a special procedure to enter bootloader
494-
if boardOptions["upload.use_1200bps_touch"] == "true" {
495-
// triggers bootloader mode
496-
// the portname could change in this occasion (expecially on Windows) so change portname
497-
// with the port which will reappear
498-
log.Println("Restarting in bootloader mode")
499-
500-
mode := &serial.Mode{
501-
BaudRate: 1200,
502-
Vmin: 1,
503-
Vtimeout: 0,
504-
}
505-
port, err := serial.OpenPort(portname, mode)
506-
if err != nil {
507-
log.Println(err)
508-
return false, "", nil
509-
}
510-
//port.SetDTR(false)
511-
port.Close()
512-
time.Sleep(time.Second / 2.0)
513-
514-
timeout := false
515-
go func() {
516-
time.Sleep(2 * time.Second)
517-
timeout = true
518-
}()
519-
520-
// time.Sleep(time.Second / 4)
521-
// wait for port to reappear
522-
if boardOptions["upload.wait_for_upload_port"] == "true" {
523-
after_reset_ports, _ := serial.GetPortsList()
524-
log.Println(after_reset_ports)
525-
var ports []string
526-
for {
527-
ports, _ = serial.GetPortsList()
528-
log.Println(ports)
529-
time.Sleep(time.Millisecond * 200)
530-
portname = findNewPortName(ports, after_reset_ports)
531-
if portname != "" {
532-
break
533-
}
534-
if timeout {
535-
break
536-
}
537-
}
538-
}
539-
}
540-
541-
if portname == "" {
542-
portname = initialPortName
543-
}
544-
545-
boardOptions["serial.port"] = portname
546-
boardOptions["serial.port.file"] = filepath.Base(portname)
547-
548-
// split the commandline in substrings and recursively replace mapped strings
549-
cmdlineSlice := strings.Split(cmdline, " ")
550-
var winded = true
551-
for index, _ := range cmdlineSlice {
552-
winded = true
553-
for winded != false {
554-
cmdlineSlice[index], winded = formatCmdline(cmdlineSlice[index], boardOptions)
555-
}
556-
}
557-
558-
tool = (filepath.Dir(execPath) + "/" + boardFields[0] + "/tools/" + tool + "/bin/" + tool)
559-
// the file doesn't exist, we are on windows
560-
if _, err := os.Stat(tool); err != nil {
561-
tool = tool + ".exe"
562-
// convert all "/" to "\"
563-
tool = strings.Replace(tool, "/", "\\", -1)
564-
}
565-
566-
// remove blanks from cmdlineSlice
567-
var cmdlineSliceOut []string
568-
for _, element := range cmdlineSlice {
569-
if element != "" {
570-
cmdlineSliceOut = append(cmdlineSliceOut, element)
571-
}
572-
}
573-
574-
return (tool != ""), tool, cmdlineSliceOut
575-
}

0 commit comments

Comments
 (0)