Skip to content

Commit 6a7d47f

Browse files
committed
--build-cache-path now contains also the sketches
1 parent 23888af commit 6a7d47f

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

commands/service_compile.go

+12-16
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
162162

163163
// Generate or retrieve build path
164164
var buildPath *paths.Path
165-
isDefaultBuildPath := false
166165
if buildPathArg := req.GetBuildPath(); buildPathArg != "" {
167166
buildPath = paths.New(req.GetBuildPath()).Canonical()
168167
if in, _ := buildPath.IsInsideDir(sk.FullPath); in && buildPath.IsDir() {
@@ -171,24 +170,10 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
171170
}
172171
}
173172
}
174-
if buildPath == nil {
175-
buildPath = sk.DefaultBuildPath()
176-
isDefaultBuildPath = true
177-
}
178-
if err = buildPath.MkdirAll(); err != nil {
179-
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build directory"), Cause: err}
180-
}
181173

182174
var coreBuildCachePath *paths.Path
183175
var extraCoreBuildCachePaths paths.PathList
184-
if isDefaultBuildPath {
185-
buildcache.New(buildPath.Parent()).GetOrCreate(buildPath.Base())
186-
// cache is purged after compilation to not remove entries that might be required
187-
188-
defer maybePurgeBuildCache(
189-
s.settings.GetCompilationsBeforeBuildCachePurge(),
190-
s.settings.GetBuildCacheTTL().Abs())
191-
176+
if buildPath == nil {
192177
var buildCachePath *paths.Path
193178
if req.GetBuildCachePath() != "" {
194179
p, err := paths.New(req.GetBuildCachePath()).Abs()
@@ -214,6 +199,17 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
214199
for i, p := range extraCoreBuildCachePaths {
215200
extraCoreBuildCachePaths[i] = p.Join("cores")
216201
}
202+
203+
buildPath = sk.DefaultBuildPath(buildCachePath)
204+
buildcache.New(buildPath.Parent()).GetOrCreate(buildPath.Base())
205+
206+
// cache is purged after compilation to not remove entries that might be required
207+
defer maybePurgeBuildCache(
208+
s.settings.GetCompilationsBeforeBuildCachePurge(),
209+
s.settings.GetBuildCacheTTL().Abs())
210+
}
211+
if err = buildPath.MkdirAll(); err != nil {
212+
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build directory"), Cause: err}
217213
}
218214

219215
if _, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform); err != nil {

commands/service_debug_config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
109109
}
110110
sketchName = sk.Name
111111
sketchDefaultFQBN = sk.GetDefaultFQBN()
112-
sketchDefaultBuildPath = sk.DefaultBuildPath()
112+
sketchDefaultBuildPath = sk.DefaultBuildPath(nil)
113113
} else {
114114
// Use placeholder sketch data
115115
sketchName = "Sketch"

commands/service_upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ func determineBuildPathAndSketchName(importFile, importDir string, sk *sketch.Sk
788788

789789
// Case 4: only sketch specified. In this case we use the generated build path
790790
// and the given sketch name.
791-
return sk.DefaultBuildPath(), sk.Name + sk.MainFile.Ext(), nil
791+
return sk.DefaultBuildPath(nil), sk.Name + sk.MainFile.Ext(), nil
792792
}
793793

794794
func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) {

commands/service_upload_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
8181
// 03: error: used both importPath and importFile
8282
{"testdata/upload/build_path_2/Blink.ino.hex", "testdata/upload/build_path_2", nil, nil, "<nil>", ""},
8383
// 04: only sketch without FQBN
84-
{"", "", blonk, nil, blonk.DefaultBuildPath().String(), "Blonk.ino"},
84+
{"", "", blonk, nil, blonk.DefaultBuildPath(nil).String(), "Blonk.ino"},
8585
// 05: use importFile to detect build.path and project_name, sketch is ignored.
8686
{"testdata/upload/build_path_2/Blink.ino.hex", "", blonk, nil, "testdata/upload/build_path_2", "Blink.ino"},
8787
// 06: use importPath as build.path and Blink as project name, ignore the sketch Blonk
@@ -97,7 +97,7 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
9797
// 11: error: used both importPath and importFile
9898
{"testdata/upload/build_path_2/Blink.ino.hex", "testdata/upload/build_path_2", nil, fqbn, "<nil>", ""},
9999
// 12: use sketch to determine project name and sketch+fqbn to determine build path
100-
{"", "", blonk, fqbn, blonk.DefaultBuildPath().String(), "Blonk.ino"},
100+
{"", "", blonk, fqbn, blonk.DefaultBuildPath(nil).String(), "Blonk.ino"},
101101
// 13: use importFile to detect build.path and project_name, sketch+fqbn is ignored.
102102
{"testdata/upload/build_path_2/Blink.ino.hex", "", blonk, fqbn, "testdata/upload/build_path_2", "Blink.ino"},
103103
// 14: use importPath as build.path and Blink as project name, ignore the sketch Blonk, ignore fqbn

internal/arduino/sketch/sketch.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,13 @@ func (e *InvalidSketchFolderNameError) Error() string {
280280
}
281281

282282
// DefaultBuildPath generates the default build directory for a given sketch.
283-
// The build path is in a temporary directory and is unique for each sketch.
284-
func (s *Sketch) DefaultBuildPath() *paths.Path {
285-
return paths.TempDir().Join("arduino", "sketches", s.Hash())
283+
// The sketch build path is inside the build cache path and is unique for each sketch.
284+
// If buildCachePath is nil the default build cache path is used.
285+
func (s *Sketch) DefaultBuildPath(buildCachePath *paths.Path) *paths.Path {
286+
if buildCachePath == nil {
287+
return paths.TempDir().Join("arduino", "sketches", s.Hash())
288+
}
289+
return buildCachePath.Join("sketches", s.Hash())
286290
}
287291

288292
// Hash generate a unique hash for the given sketch.

internal/arduino/sketch/sketch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func TestNewSketchFolderSymlink(t *testing.T) {
287287

288288
func TestGenBuildPath(t *testing.T) {
289289
want := paths.TempDir().Join("arduino", "sketches", "ACBD18DB4CC2F85CEDEF654FCCC4A4D8")
290-
assert.True(t, (&Sketch{FullPath: paths.New("foo")}).DefaultBuildPath().EquivalentTo(want))
290+
assert.True(t, (&Sketch{FullPath: paths.New("foo")}).DefaultBuildPath(nil).EquivalentTo(want))
291291
assert.Equal(t, "ACBD18DB4CC2F85CEDEF654FCCC4A4D8", (&Sketch{FullPath: paths.New("foo")}).Hash())
292292
}
293293

0 commit comments

Comments
 (0)