Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42e691e

Browse files
committedDec 14, 2023
Reuse archiveCompiledFiles helper for long commandline shrink
Since archiveCompiledFiles already handles hot cache correctly, this avoids objs.a being rebuilt even if files don't change. Would be ideal if PathList could expose a generic Filter API (to get rid of the "duplicated" filter)
1 parent 7b991e4 commit 42e691e

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed
 

‎internal/arduino/builder/linker.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ import (
2222
"github.com/arduino/go-paths-helper"
2323
)
2424

25+
func filter(p *paths.PathList, filter func(*paths.Path) bool) paths.PathList {
26+
res := (*p)[:0]
27+
for _, path := range *p {
28+
if filter(path) {
29+
res = append(res, path)
30+
}
31+
}
32+
return res
33+
}
34+
2535
// link fixdoc
2636
func (b *Builder) link() error {
2737
if b.onlyUpdateCompilationDatabase {
@@ -53,31 +63,16 @@ func (b *Builder) link() error {
5363
// it may happen that a subdir/spi.o inside the archive may be overwritten by a anotherdir/spi.o
5464
// because thery are both named spi.o.
5565

56-
properties := b.buildProperties.Clone()
5766
archives := paths.NewPathList()
67+
5868
for _, object := range objectFiles {
59-
if object.HasSuffix(".a") {
60-
archives.Add(object)
61-
continue
62-
}
6369
archive := object.Parent().Join("objs.a")
64-
if !archives.Contains(archive) {
65-
archives.Add(archive)
66-
// Cleanup old archives
67-
_ = archive.Remove()
68-
}
69-
properties.Set("archive_file", archive.Base())
70-
properties.SetPath("archive_file_path", archive)
71-
properties.SetPath("object_file", object)
72-
73-
command, err := b.prepareCommandForRecipe(properties, "recipe.ar.pattern", false)
74-
if err != nil {
75-
return err
76-
}
77-
78-
if err := b.execCommand(command); err != nil {
79-
return err
80-
}
70+
archives.AddIfMissing(archive)
71+
}
72+
73+
for _, archive := range archives {
74+
relatedObjectFiles := filter(&objectFiles, func(object *paths.Path) bool { return object.Parent().EquivalentTo(archive.Parent()) })
75+
b.archiveCompiledFiles(archive.Parent(), paths.New(archive.Base()), relatedObjectFiles)
8176
}
8277

8378
objectFileList = strings.Join(f.Map(archives.AsStrings(), wrapWithDoubleQuotes), " ")

0 commit comments

Comments
 (0)
Please sign in to comment.