Skip to content

Commit

Permalink
Store all temporary files under a single folder (arduino#2031)
Browse files Browse the repository at this point in the history
Fix arduino#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 <panzironi.giuliano@gmail.com>
  • Loading branch information
giulianopz authored Jan 10, 2023
1 parent c0d4e44 commit 34762a6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion arduino/sketch/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "sketch-"+md5Sum)
}
4 changes: 2 additions & 2 deletions arduino/sketch/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8")
assert.True(t, GenBuildPath(paths.New("foo")).EquivalentTo(want))

want = paths.TempDir().Join("arduino-sketch-D41D8CD98F00B204E9800998ECF8427E")
want = paths.TempDir().Join("arduino", "sketch-D41D8CD98F00B204E9800998ECF8427E")
assert.True(t, GenBuildPath(nil).EquivalentTo(want))
}

Expand Down
2 changes: 1 addition & 1 deletion commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "core-cache")

builderCtx.Jobs = int(req.GetJobs())

Expand Down
8 changes: 4 additions & 4 deletions internal/integrationtest/compile_1/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "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())
Expand Down Expand Up @@ -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", "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())
Expand Down Expand Up @@ -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", "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())
Expand Down Expand Up @@ -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", "sketch-"+sketchPathMd5)

_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--verbose")
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/integrationtest/compile_2/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "sketch-"+sketchPathMd5)

// Compile sketch using library not managed by CLI
stdout, _, err := cli.Run("compile", "-b", fqbn, "--library", manuallyInstalledLibPath.String(), sketchPath.String(), "-v")
Expand Down
2 changes: 1 addition & 1 deletion internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "sketch-"+sketchPathMd5)
require.FileExists(t, buildDir.Join(sketchName+".ino.partitions.bin").String())
}

Expand Down
2 changes: 1 addition & 1 deletion internal/integrationtest/upload_mock/upload_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "sketch-"+sketchPathMd5)
require.NoError(t, buildDir.MkdirAll())
require.NoError(t, buildDir.ToAbs())
return buildDir
Expand Down

0 comments on commit 34762a6

Please sign in to comment.