Skip to content

Commit b126a73

Browse files
committed
Pre-compute sourceFile fields, and save the in the includes.cache
1 parent e779f4d commit b126a73

File tree

3 files changed

+42
-57
lines changed

3 files changed

+42
-57
lines changed

Diff for: internal/arduino/builder/internal/detector/cache.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ type detectorCache struct {
2828
}
2929

3030
type detectorCacheEntry struct {
31-
AddedIncludePath *paths.Path `json:"added_include_path,omitempty"`
32-
CompilingSourcePath *paths.Path `json:"compiling_source_path,omitempty"`
33-
MissingIncludeH *string `json:"missing_include_h,omitempty"`
31+
AddedIncludePath *paths.Path `json:"added_include_path,omitempty"`
32+
Compile *sourceFile `json:"compile,omitempty"`
33+
MissingIncludeH *string `json:"missing_include_h,omitempty"`
3434
}
3535

3636
func (e *detectorCacheEntry) String() string {
3737
if e.AddedIncludePath != nil {
3838
return "Added include path: " + e.AddedIncludePath.String()
3939
}
40-
if e.CompilingSourcePath != nil {
41-
return "Compiling source path: " + e.CompilingSourcePath.String()
40+
if e.Compile != nil {
41+
return "Compiling: " + e.Compile.String()
4242
}
4343
if e.MissingIncludeH != nil {
4444
if *e.MissingIncludeH == "" {

Diff for: internal/arduino/builder/internal/detector/detector.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
292292
platformArch string,
293293
) error {
294294
sourceFile := sourceFileQueue.Pop()
295-
sourcePath := sourceFile.SourcePath()
296-
depPath := sourceFile.DepfilePath()
297-
objPath := sourceFile.ObjectPath()
295+
sourcePath := sourceFile.SourcePath
296+
depPath := sourceFile.DepfilePath
297+
objPath := sourceFile.ObjectPath
298298

299299
// TODO: This should perhaps also compare against the
300300
// include.cache file timestamp. Now, it only checks if the file
@@ -315,14 +315,14 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
315315

316316
first := true
317317
for {
318-
l.cache.Expect(&detectorCacheEntry{CompilingSourcePath: sourcePath})
318+
l.cache.Expect(&detectorCacheEntry{Compile: sourceFile})
319319

320320
// Libraries may require the "utility" directory to be added to the include
321321
// search path, but only for the source code of the library, so we temporary
322322
// copy the current search path list and add the library' utility directory
323323
// if needed.
324324
includeFolders := l.includeFolders
325-
if extraInclude := sourceFile.ExtraIncludePath(); extraInclude != nil {
325+
if extraInclude := sourceFile.ExtraIncludePath; extraInclude != nil {
326326
includeFolders = append(includeFolders, extraInclude)
327327
}
328328

Diff for: internal/arduino/builder/internal/detector/source_file.go

+32-47
Original file line numberDiff line numberDiff line change
@@ -16,85 +16,70 @@
1616
package detector
1717

1818
import (
19+
"fmt"
1920
"slices"
2021

2122
"github.com/arduino/go-paths-helper"
2223
)
2324

2425
type sourceFile struct {
25-
// Path to the source file within the sketch/library root folder
26-
relativePath *paths.Path
26+
// SourcePath is the path to the source file
27+
SourcePath *paths.Path `json:"source_path"`
28+
29+
// ObjectPath is the path to the object file that will be generated
30+
ObjectPath *paths.Path `json:"object_path"`
31+
32+
// DepfilePath is the path to the dependency file that will be generated
33+
DepfilePath *paths.Path `json:"depfile_path"`
2734

2835
// ExtraIncludePath contains an extra include path that must be
2936
// used to compile this source file.
3037
// This is mainly used for source files that comes from old-style libraries
3138
// (Arduino IDE <1.5) requiring an extra include path to the "utility" folder.
32-
extraIncludePath *paths.Path
33-
34-
// The source root for the given origin, where its source files
35-
// can be found. Prepending this to SourceFile.RelativePath will give
36-
// the full path to that source file.
37-
sourceRoot *paths.Path
39+
ExtraIncludePath *paths.Path `json:"extra_include_path,omitempty"`
40+
}
3841

39-
// The build root for the given origin, where build products will
40-
// be placed. Any directories inside SourceFile.RelativePath will be
41-
// appended here.
42-
buildRoot *paths.Path
42+
func (f *sourceFile) String() string {
43+
return fmt.Sprintf("SourcePath:%s SourceRoot:%s BuildRoot:%s ExtraInclude:%s",
44+
f.SourcePath, f.ObjectPath, f.DepfilePath, f.ExtraIncludePath)
4345
}
4446

45-
// Equals fixdoc
47+
// Equals checks if a sourceFile is equal to another.
4648
func (f *sourceFile) Equals(g *sourceFile) bool {
47-
return f.relativePath.EqualsTo(g.relativePath) &&
48-
f.buildRoot.EqualsTo(g.buildRoot) &&
49-
f.sourceRoot.EqualsTo(g.sourceRoot)
49+
return f.SourcePath.EqualsTo(g.SourcePath) &&
50+
f.ObjectPath.EqualsTo(g.ObjectPath) &&
51+
f.DepfilePath.EqualsTo(g.DepfilePath) &&
52+
((f.ExtraIncludePath == nil && g.ExtraIncludePath == nil) ||
53+
(f.ExtraIncludePath != nil && g.ExtraIncludePath != nil && f.ExtraIncludePath.EqualsTo(g.ExtraIncludePath)))
5054
}
5155

5256
// makeSourceFile create a sourceFile object for the given source file path.
5357
// The given sourceFilePath can be absolute, or relative within the sourceRoot root folder.
54-
func makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePath ...*paths.Path) (*sourceFile, error) {
55-
res := &sourceFile{
56-
buildRoot: buildRoot,
57-
sourceRoot: sourceRoot,
58-
}
59-
60-
if len(extraIncludePath) > 1 {
58+
func makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePaths ...*paths.Path) (*sourceFile, error) {
59+
if len(extraIncludePaths) > 1 {
6160
panic("only one extra include path allowed")
6261
}
63-
if len(extraIncludePath) > 0 {
64-
res.extraIncludePath = extraIncludePath[0]
62+
var extraIncludePath *paths.Path
63+
if len(extraIncludePaths) > 0 {
64+
extraIncludePath = extraIncludePaths[0]
6565
}
6666

6767
if sourceFilePath.IsAbs() {
6868
var err error
69-
sourceFilePath, err = res.sourceRoot.RelTo(sourceFilePath)
69+
sourceFilePath, err = sourceRoot.RelTo(sourceFilePath)
7070
if err != nil {
7171
return nil, err
7272
}
7373
}
74-
res.relativePath = sourceFilePath
74+
res := &sourceFile{
75+
SourcePath: sourceRoot.JoinPath(sourceFilePath),
76+
ObjectPath: buildRoot.Join(sourceFilePath.String() + ".o"),
77+
DepfilePath: buildRoot.Join(sourceFilePath.String() + ".d"),
78+
ExtraIncludePath: extraIncludePath,
79+
}
7580
return res, nil
7681
}
7782

78-
// ExtraIncludePath returns the extra include path required to build the source file.
79-
func (f *sourceFile) ExtraIncludePath() *paths.Path {
80-
return f.extraIncludePath
81-
}
82-
83-
// SourcePath return the full path to the source file.
84-
func (f *sourceFile) SourcePath() *paths.Path {
85-
return f.sourceRoot.JoinPath(f.relativePath)
86-
}
87-
88-
// ObjectPath return the full path to the object file.
89-
func (f *sourceFile) ObjectPath() *paths.Path {
90-
return f.buildRoot.Join(f.relativePath.String() + ".o")
91-
}
92-
93-
// DepfilePath return the full path to the dependency file.
94-
func (f *sourceFile) DepfilePath() *paths.Path {
95-
return f.buildRoot.Join(f.relativePath.String() + ".d")
96-
}
97-
9883
// uniqueSourceFileQueue is a queue of source files that does not allow duplicates.
9984
type uniqueSourceFileQueue []*sourceFile
10085

0 commit comments

Comments
 (0)