-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Sketch compiling via commandline does not check for valid primary .ino filename #10755
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
Comments
It's not just an arbitrary restriction, the .ino-file-that-matches-the-directory is also the primary file that should be the first when joining multiple .ino files, so it does actually influence the compilation result. I was going to write that not having a "primary" file would make it impossible to have a specific file as the "first" file, but things could just fall back to sorting all .ino files alphabetically or so and then that would be the order. If you do care about one file being primary, then you can just name it after the folder. One caveat is that if someone renames the folder, but not the primary .ino file, then the compilation might break due to reordering (currently, the sketch fails to load, which is probably slightly better). As for the compilation itself, this is done by |
One more thought: In your PR, you make the .ino file passed on the commandline the "primary" one, but that seems a bit fragile: Depending on what .ino file you pass, the compilation result might change. Also, when you have an arbitrary sketch with multiple .ino files, then you would have to remember which of the .ino files is supposed to be the primary one to make the sketch work. If this restriction is dropped, I would rather suggest that when there is no matching .ino file, there is simply no primary file at all and compilation should just treat all .ino files equally (and probably in alphabetical order). But again, the behavior of arduino-builder in this area seems also relevant. The bug you report here is not so much about this restriction, but a bug that causes a non-.ino file to be passed to arduino-builder I think. |
They don't, and there is no such feature planned. The problem arises with sketch made by multiple We may like it or not, but this is how it worked from day 0, doesn't look like a good idea to change this behavior now. |
I wasn't suggesting to change that, just to not enforce that there is a primary .ino file. AFAIK, currently the compilation order of .ino files is:
It might be easy to just make 1. optional and if it is not present, just use all .ino files in alphabetical order? That should be 100% backward compatible, any sketches that are currently supported are still supported, you just add some more options. If we choose not to relax this requirement, then the commandline
I just tested this, it seems that |
the
my main concern is that if you try to open an "invalid" sketch with the IDE GUI you get a dialog like this: so if we do as you suggest:
As I said, this issue comes back from time to time, but it's trickier than it seems. If we really want to fix this I suggest we move the discussion in the arduino-cli repo to find the less disruptive solution. |
My suggestion would be to simply drop this limitation everywhere, so the GUI prompt you mention in 1. would be dropped, and of course arduino-cli would also need to be changed, which solves 3. Number 2 is indeed an issue, though one could argue that it's a small inconvenience in exchange for more freedom in naming sketches. Agreed that this is not the ideal place to discuss this change, this issue should probably be about the missing check in the IDE now. Even though I'm not super-interested in changing this policy, it seems there have been some useful arguments in this discussion, so I've created a separate issue for this: arduino/arduino-cli#948 |
@briman0094, I've closed your PR as I think that is not the correct approach here (see the PR for detailed comments). I can see two ways forward:
|
Perhaps it's best to throw a clear error from the command line then, instead of letting the current undeterministic behavior cause random compile errors due to a random file being picked as the "entry point". While trying to figure out what was going on, I stumbled across quite a few threads on the Arduino forums in which it was recommended to not have multiple I guess that's not the point of multiple |
This is indeed not how things were intended. I guess the usecase in itself is interesting to explore, but that should then be the subject of a new issue (probably in arduino-cli as well). |
When the Arduino IDE is invoked via the command line for a Verify or Upload task, such as when an external tool like microsoft/vscode-arduino invokes a build, but the name of the sketch file provided on the command line does not match its containing folder name, the first file from
FileUtils.listFiles
is used as the "primary" file, resulting in undefined behavior (the order returned bylistFiles
seems non-deterministic) and apparent obscure bugs such as the one I filed at microsoft/vscode-arduino#1100.The requirement to have the
.ino
file match the folder name seems arbitrary and restrictive for command-line compilations when the IDE itself is not being used for development. I developed a simple fix for this on my own branch and plan on filing a PR.The text was updated successfully, but these errors were encountered: