From 8918527986a9e73d7f98b19bd71d21e46e12a56c Mon Sep 17 00:00:00 2001 From: giuliano Date: Sat, 7 Jan 2023 18:36:00 +0100 Subject: [PATCH 1/2] Store all temporary files under a single folder named "arduino" in tmp dir. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #2028 Any temporary file will be persisted in a new dedicated folder named as "arduino" located in the OS-specific temporary directory, e.g.: /tmp/ ├── arduino │   ├── arduino-core-cache │   │   └── core_arduino_avr_uno_640aa5b4d646262327bbea65c3462b39.a │   └── arduino-sketch-89E1544CF5F196B29E530BA6940B661F │   ├── 06.ino.elf │   ├── 06.ino.with_bootloader.bin │   ├── build.options.json │   ├── compile_commands.json │   ├── core │   │   ├── abi.cpp.d [...] This change is meant to make easier maintenance operations for both end-users and operating-systems. Signed-off-by: giuliano --- arduino/sketch/sketch.go | 2 +- arduino/sketch/sketch_test.go | 4 ++-- commands/compile/compile.go | 2 +- internal/integrationtest/compile_1/compile_test.go | 8 ++++---- internal/integrationtest/compile_2/compile_test.go | 2 +- internal/integrationtest/core/core_test.go | 2 +- internal/integrationtest/upload_mock/upload_mock_test.go | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arduino/sketch/sketch.go b/arduino/sketch/sketch.go index 28aed70d861..cf9bfbef3be 100644 --- a/arduino/sketch/sketch.go +++ b/arduino/sketch/sketch.go @@ -302,5 +302,5 @@ func GenBuildPath(sketchPath *paths.Path) *paths.Path { } md5SumBytes := md5.Sum([]byte(path)) md5Sum := strings.ToUpper(hex.EncodeToString(md5SumBytes[:])) - return paths.TempDir().Join("arduino-sketch-" + md5Sum) + return paths.TempDir().Join("arduino/arduino-sketch-" + md5Sum) } diff --git a/arduino/sketch/sketch_test.go b/arduino/sketch/sketch_test.go index 87bf6e63543..d0668729ab3 100644 --- a/arduino/sketch/sketch_test.go +++ b/arduino/sketch/sketch_test.go @@ -286,10 +286,10 @@ func TestNewSketchFolderSymlink(t *testing.T) { } func TestGenBuildPath(t *testing.T) { - want := paths.TempDir().Join("arduino-sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8") + want := paths.TempDir().Join("arduino/arduino-sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8") assert.True(t, GenBuildPath(paths.New("foo")).EquivalentTo(want)) - want = paths.TempDir().Join("arduino-sketch-D41D8CD98F00B204E9800998ECF8427E") + want = paths.TempDir().Join("arduino/arduino-sketch-D41D8CD98F00B204E9800998ECF8427E") assert.True(t, GenBuildPath(nil).EquivalentTo(want)) } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index be605746b93..f84cbcefa88 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -143,7 +143,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream // Optimize for debug builderCtx.OptimizeForDebug = req.GetOptimizeForDebug() - builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino-core-cache") + builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino/arduino-core-cache") builderCtx.Jobs = int(req.GetJobs()) diff --git a/internal/integrationtest/compile_1/compile_test.go b/internal/integrationtest/compile_1/compile_test.go index 7702ba0e4df..6ad6c375d64 100644 --- a/internal/integrationtest/compile_1/compile_test.go +++ b/internal/integrationtest/compile_1/compile_test.go @@ -140,7 +140,7 @@ func compileWithSimpleSketch(t *testing.T, env *integrationtest.Environment, cli md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String()) @@ -374,7 +374,7 @@ func compileWithOutputDirFlag(t *testing.T, env *integrationtest.Environment, cl md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String()) @@ -441,7 +441,7 @@ func compileWithCustomBuildPath(t *testing.T, env *integrationtest.Environment, md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String()) require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String()) require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String()) @@ -975,7 +975,7 @@ func compileWithInvalidBuildOptionJson(t *testing.T, env *integrationtest.Enviro md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) _, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--verbose") require.NoError(t, err) diff --git a/internal/integrationtest/compile_2/compile_test.go b/internal/integrationtest/compile_2/compile_test.go index c59c18d839e..3487dacb480 100644 --- a/internal/integrationtest/compile_2/compile_test.go +++ b/internal/integrationtest/compile_2/compile_test.go @@ -145,7 +145,7 @@ func recompileWithDifferentLibrary(t *testing.T, env *integrationtest.Environmen md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) // Compile sketch using library not managed by CLI stdout, _, err := cli.Run("compile", "-b", fqbn, "--library", manuallyInstalledLibPath.String(), sketchPath.String(), "-v") diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index 16ac2e4fc3b..e0f503978f4 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -253,7 +253,7 @@ func TestCoreInstallEsp32(t *testing.T) { md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) require.FileExists(t, buildDir.Join(sketchName+".ino.partitions.bin").String()) } diff --git a/internal/integrationtest/upload_mock/upload_mock_test.go b/internal/integrationtest/upload_mock/upload_mock_test.go index db304ad8aec..26a0d395ade 100644 --- a/internal/integrationtest/upload_mock/upload_mock_test.go +++ b/internal/integrationtest/upload_mock/upload_mock_test.go @@ -697,7 +697,7 @@ func TestUploadSketch(t *testing.T) { func generateBuildDir(sketchPath *paths.Path, t *testing.T) *paths.Path { md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) - buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) require.NoError(t, buildDir.MkdirAll()) require.NoError(t, buildDir.ToAbs()) return buildDir From 2b561313d94d515ff5981f2230caa5d0d4de085b Mon Sep 17 00:00:00 2001 From: giuliano Date: Mon, 9 Jan 2023 18:09:31 +0100 Subject: [PATCH 2/2] remove forward slash to guarantee cross-platform compatibility and strip 'arduino' from cache and sketch tmp folders' name --- arduino/sketch/sketch.go | 2 +- arduino/sketch/sketch_test.go | 4 ++-- commands/compile/compile.go | 2 +- internal/integrationtest/compile_1/compile_test.go | 8 ++++---- internal/integrationtest/compile_2/compile_test.go | 2 +- internal/integrationtest/core/core_test.go | 2 +- internal/integrationtest/upload_mock/upload_mock_test.go | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arduino/sketch/sketch.go b/arduino/sketch/sketch.go index cf9bfbef3be..337aa904d57 100644 --- a/arduino/sketch/sketch.go +++ b/arduino/sketch/sketch.go @@ -302,5 +302,5 @@ func GenBuildPath(sketchPath *paths.Path) *paths.Path { } md5SumBytes := md5.Sum([]byte(path)) md5Sum := strings.ToUpper(hex.EncodeToString(md5SumBytes[:])) - return paths.TempDir().Join("arduino/arduino-sketch-" + md5Sum) + return paths.TempDir().Join("arduino", "sketch-"+md5Sum) } diff --git a/arduino/sketch/sketch_test.go b/arduino/sketch/sketch_test.go index d0668729ab3..cb7b624ab12 100644 --- a/arduino/sketch/sketch_test.go +++ b/arduino/sketch/sketch_test.go @@ -286,10 +286,10 @@ func TestNewSketchFolderSymlink(t *testing.T) { } func TestGenBuildPath(t *testing.T) { - want := paths.TempDir().Join("arduino/arduino-sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8") + want := paths.TempDir().Join("arduino", "sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8") assert.True(t, GenBuildPath(paths.New("foo")).EquivalentTo(want)) - want = paths.TempDir().Join("arduino/arduino-sketch-D41D8CD98F00B204E9800998ECF8427E") + want = paths.TempDir().Join("arduino", "sketch-D41D8CD98F00B204E9800998ECF8427E") assert.True(t, GenBuildPath(nil).EquivalentTo(want)) } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index f84cbcefa88..c7207760fb0 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -143,7 +143,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream // Optimize for debug builderCtx.OptimizeForDebug = req.GetOptimizeForDebug() - builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino/arduino-core-cache") + builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino", "core-cache") builderCtx.Jobs = int(req.GetJobs()) diff --git a/internal/integrationtest/compile_1/compile_test.go b/internal/integrationtest/compile_1/compile_test.go index 6ad6c375d64..aa8bad05d1f 100644 --- a/internal/integrationtest/compile_1/compile_test.go +++ b/internal/integrationtest/compile_1/compile_test.go @@ -140,7 +140,7 @@ func compileWithSimpleSketch(t *testing.T, env *integrationtest.Environment, cli md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String()) @@ -374,7 +374,7 @@ func compileWithOutputDirFlag(t *testing.T, env *integrationtest.Environment, cl md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String()) require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String()) @@ -441,7 +441,7 @@ func compileWithCustomBuildPath(t *testing.T, env *integrationtest.Environment, md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String()) require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String()) require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String()) @@ -975,7 +975,7 @@ func compileWithInvalidBuildOptionJson(t *testing.T, env *integrationtest.Enviro md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) _, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--verbose") require.NoError(t, err) diff --git a/internal/integrationtest/compile_2/compile_test.go b/internal/integrationtest/compile_2/compile_test.go index 3487dacb480..dc67aeaf2b0 100644 --- a/internal/integrationtest/compile_2/compile_test.go +++ b/internal/integrationtest/compile_2/compile_test.go @@ -145,7 +145,7 @@ func recompileWithDifferentLibrary(t *testing.T, env *integrationtest.Environmen md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) // Compile sketch using library not managed by CLI stdout, _, err := cli.Run("compile", "-b", fqbn, "--library", manuallyInstalledLibPath.String(), sketchPath.String(), "-v") diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index e0f503978f4..cea3c33195b 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -253,7 +253,7 @@ func TestCoreInstallEsp32(t *testing.T) { md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) require.NotEmpty(t, sketchPathMd5) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) require.FileExists(t, buildDir.Join(sketchName+".ino.partitions.bin").String()) } diff --git a/internal/integrationtest/upload_mock/upload_mock_test.go b/internal/integrationtest/upload_mock/upload_mock_test.go index 26a0d395ade..208e48fd772 100644 --- a/internal/integrationtest/upload_mock/upload_mock_test.go +++ b/internal/integrationtest/upload_mock/upload_mock_test.go @@ -697,7 +697,7 @@ func TestUploadSketch(t *testing.T) { func generateBuildDir(sketchPath *paths.Path, t *testing.T) *paths.Path { md5 := md5.Sum(([]byte(sketchPath.String()))) sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) - buildDir := paths.TempDir().Join("arduino/arduino-sketch-" + sketchPathMd5) + buildDir := paths.TempDir().Join("arduino", "sketch-"+sketchPathMd5) require.NoError(t, buildDir.MkdirAll()) require.NoError(t, buildDir.ToAbs()) return buildDir