@@ -11,8 +11,6 @@ import (
11
11
"strings"
12
12
)
13
13
14
- const arduinoCLI = "arduino-cli"
15
-
16
14
func generateCpp (inoCode []byte , name , fqbn string ) (cppPath string , cppCode []byte , err error ) {
17
15
tempDir , err := ioutil .TempDir ("" , "ino2cpp-" )
18
16
if err != nil {
@@ -42,9 +40,10 @@ func generateCpp(inoCode []byte, name, fqbn string) (cppPath string, cppCode []b
42
40
}
43
41
44
42
// Generate target file
45
- preprocessCmd := exec .Command (arduinoCLI , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
43
+ preprocessCmd := exec .Command (globalCliPath , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
46
44
cppCode , err = preprocessCmd .Output ()
47
45
if err != nil {
46
+ logCommandErr (globalCliPath , cppCode , err )
48
47
return
49
48
}
50
49
@@ -66,9 +65,10 @@ func updateCpp(inoCode []byte, fqbn, cppPath string) (cppCode []byte, err error)
66
65
}
67
66
68
67
// Generate target file
69
- preprocessCmd := exec .Command (arduinoCLI , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
68
+ preprocessCmd := exec .Command (globalCliPath , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
70
69
cppCode , err = preprocessCmd .Output ()
71
70
if err != nil {
71
+ logCommandErr (globalCliPath , cppCode , err )
72
72
return
73
73
}
74
74
@@ -78,9 +78,10 @@ func updateCpp(inoCode []byte, fqbn, cppPath string) (cppCode []byte, err error)
78
78
}
79
79
80
80
func generateCompileFlags (tempDir , inoPath , fqbn string ) (string , error ) {
81
- propertiesCmd := exec .Command (arduinoCLI , "compile" , "--fqbn" , fqbn , "--show-properties" , inoPath )
81
+ propertiesCmd := exec .Command (globalCliPath , "compile" , "--fqbn" , fqbn , "--show-properties" , inoPath )
82
82
output , err := propertiesCmd .Output ()
83
83
if err != nil {
84
+ logCommandErr (globalCliPath , output , err )
84
85
return "" , err
85
86
}
86
87
properties , err := readProperties (bytes .NewReader (output ))
@@ -119,3 +120,16 @@ func generateCompileFlags(tempDir, inoPath, fqbn string) (string, error) {
119
120
writer .Flush ()
120
121
return flagsPath , nil
121
122
}
123
+
124
+ func logCommandErr (command string , stdout []byte , err error ) {
125
+ log .Println ("Command error:" , command , err )
126
+ if len (stdout ) > 0 {
127
+ log .Println ("------------------------------BEGIN STDOUT\n " , string (stdout ), "\n ------------------------------END STDOUT" )
128
+ }
129
+ if exitErr , ok := err .(* exec.ExitError ); ok {
130
+ stderr := exitErr .Stderr
131
+ if len (stderr ) > 0 {
132
+ log .Println ("------------------------------BEGIN STDERR\n " , string (stderr ), "\n ------------------------------END STDERR" )
133
+ }
134
+ }
135
+ }
0 commit comments