Skip to content

Commit e548e10

Browse files
committed
makeSourceFile is now a method of SketchLibrariesDetector
1 parent e96033f commit e548e10

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

internal/arduino/builder/internal/detector/detector.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (l *SketchLibrariesDetector) findIncludes(
290290

291291
if !l.useCachedLibrariesResolution {
292292
sketch := sketch
293-
mergedfile, err := makeSourceFile(sketchBuildPath, sketchBuildPath, paths.New(sketch.MainFile.Base()+".cpp.merged"))
293+
mergedfile, err := l.makeSourceFile(sketchBuildPath, sketchBuildPath, paths.New(sketch.MainFile.Base()+".cpp.merged"))
294294
if err != nil {
295295
return err
296296
}
@@ -503,7 +503,7 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
503503
}
504504

505505
for _, filePath := range filePaths {
506-
sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...)
506+
sourceFile, err := l.makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...)
507507
if err != nil {
508508
return err
509509
}
@@ -513,6 +513,33 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
513513
return nil
514514
}
515515

516+
// makeSourceFile create a sourceFile object for the given source file path.
517+
// The given sourceFilePath can be absolute, or relative within the sourceRoot root folder.
518+
func (l *SketchLibrariesDetector) makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePaths ...*paths.Path) (*sourceFile, error) {
519+
if len(extraIncludePaths) > 1 {
520+
panic("only one extra include path allowed")
521+
}
522+
var extraIncludePath *paths.Path
523+
if len(extraIncludePaths) > 0 {
524+
extraIncludePath = extraIncludePaths[0]
525+
}
526+
527+
if sourceFilePath.IsAbs() {
528+
var err error
529+
sourceFilePath, err = sourceRoot.RelTo(sourceFilePath)
530+
if err != nil {
531+
return nil, err
532+
}
533+
}
534+
res := &sourceFile{
535+
SourcePath: sourceRoot.JoinPath(sourceFilePath),
536+
ObjectPath: buildRoot.Join(sourceFilePath.String() + ".o"),
537+
DepfilePath: buildRoot.Join(sourceFilePath.String() + ".d"),
538+
ExtraIncludePath: extraIncludePath,
539+
}
540+
return res, nil
541+
}
542+
516543
func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
517544
if len(l.importedLibraries) == 0 {
518545
return nil

internal/arduino/builder/internal/detector/source_file.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,6 @@ func (f *sourceFile) Equals(g *sourceFile) bool {
5454
(f.ExtraIncludePath != nil && g.ExtraIncludePath != nil && f.ExtraIncludePath.EqualsTo(g.ExtraIncludePath)))
5555
}
5656

57-
// makeSourceFile create a sourceFile object for the given source file path.
58-
// The given sourceFilePath can be absolute, or relative within the sourceRoot root folder.
59-
func makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePaths ...*paths.Path) (*sourceFile, error) {
60-
if len(extraIncludePaths) > 1 {
61-
panic("only one extra include path allowed")
62-
}
63-
var extraIncludePath *paths.Path
64-
if len(extraIncludePaths) > 0 {
65-
extraIncludePath = extraIncludePaths[0]
66-
}
67-
68-
if sourceFilePath.IsAbs() {
69-
var err error
70-
sourceFilePath, err = sourceRoot.RelTo(sourceFilePath)
71-
if err != nil {
72-
return nil, err
73-
}
74-
}
75-
res := &sourceFile{
76-
SourcePath: sourceRoot.JoinPath(sourceFilePath),
77-
ObjectPath: buildRoot.Join(sourceFilePath.String() + ".o"),
78-
DepfilePath: buildRoot.Join(sourceFilePath.String() + ".d"),
79-
ExtraIncludePath: extraIncludePath,
80-
}
81-
return res, nil
82-
}
83-
8457
// ObjFileIsUpToDate checks if the compile object file is up to date.
8558
func (f *sourceFile) ObjFileIsUpToDate() (unchanged bool, err error) {
8659
return utils.ObjFileIsUpToDate(f.SourcePath, f.ObjectPath, f.DepfilePath)

0 commit comments

Comments
 (0)