Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78bfa74

Browse filesBrowse files
[skip-changelog] Handle repeated builds of a sketch when --build-path target is in the sketch directory (#2084)
* Handle repeated builds of a sketch when the build path is inside the sketch directory * Add TestCompileBuildPathInsideSketch to compile_test.go
1 parent e7ba99f commit 78bfa74
Copy full SHA for 78bfa74

File tree

Expand file treeCollapse file tree

2 files changed

+52
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+52
-0
lines changed

‎commands/compile/compile.go

Copy file name to clipboardExpand all lines: commands/compile/compile.go
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
133133
builderCtx.BuildPath = sk.DefaultBuildPath()
134134
} else {
135135
builderCtx.BuildPath = paths.New(req.GetBuildPath()).Canonical()
136+
if in, err := builderCtx.BuildPath.IsInsideDir(sk.FullPath); err != nil {
137+
return nil, &arduino.NotFoundError{Message: tr("Cannot find build path"), Cause: err}
138+
} else if in && builderCtx.BuildPath.IsDir() {
139+
if sk.AdditionalFiles, err = removeBuildFromSketchFiles(sk.AdditionalFiles, builderCtx.BuildPath); err != nil {
140+
return nil, err
141+
}
142+
}
136143
}
137144
if err = builderCtx.BuildPath.MkdirAll(); err != nil {
138145
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build directory"), Cause: err}
@@ -315,3 +322,24 @@ func maybePurgeBuildCache() {
315322
buildcache.New(paths.TempDir().Join("arduino", "cores")).Purge(cacheTTL)
316323
buildcache.New(paths.TempDir().Join("arduino", "sketches")).Purge(cacheTTL)
317324
}
325+
326+
// removeBuildFromSketchFiles removes the files contained in the build directory from
327+
// the list of the sketch files
328+
func removeBuildFromSketchFiles(files paths.PathList, build *paths.Path) (paths.PathList, error) {
329+
var res paths.PathList
330+
ignored := false
331+
for _, file := range files {
332+
if in, err := file.IsInsideDir(build); err != nil {
333+
return nil, &arduino.NotFoundError{Message: tr("Cannot find build path"), Cause: err}
334+
} else if !in {
335+
res = append(res, file)
336+
} else if !ignored {
337+
ignored = true
338+
}
339+
}
340+
// log only if at least a file is ignored
341+
if ignored {
342+
logrus.Tracef("Build path %s is a child of sketch path and it is ignored for additional files.", build.String())
343+
}
344+
return res, nil
345+
}

‎internal/integrationtest/compile_3/compile_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/compile_3/compile_test.go
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,27 @@ func TestRuntimeToolPropertiesGeneration(t *testing.T) {
7272
require.True(t, res.GetPath("runtime.tools.avrdude.path").EquivalentTo(hardwareDir.Join("arduino", "tools", "avrdude", "6.3.0-arduino17")))
7373
}
7474
}
75+
76+
func TestCompileBuildPathInsideSketch(t *testing.T) {
77+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
78+
defer env.CleanUp()
79+
80+
_, _, err := cli.Run("core", "update-index")
81+
require.NoError(t, err)
82+
83+
_, _, err = cli.Run("core", "install", "arduino:avr")
84+
require.NoError(t, err)
85+
86+
sketch := "sketchSimple"
87+
_, _, err = cli.Run("sketch", "new", sketch)
88+
require.NoError(t, err)
89+
90+
cli.SetWorkingDir(cli.WorkingDir().Join(sketch))
91+
// Compile the sketch creating the build directory inside the sketch directory
92+
_, _, err = cli.Run("compile", "-b", "arduino:avr:mega", "--build-path", "build-mega")
93+
require.NoError(t, err)
94+
95+
// Compile again using the same build path
96+
_, _, err = cli.Run("compile", "-b", "arduino:avr:mega", "--build-path", "build-mega")
97+
require.NoError(t, err)
98+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.