Skip to content

Commit

Permalink
compile: fix export when artifacts contains a folder (#2788)
Browse files Browse the repository at this point in the history
* test that the export binaries should not fail if tries to copy a dir

* compile: fix export binaries when trying to copy a folder
  • Loading branch information
alessio-perugini authored Dec 20, 2024
1 parent d1cc322 commit 0a116e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions commands/service_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Error reading build directory"), Cause: err}
}
buildFiles.FilterPrefix(baseName)
buildFiles.FilterOutDirs()
for _, buildFile := range buildFiles {
exportedFile := exportPath.Join(buildFile.Base())
logrus.WithField("src", buildFile).WithField("dest", exportedFile).Trace("Copying artifact.")
Expand Down
43 changes: 43 additions & 0 deletions internal/integrationtest/compile_1/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,3 +1321,46 @@ func buildWithCustomBuildPathAndOUtputDirFlag(t *testing.T, env *integrationtest
require.NotEmpty(t, content)
}
}

func TestCompileWithOutputDirFlagIgnoringFoldersCreatedByEsp32RainMakerLib(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("update")
require.NoError(t, err)

// Update index with esp32 core and install it
url := "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json"
_, _, err = cli.Run("core", "update-index", "--additional-urls="+url)
require.NoError(t, err)
_, _, err = cli.Run("core", "install", "esp32:[email protected]", "--additional-urls="+url)
require.NoError(t, err)

sketchName := "RainMakerSketch"
sketchPath := cli.SketchbookDir().Join(sketchName)
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)

// When importing the `RMaker` library, the esp32 core produces in output a folder,
// containing all the binaries exported. The name of the folder matches the sketch name.
// In out case:
// cache-dir/
// |- RainMakerSketch.ino/ <--- This should be ignored
// |- RainMakerSketch.ino.uf2
// |- RainMakerSketch.ino.bin
// |- ...
err = sketchPath.Join(sketchName + ".ino").WriteFile([]byte(`
#include "RMaker.h"
void setup() { }
void loop() { }`,
))
require.NoError(t, err)

buildPath := cli.DataDir().Join("test_dir", "build_dir")
outputDir := cli.SketchbookDir().Join("test_dir", "output_dir")
_, stderr, err := cli.Run("compile", "-b", "esp32:esp32:esp32", sketchPath.String(), "--build-path", buildPath.String(), "--output-dir", outputDir.String())
require.NoError(t, err)
require.NotContains(t, stderr, []byte("Error during build: Error copying output file"))
require.DirExists(t, buildPath.Join(sketchName+".ino").String())
require.NoDirExists(t, outputDir.Join(sketchName+".ino").String())
}

0 comments on commit 0a116e7

Please sign in to comment.