arduino-cli compile can no longer specify .ino file

Created on 25 Jun 2020  路  13Comments  路  Source: arduino/arduino-cli

Bug Report

Current behavior

On v0.9 of the CLI we can compile a specific ino file via:

$ arduino-cli compile --fqbn arduino:mbed:nano33ble my-sketch.ino

On v0.11 this fails with:

Error during build: unable to find a sketch file in directory XXX

And there seems no way to specify the .ino file anymore. Is there any replacement?

Environment

  • CLI version (output of arduino-cli version): arduino-cli Version: 0.11.0 Commit: 0296f4d
  • OS and platform: macOS Catalina
invalid CLI bug

All 13 comments

Hi @janjongboom,
We solved a couple of bugs regarding the sketch file or folder parsing from command line here https://github.com/arduino/arduino-cli/pull/690

It could be a regression, can you give us more details in order to reproduce the issue?
What is the sketch folder structure you are trying to compile?

@rsora I have a sketch folder (e.g. here-is-my-sketch) and an .ino with a different name (hello.ino). I could previously compile this fine by specifying the hello.ino file at the end of my compile command. This no longer works in 0.11.

The folder containing the sketch must have the same name as the main .ino file and this is due to the way the sketches made by multiple .ino files are preprocessed to obtain the final .cpp file to compile.

For example, if you have a project like this:

~/Arduino/GPS_Tracker/GPS_Module.ino
~/Arduino/GPS_Tracker/GPS_Tracker.ino    <-- main file named as the containing folder
~/Arduino/GPS_Tracker/LCD.ino
~/Arduino/GPS_Tracker/SD.ino

all the .ino files are concatenated together in alphabetic order, _except for the main file_ GPS_Tracker.ino that is always the first -> this is the reason why we need the containing folder to be the same name as the main sketch.

Here you can find the relevant documentation about how a sketch structure https://arduino.github.io/arduino-cli/latest/sketch-specification/#primary-sketch-file

It may be a problem to rename your folders or the sketch .ino so they match?
We may like this requirement or not, but it has always been like this from day 1 of Arduino, changing it now may turn out to be a huge compatiblity mess...

@cmaglie I am trying to understand your arguments but if I specify directly what I want to compile as a cmd parameter I would expect compilation of that file and not getting error (Error during build: unable to find a sketch file in directory ...).

I also experience troubles with your last changes. My project in Gitlab repository has different name than the main *.ino file.

I was trying to use 0.10 version via install.sh script but this script checks for updates and install the 0.11 version anyway. It is also not good. If I use install script from version 0.10 I would expect that the 0.10 will be installed. But it is only my opinion...

@janjongboom and @xplsek01
We recently fixed our install script to support a "version" argument, please see the issue https://github.com/arduino/arduino-cli/pull/766

I'd like to add that this whatever change caused this also seems to have broken other useful features. I used to have very good Eclipse IDE integration via a simple Makefile script that called the arduino-cli. In this scenario, the subdirectory was the same name as the main "sketch", but the main sketch had a .cpp extension, so that eclipse would handle it well and do all of the appropriate edit-time checking, etc. Now that is is broken and it claims it can't find a sketch.

Not understanding why the default behavior can't be as described -- subdir name same as the sketch, with an extension of ".ino", but more advanced users can specify other parameters (that USED to work just fine).

Happy to provide a copy of my Makefile if that would help.

Another vote here for specifying the file to be complied. I don't even use .ino files, since they break compatibility with editors that know how to handle .cpp files. Previously it worked just fine for those that provided their own main.cpp file rather than relying on the .ino wrapper.

The easy workaround for third-party IDE integration as described above would be to add an empty .ino file matching the directory name, to indicate to arduino-cli that this is indeed an Arduino sketch, but then just keep all your code in .cpp files so you can edit those files with your IDE optimally.

Also note that the change mentioned in the first post seems like a regression in arduino-cli, but this should be viewed in the context of the entire Arduino ecosystem: Before, arduino-cli allowed compiling sketches that the Java IDE would reject. IMHO, the concept of a "Sketch" should be consistent between all tools, so the change in arduino-cli was really a fix to make arduino-cli consistent with all other tools in the ecosystem.

Of course, the notion of what constitutes a sketch can be changed in all Arduino tools, see #948 for discussion about this.

Just came across this regression myself. The offending code is here:

https://github.com/arduino/arduino-cli/pull/690/files#diff-76bc1d481fc32adae0d5a4ee3b2ccdf0R46

Prior to this, a full sketch path (including .ino file) could be specified. After this change it always ignores any sketch file passed and forces it to expect the sketch to be the same name as the containing folder.

Can this be fixed?

@thegecko
like @matthijskooijman explains in the comment just before yours, arduino-cli allows you to do a lot of things but we still need to be consistent with our whole concept of Sketch.
A Sketch is not the .ino file itself but the whole folder and including (if present) a sketch.json file withe board/port association and (in the future) more things related to libraries, versions and so on.
Before beginning to work on this project I often found myself struggling with the fact that the main file should be contained by a folder with its name, but then made peace with it once I learned what the structure of a sketch is supposed to be.
Believe me when I say that a lot of thinking goes behind defining these workflows :)

Because many Arduino sketches only contain a single .ino file, it's easy to think of that file as the sketch. However, it is the folder that is the sketch. The reason is that sketches may consist of multiple code files and the folder is what groups those files into a single program.

https://arduino.github.io/arduino-cli/latest/sketch-specification/

So this behavior broke again in the 0.13 release. As we have zero control over the folder name where the .ino.bin is in (as it's downloaded) we make a copy of the ino.bin to foldername.ino.bin - which we created as a response to this issue. This worked fine in 0.11 and 0.12, and now this no longer works:

Error during Upload: retrieving build artifacts: autodetect build artifact: multiple build artifacts found: 'ei-custom-keywords-local-deployment-arduino-nano-33-ble-sense-1601039830533.ino.bin' and 'firmware.ino.bin'

I realize that this is technically not a 1.0 release of the CLI, but the constant breaking of the API is very annoying as there's zero heads-up on our end and the only way we realize this is from complaining customers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ricms93 picture ricms93  路  4Comments

martsalz picture martsalz  路  7Comments

jonathangjertsen picture jonathangjertsen  路  5Comments

Renaud11232 picture Renaud11232  路  8Comments

nkieffer picture nkieffer  路  7Comments