arduino / arduino-cli

Arduino command line tool
https://arduino.github.io/arduino-cli/latest/
GNU General Public License v3.0
4.39k stars 384 forks source link

Function prototypes not generated when sketch path contains `"` #1945

Open per1234 opened 2 years ago

per1234 commented 2 years ago

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 automatically generates and adds prototypes for functions defined in a .ino file of a sketch.

šŸ› If the parent path of a sketch contains a double quote character ("), function prototypes are not generated.

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 "void setup() {\n  foo();\n}\nvoid loop() {}\nvoid foo() {}" > /tmp/foo\"bar/SomeSketch/SomeSketch.ino

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

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/foo"bar/SomeSketch/SomeSketch.ino: In function 'void setup()':
/tmp/foo"bar/SomeSketch/SomeSketch.ino:2:3: error: 'foo' was not declared in this scope
   foo();
   ^~~

šŸ› The function prototype for foo was not generated. It will be very difficult for the average user to understand why the compilation failed and how to fix the error.

Expected behavior

Function prototypes are generated regardless of which characters are present in the path.

Arduino CLI version

f2397543

Operating system

Ubuntu, macOS

Operating system version

Additional context

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


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


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

Issue checklist

cmaglie commented 1 year ago

The problem is that the ctags version we are using is not able to parse the #line directive correctly. Here is a patch to ctags https://github.com/arduino/ctags/pull/18 but I'm wondering if it's time to move to a more modern version of ctags.

/cc @umbynos @facchinm

umbynos commented 1 year ago

We could evaluate https://github.com/universal-ctags/ctags or maybe it's time to resurrect https://github.com/arduino/arduino-preprocessor