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

[Proposal] Mangle build.arch if cloned from git #721

Open facchinm opened 4 years ago

facchinm commented 4 years ago

Bug Report

Almost all our cores in github are called ArduinoCore-$architecture. When cloned through git, the folder name is preserved and everything seems to work unless some code uses ARDUINO_ARCH_{build.arch} pattern.

In this case, we normally expand in ARDUINO_ARCH_ARDUINOCORE-$ARCH which is not expected.

Proposal: if a core is recognized to be in a folder with ArduinoCore-$arch pattern, modify targetPlatform.Platform.Architecture to keep only the string after the dash

https://github.com/arduino/arduino-cli/blob/5b805ddab199101deca72c72f4c56e9c3cefcf59/legacy/builder/setup_build_properties.go#L51

Current behavior

Clone ArduinoCore-avr in $sketchbook/hardware/arduino_git Run arduino-cli --fqbn arduino_git:ArduinoCore-avr:uno compile ... The gcc verbose commandline will contain -DARDUINO_ARCH_ARDUINOCORE-AVR

Expected behavior

The gcc verbose commandline should contain -DARDUINO_ARCH_AVR

Environment

Additional context

@Polldo

matthijskooijman commented 4 years ago

everything seems to work unless some code uses ARDUINOARCH{build.arch} pattern.

Also, I think core references do not work (e.g. someboard.build.core=arduino:arduino or something like that in a derived core that uses e.g. avr as the arch name).

if a core is recognized to be in a folder with ArduinoCore-$arch pattern, modify targetPlatform.Platform.Architecture to keep only the string after the dash

I'm not sure I like this mangling much. It seems rather hardcoded and specific to the Arduino repository structure (e.g. won't work for, say, https://github.com/stm32duino/Arduino_Core_STM32).

Thinking about more general solutions, how about putting the arch (and maybe also the package, so the first part of arduino:avr) in platform.txt? That means the exact directory name is no longer relevant. Maybe you could even allow cloning repositories directly in sketchbook/hardware, then at some point. For compatibility with older IDE and arduino-cli versions, it would make sense to still name the directory e.g. arduino/avr, but if platform.txt knows the right values, arduino-cli can actually show a warning if the directory name is incorrect (which might already be a reasonable solution for the problem at hand?).

One complication of putting arch and package in platform.txt, is that it becomes harder to use two versions side by side (e.g. I now have sketchbook/arduino-git/avr to distinguish it from the arduino:avr platform installed through the board manager). You can still do this, but that needs modifications to platform.txt (though I guess that's exactly what platform.local.tx is for, of course).