From 434978cdc600525219de44f1d3c573ba90b5c21a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 19 Dec 2023 18:24:52 +0100 Subject: [PATCH] Upgrade go-paths / remove duplicate filter function --- .../arduino/go-paths-helper.dep.yml | 2 +- go.mod | 2 +- go.sum | 2 ++ internal/arduino/builder/linker.go | 19 +++++++------------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.licenses/go/github.com/arduino/go-paths-helper.dep.yml b/.licenses/go/github.com/arduino/go-paths-helper.dep.yml index f06e4ce1625..c821a1e1141 100644 --- a/.licenses/go/github.com/arduino/go-paths-helper.dep.yml +++ b/.licenses/go/github.com/arduino/go-paths-helper.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/arduino/go-paths-helper -version: v1.10.1 +version: v1.11.0 type: go summary: homepage: https://pkg.go.dev/github.com/arduino/go-paths-helper diff --git a/go.mod b/go.mod index 152f24a4ea5..7c485728a0c 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1 require ( github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 - github.com/arduino/go-paths-helper v1.10.1 + github.com/arduino/go-paths-helper v1.11.0 github.com/arduino/go-properties-orderedmap v1.8.0 github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b github.com/arduino/go-win32-utils v1.0.0 diff --git a/go.sum b/go.sum index d0155206e1a..737e90ff2ff 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.10.1 h1:j8InnhLrSeoPiOvTnZL0XMFt7l407ciTBJJJs7W9bs4= github.com/arduino/go-paths-helper v1.10.1/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= +github.com/arduino/go-paths-helper v1.11.0 h1:hkpGb9AtCTByTj2FKutuHWb3klDf4kAKL10hW+fN+oE= +github.com/arduino/go-paths-helper v1.11.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= github.com/arduino/go-properties-orderedmap v1.8.0 h1:wEfa6hHdpezrVOh787OmClsf/Kd8qB+zE3P2Xbrn0CQ= github.com/arduino/go-properties-orderedmap v1.8.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4= diff --git a/internal/arduino/builder/linker.go b/internal/arduino/builder/linker.go index 20580a5e1db..0af2e9b3e53 100644 --- a/internal/arduino/builder/linker.go +++ b/internal/arduino/builder/linker.go @@ -22,16 +22,6 @@ import ( "github.com/arduino/go-paths-helper" ) -func filter(p *paths.PathList, filter func(*paths.Path) bool) paths.PathList { - res := (*p)[:0] - for _, path := range *p { - if filter(path) { - res = append(res, path) - } - } - return res -} - // link fixdoc func (b *Builder) link() error { if b.onlyUpdateCompilationDatabase { @@ -64,14 +54,19 @@ func (b *Builder) link() error { // because thery are both named spi.o. archives := paths.NewPathList() - for _, object := range objectFiles { archive := object.Parent().Join("objs.a") archives.AddIfMissing(archive) } + // Generate archive for each directory for _, archive := range archives { - relatedObjectFiles := filter(&objectFiles, func(object *paths.Path) bool { return object.Parent().EquivalentTo(archive.Parent()) }) + archiveDir := archive.Parent() + relatedObjectFiles := objectFiles.Clone() + relatedObjectFiles.Filter(func(object *paths.Path) bool { + // extract all the object files that are in the same directory of the archive + return object.Parent().EquivalentTo(archiveDir) + }) b.archiveCompiledFiles(archive.Parent(), paths.New(archive.Base()), relatedObjectFiles) }