@@ -40,6 +40,12 @@ func generateCpp(inoCode []byte, sourcePath, fqbn string) (cppPath string, cppCo
4040 log .Println ("Source file written to" , inoPath )
4141 }
4242
43+ // Copy all header files to temp dir
44+ err = copyHeaderFiles (filepath .Dir (sourcePath ), tempDir )
45+ if err != nil {
46+ return
47+ }
48+
4349 // Generate compile_flags.txt
4450 cppPath = filepath .Join (tempDir , name + ".cpp" )
4551 flagsPath , err := generateCompileFlags (tempDir , inoPath , sourcePath , fqbn )
@@ -55,6 +61,27 @@ func generateCpp(inoCode []byte, sourcePath, fqbn string) (cppPath string, cppCo
5561 return
5662}
5763
64+ func copyHeaderFiles (sourceDir string , destDir string ) error {
65+ fileInfos , err := ioutil .ReadDir (sourceDir )
66+ if err != nil {
67+ return err
68+ }
69+ for _ , fileInfo := range fileInfos {
70+ if ! fileInfo .IsDir () && strings .HasSuffix (fileInfo .Name (), ".h" ) {
71+ input , err := ioutil .ReadFile (filepath .Join (sourceDir , fileInfo .Name ()))
72+ if err != nil {
73+ return err
74+ }
75+
76+ err = ioutil .WriteFile (filepath .Join (destDir , fileInfo .Name ()), input , 0644 )
77+ if err != nil {
78+ return err
79+ }
80+ }
81+ }
82+ return nil
83+ }
84+
5885func updateCpp (inoCode []byte , sourcePath , fqbn string , fqbnChanged bool , cppPath string ) (cppCode []byte , err error ) {
5986 tempDir := filepath .Dir (cppPath )
6087 inoPath := strings .TrimSuffix (cppPath , ".cpp" )
@@ -132,6 +159,9 @@ func generateTargetFile(tempDir, inoPath, cppPath, fqbn string) (cppCode []byte,
132159 return
133160 }
134161
162+ // Filter lines beginning with ERROR or WARNING
163+ cppCode = []byte (filterErrorsAndWarnings (cppCode ))
164+
135165 err = ioutil .WriteFile (cppPath , cppCode , 0600 )
136166 if err != nil {
137167 err = errors .Wrap (err , "Error while writing target file to temporary directory." )
@@ -141,6 +171,19 @@ func generateTargetFile(tempDir, inoPath, cppPath, fqbn string) (cppCode []byte,
141171 return
142172}
143173
174+ func filterErrorsAndWarnings (cppCode []byte ) string {
175+ var sb strings.Builder
176+ scanner := bufio .NewScanner (bytes .NewReader (cppCode ))
177+ for scanner .Scan () {
178+ lineStr := scanner .Text ()
179+ if ! (strings .HasPrefix (lineStr , "ERROR:" ) || strings .HasPrefix (lineStr , "WARNING:" )) {
180+ sb .WriteString (lineStr )
181+ sb .WriteRune ('\n' )
182+ }
183+ }
184+ return sb .String ()
185+ }
186+
144187func copyIno2Cpp (inoCode string , cppPath string ) (cppCode []byte , err error ) {
145188 inoPath := strings .TrimSuffix (cppPath , ".cpp" )
146189 filePrefix := "#include <Arduino.h>\n #line 1 \" " + inoPath + "\" \n "
0 commit comments