@@ -11,8 +11,6 @@ import (
1111 "strings"
1212)
1313
14- const arduinoCLI = "arduino-cli"
15-
1614func generateCpp (inoCode []byte , name , fqbn string ) (cppPath string , cppCode []byte , err error ) {
1715 tempDir , err := ioutil .TempDir ("" , "ino2cpp-" )
1816 if err != nil {
@@ -42,9 +40,10 @@ func generateCpp(inoCode []byte, name, fqbn string) (cppPath string, cppCode []b
4240 }
4341
4442 // Generate target file
45- preprocessCmd := exec .Command (arduinoCLI , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
43+ preprocessCmd := exec .Command (globalCliPath , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
4644 cppCode , err = preprocessCmd .Output ()
4745 if err != nil {
46+ logCommandErr (globalCliPath , cppCode , err )
4847 return
4948 }
5049
@@ -66,9 +65,10 @@ func updateCpp(inoCode []byte, fqbn, cppPath string) (cppCode []byte, err error)
6665 }
6766
6867 // Generate target file
69- preprocessCmd := exec .Command (arduinoCLI , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
68+ preprocessCmd := exec .Command (globalCliPath , "compile" , "--fqbn" , fqbn , "--preprocess" , inoPath )
7069 cppCode , err = preprocessCmd .Output ()
7170 if err != nil {
71+ logCommandErr (globalCliPath , cppCode , err )
7272 return
7373 }
7474
@@ -78,9 +78,10 @@ func updateCpp(inoCode []byte, fqbn, cppPath string) (cppCode []byte, err error)
7878}
7979
8080func 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 )
8282 output , err := propertiesCmd .Output ()
8383 if err != nil {
84+ logCommandErr (globalCliPath , output , err )
8485 return "" , err
8586 }
8687 properties , err := readProperties (bytes .NewReader (output ))
@@ -119,3 +120,16 @@ func generateCompileFlags(tempDir, inoPath, fqbn string) (string, error) {
119120 writer .Flush ()
120121 return flagsPath , nil
121122}
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