Skip to content

Commit

Permalink
Make --input-dir handle gracefully some rare cases
Browse files Browse the repository at this point in the history
Using `--input-dir path/to/firmware` with a directory containing:

  path/to/firmware/firmware.ino.bin
  path/to/firmware/some_other_firmware_name.ino.bin

should not fail but select `firmware.ino.bin` for upload because the
containing folder has the same name.

See arduino#765 (comment)
  • Loading branch information
cmaglie committed Sep 29, 2020
1 parent d56e8d4 commit c7855c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) {
return "", err
}

if absBuildPath, err := buildPath.Abs(); err == nil {
candidateName := absBuildPath.Base() + ".ino"
f := files.Clone()
f.FilterPrefix(candidateName + ".")
if f.Len() > 0 {
return candidateName, nil
}
}

candidateName := ""
var candidateFile *paths.Path
for _, file := range files {
Expand Down
5 changes: 5 additions & 0 deletions commands/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
{"", "testdata/build_path_2", blonk, fqbn, "testdata/build_path_2", "Blink.ino"},
// 15: error: used both importPath and importFile
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, fqbn, "<nil>", ""},

// 16: importPath containing multiple firmwares, but one has the same name as the containing folder
{"", "testdata/firmware", nil, fqbn, "testdata/firmware", "firmware.ino"},
// 17: importFile among multiple firmwares
{"testdata/firmware/another_firmware.ino.bin", "", nil, fqbn, "testdata/firmware", "another_firmware.ino"},
}
for i, test := range tests {
t.Run(fmt.Sprintf("SubTest%02d", i), func(t *testing.T) {
Expand Down

0 comments on commit c7855c1

Please sign in to comment.