Skip to content

Multi-file sketches broken by name mismatch resolution feature #2727

Open
@per1234

Description

@per1234

Describe the problem

Arduino sketches may consist of multiple code files:

https://arduino.github.io/arduino-cli/dev/sketch-specification/#additional-code-files

The Arduino sketch folder must have a name matching that of the primary sketch file:

https://arduino.github.io/arduino-cli/dev/sketch-specification/#primary-sketch-file

Unfortunately some of the sketches that are published online do not comply, which might occur for reasons such as:

  • The sketch is in the root of a GitHub repository with an appropriate name, but when the user uses GitHub's "Download ZIP" feature to obtain the sketch, GitHub appends the Git ref to the folder name, causing a mismatch.
  • The sketch developer used some 3rd party development software which does not enforce compliance.
  • The sketch developer was simply sloppy in the way they packaged the sketch for distribution.

If the user opens a sketch which does not have a matching folder name, Arduino IDE helpfully offers to move the sketch to a folder with a matching name to make the sketch valid so that it can be opened in Arduino IDE.

🐛 The feature only moves the single file the user selected from the "Open" dialog, which breaks sketches that consist of multiple code files.

To reproduce

  1. Click the following link to download a demonstration sketch:
    Foo.zip
  2. Extract the downloaded file.
  3. Note that the extracted folder has the following structure:
    Foo/
    ├── Bar.ino
    └── Baz.ino
    
  4. Select File > Open... from the Arduino IDE menus.
  5. Select the Bar.ino file from the extracted Foo folder.
    🙂 A helpful dialog appears:
    Image

    The file "Bar.ino" needs to be inside a sketch folder named "Bar".
    Create this folder, move the file, and continue?

  6. Click the "OK" button in the dialog.
    A sketch named "Bar" opens in a new sketch window.

🐛 The additional code file Baz.ino was not moved to the new folder. The sketch will not compile because it is incomplete due to the missing file.

Expected behavior

The feature for helping the user to resolve an invalid sketch folder name does not break multi-file sketches.

Arduino IDE version

2.3.6

Operating system

All

Operating system version

Any

Additional context

The same problem was also present in Arduino IDE 1.x. The initial proposal was to make it move all files in the original folder to the new folder:

arduino/Arduino#6404

However, the problem with that solution is that the user might have downloaded a single sketch folder into a folder that contains various irrelevant files. In this case, Arduino IDE moving all the irrelevant files to the new sketch folder would not be appropriate.

An alternative proposal was then made to simply remove the feature:

arduino/Arduino#7904

And then a 3rd proposal which attempted to make the feature deciding when it should copy the single file or all files to the new folder:

arduino/Arduino#7909


Examples of the current behavior causing problems:

Related

Workaround

Manually rename the folder to match the name of the primary .ino file before opening the sketch in Arduino IDE.


Keywords

  • "rename"

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions