Skip to content

#line directive inserted incorrectly when sketch under path w/ " and contains #include <Arduino.h> #1946

Open
@per1234

Description

@per1234

Describe the problem

In order to make it easier for beginners to get started with writing Arduino sketches, and for the convenience of all users, Arduino CLI does some minor preprocessing of the .ino files of a sketch to convert them to C++.

This preprocessing includes adding lines to the code and changing the file name. In order to cause the warning and error messages from the compiler to match the file names and line numbers of the user's sketch code, #line directives are inserted by the preprocessor.

🐛 A #line directive is inserted incorrectly under the following conditions:

  • A parent path of the sketch contains a double quote character (")
  • The sketch contains an #include directive for Arduino.h

To reproduce

$ arduino-cli version
arduino-cli  Version: nightly-20221024 Commit: 5efa9b5 Date: 2022-10-24T01:36:36Z

$ mkdir --parents /tmp/foo\"bar/SomeSketch

$ printf "#include <Arduino.h>\nvoid setup() {}\nvoid loop() {}" > /tmp/foo\"bar/SomeSketch/SomeSketch.ino

$ arduino-cli compile --fqbn arduino:avr:uno --preprocess /tmp/foo\"bar/SomeSketch
##line 3 "/tmp/foo\\"
void loop();
#line 0 "/tmp/foo\\"
line 1 "/tmp/foo\"bar/SomeSketch/SomeSketch.ino"
#include <Arduino.h>
void setup() {}
void loop() {}


Used platform Version Path                                                    
arduino:avr   1.8.5   /home/per/.arduino15/packages/arduino/hardware/avr/1.8.5

$ arduino-cli compile --fqbn arduino:avr:uno /tmp/foo\"bar/SomeSketch
/tmp/arduino-sketch-6C01938A31CAC1E8EFDFDDED0AC852A3/sketch/SomeSketch.ino.cpp:1:1: error: stray '##' in program
 ##line 3 "/tmp/foo\\"
 ^~
/tmp/arduino-sketch-6C01938A31CAC1E8EFDFDDED0AC852A3/sketch/SomeSketch.ino.cpp:1:3: error: 'line' does not name a type; did you mean 'sinf'?
 ##line 3 "/tmp/foo\\"
   ^~~~
   sinf
/tmp/foo\:0:1: error: 'line' does not name a type; did you mean 'sinf'?
In file included from /home/per/.arduino15/packages/arduino/hardware/avr/1.8.5/cores/arduino/Arduino.h:23:0,
                 from /tmp/foo\:1:
/home/per/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include/stdlib.h:153:61: error: 'size_t' has not been declared
 extern void *bsearch(const void *__key, const void *__base, size_t __nmemb,
                                                             ^~~~~~
[... many more lines of errors]

🐛 The corrupted #line directive caused the sketch compilation to fail with cryptic errors. It will be very difficult for the average user to understand why the compilation failed and how to fix the error.

🐛 Even the #line directive that is syntactically valid has an incorrect path due to it being truncated at the " character.

Expected behavior

#line directives are inserted correctly regardless of which characters are present in the path and which #include directives are present in the sketch.

Arduino CLI version

f239754

Operating system

Ubuntu, macOS

Operating system version

  • Ubuntu 20.04
  • macOS 12.6

Additional context

The bug is not applicable to Windows because " is not an allowed character for Windows paths.


The #include directive for the Arduino.h file specifically is a required condition. The bug does not occur for sketches that only contain #include directives for other files.


Note this is not about supporting double quotes in sketch filenames. This is about their presence in the parent path of the sketch.


Related: #1945


Originally reported at https://forum.arduino.cc/t/mac-montery-and-library-update/1041060/21

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

topic: build-processRelated to the sketch build processtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions