Verify/Upload uses wrong file as "main file" #1100
Description
VSCode version: 1.48.2
vscode-arduino version: 0.3.2
I'm starting an Arduino project that will span multiple boards. I have subfolders for each board's project, such that the filesystem structure looks like this:
.vscode/
|- arduino.json
|- c_cpp_properties.json
|- settings.json
board1/
|- main_board1.ino
board2/
|- main_board2.ino
|- Utility.h
obj/ # This is the "output" folder in arduino.json
This seems to work fine at first, despite the inconvenience of having to manually switch which .ino
sketch is active in arduino.json
. However, I discovered once I added that Utility.h
file in board2/
that it seems the Upload/Verify commands are passing the wrong "main" file to Arduino when there is more than one file in the folder.
main_board1.ino
does not include anything, and main_board2.ino
starts with this:
#include "Utility.h"
When board1/main_board1.ino
is the active sketch, it verifies fine. However when board2/main_board2.ino
is the active sketch, it throws a compile error:
main_board2:1:10: fatal error: Utility.h: No such file or directory
#include "Utility.h"
^~~~~~~~~~~
Oddly, if I create a Utility.cpp
file and have it include Utility.h
, it compiles fine. It doesn't have to have anything in it other than #include "Utility.h"
.
I looked at the verbose build logs and noticed something. When compiling board1/main_board1.ino
I see the following:
D:\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Arduino\hardware -hardware C:\Users\[Username]\AppData\Local\Arduino15\packages -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -tools C:\Users\[Username]\AppData\Local\Arduino15\packages -built-in-libraries D:\Arduino\libraries -libraries D:\Users\[Username]\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10813 -build-path c:\Development\Projects\Arduino\BugReproduction\obj -warnings=null -prefs=build.path=c:\Development\Projects\Arduino\BugReproduction\obj -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\Arduino\hardware\tools\avr -verbose c:\Development\Projects\Arduino\BugReproduction\board1\main_board1.ino
D:\Arduino\arduino-builder -compile -logger=machine -hardware D:\Arduino\hardware -hardware C:\Users\[Username]\AppData\Local\Arduino15\packages -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -tools C:\Users\[Username]\AppData\Local\Arduino15\packages -built-in-libraries D:\Arduino\libraries -libraries D:\Users\[Username]\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10813 -build-path c:\Development\Projects\Arduino\BugReproduction\obj -warnings=null -prefs=build.path=c:\Development\Projects\Arduino\BugReproduction\obj -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\Arduino\hardware\tools\avr -verbose c:\Development\Projects\Arduino\BugReproduction\board1\main_board1.ino
However when compiling board2/main_board2.ino
, I see the following:
D:\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Arduino\hardware -hardware C:\Users\[Username]\AppData\Local\Arduino15\packages -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -tools C:\Users\[Username]\AppData\Local\Arduino15\packages -built-in-libraries D:\Arduino\libraries -libraries D:\Users\[Username]\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10813 -build-path c:\Development\Projects\Arduino\BugReproduction\obj -warnings=null -prefs=build.path=c:\Development\Projects\Arduino\BugReproduction\obj -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\Arduino\hardware\tools\avr -verbose c:\Development\Projects\Arduino\BugReproduction\board2\Utility.h
D:\Arduino\arduino-builder -compile -logger=machine -hardware D:\Arduino\hardware -hardware C:\Users\[Username]\AppData\Local\Arduino15\packages -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -tools C:\Users\[Username]\AppData\Local\Arduino15\packages -built-in-libraries D:\Arduino\libraries -libraries D:\Users\[Username]\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10813 -build-path c:\Development\Projects\Arduino\BugReproduction\obj -warnings=null -prefs=build.path=c:\Development\Projects\Arduino\BugReproduction\obj -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=D:\Arduino\hardware\tools\avr -verbose c:\Development\Projects\Arduino\BugReproduction\board2\Utility.h
The thing to note is that when compiling board1/main_board1.ino
, the "entry point" file passed to arduino-build
is in fact board1/main_board1.ino
, yet when compiling board2/main_board2.ino
, the "entry point" is actually Utility.h
. It tries to compile a Utility.cpp
file even if one does not exist.
In the obj/sketch/
folder, I can see files named Utility.cpp.cpp
, Utility.cpp.cpp.d
, and Utility.cpp.cpp.o
.
If I manually invoke the above commands for board2/main_board2.ino
but change the final arduino-build
argument from the Utility.h
file to the board2/main_board2.ino
file, it compiles fine even without the Utility.cpp
file present.
I've attached a small reproduction project:
BugReproduction.zip