arduino-builder icon indicating copy to clipboard operation
arduino-builder copied to clipboard

Make include detection for old compilers more robust

Open matthijskooijman opened this issue 9 years ago • 1 comments
trafficstars

To figure out what libraries a sketch needs, it is processed by the gcc preprocessor, and its error output is analyzed to figure out what header file is missing. Normally, the compiler outputs an error message followed by the actual source line that has the error, like:

/path/to/foo.ino:1:22: fatal error: somefile.h: No such file or directory
 #include <somefile.h>
                      ^

By matching these lines for #include, the missing filename is found.

However, older compilers do not include this source line, but just the error message:

/path/to/foo.ino:1:22: fatal error: somefile.h: No such file or directory

Currently, there is a fallback that splits on a colon, looks for "fatal error" and then returns the next part of the error message as the filename. This seems to work so far, but is also fairly fragile to changes in the error message.

A better approach might be to instead look at the /path/to/foo.ino:1:22 part (which I expect to be more reliable), load the named file, look up the given line number and see if there is any #include in that line. I believe that would be more reliable, and would make the fallback processing more in-line with the normal processing (by scanning for #include).

matthijskooijman avatar May 18 '16 18:05 matthijskooijman

Related: https://github.com/arduino/arduino-builder/issues/259

per1234 avatar Oct 14 '21 07:10 per1234