Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
per1234 opened this issue Oct 25, 2022 · 0 comments
Assignees
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Oct 25, 2022

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
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project topic: build-process Related to the sketch build process labels Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants