Skip to content

Commit 3daa69f

Browse files
committed
Moving sourceFile object in his own file
1 parent b4262e0 commit 3daa69f

File tree

2 files changed

+92
-91
lines changed

2 files changed

+92
-91
lines changed

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

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -500,97 +500,6 @@ func findIncludeForOldCompilers(source string) string {
500500
return ""
501501
}
502502

503-
type sourceFile struct {
504-
// Path to the source file within the sketch/library root folder
505-
relativePath *paths.Path
506-
507-
// ExtraIncludePath contains an extra include path that must be
508-
// used to compile this source file.
509-
// This is mainly used for source files that comes from old-style libraries
510-
// (Arduino IDE <1.5) requiring an extra include path to the "utility" folder.
511-
extraIncludePath *paths.Path
512-
513-
// The source root for the given origin, where its source files
514-
// can be found. Prepending this to SourceFile.RelativePath will give
515-
// the full path to that source file.
516-
sourceRoot *paths.Path
517-
518-
// The build root for the given origin, where build products will
519-
// be placed. Any directories inside SourceFile.RelativePath will be
520-
// appended here.
521-
buildRoot *paths.Path
522-
}
523-
524-
// Equals fixdoc
525-
func (f *sourceFile) Equals(g *sourceFile) bool {
526-
return f.relativePath.EqualsTo(g.relativePath) &&
527-
f.buildRoot.EqualsTo(g.buildRoot) &&
528-
f.sourceRoot.EqualsTo(g.sourceRoot)
529-
}
530-
531-
// makeSourceFile containing the given source file path within the
532-
// given origin. The given path can be absolute, or relative within the
533-
// origin's root source folder
534-
func makeSourceFile(
535-
sourceDir *paths.Path,
536-
buildDir *paths.Path,
537-
sourceFilePath *paths.Path,
538-
extraIncludePath ...*paths.Path,
539-
) (*sourceFile, error) {
540-
res := &sourceFile{
541-
buildRoot: buildDir,
542-
sourceRoot: sourceDir,
543-
}
544-
545-
if len(extraIncludePath) > 1 {
546-
panic("only one extra include path allowed")
547-
}
548-
if len(extraIncludePath) > 0 {
549-
res.extraIncludePath = extraIncludePath[0]
550-
}
551-
// switch o := origin.(type) {
552-
// case *sketch.Sketch:
553-
// res.buildRoot = sketchBuildPath
554-
// res.sourceRoot = sketchBuildPath
555-
// case *libraries.Library:
556-
// res.buildRoot = librariesBuildPath.Join(o.DirName)
557-
// res.sourceRoot = o.SourceDir
558-
// res.extraIncludePath = o.UtilityDir
559-
// default:
560-
// panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
561-
// }
562-
563-
if sourceFilePath.IsAbs() {
564-
var err error
565-
sourceFilePath, err = res.sourceRoot.RelTo(sourceFilePath)
566-
if err != nil {
567-
return nil, err
568-
}
569-
}
570-
res.relativePath = sourceFilePath
571-
return res, nil
572-
}
573-
574-
// ExtraIncludePath fixdoc
575-
func (f *sourceFile) ExtraIncludePath() *paths.Path {
576-
return f.extraIncludePath
577-
}
578-
579-
// SourcePath fixdoc
580-
func (f *sourceFile) SourcePath() *paths.Path {
581-
return f.sourceRoot.JoinPath(f.relativePath)
582-
}
583-
584-
// ObjectPath fixdoc
585-
func (f *sourceFile) ObjectPath() *paths.Path {
586-
return f.buildRoot.Join(f.relativePath.String() + ".o")
587-
}
588-
589-
// DepfilePath fixdoc
590-
func (f *sourceFile) DepfilePath() *paths.Path {
591-
return f.buildRoot.Join(f.relativePath.String() + ".d")
592-
}
593-
594503
// LibrariesLoader todo
595504
func LibrariesLoader(
596505
useCachedLibrariesResolution bool,
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package detector
17+
18+
import "github.com/arduino/go-paths-helper"
19+
20+
type sourceFile struct {
21+
// Path to the source file within the sketch/library root folder
22+
relativePath *paths.Path
23+
24+
// ExtraIncludePath contains an extra include path that must be
25+
// used to compile this source file.
26+
// This is mainly used for source files that comes from old-style libraries
27+
// (Arduino IDE <1.5) requiring an extra include path to the "utility" folder.
28+
extraIncludePath *paths.Path
29+
30+
// The source root for the given origin, where its source files
31+
// can be found. Prepending this to SourceFile.RelativePath will give
32+
// the full path to that source file.
33+
sourceRoot *paths.Path
34+
35+
// The build root for the given origin, where build products will
36+
// be placed. Any directories inside SourceFile.RelativePath will be
37+
// appended here.
38+
buildRoot *paths.Path
39+
}
40+
41+
// Equals fixdoc
42+
func (f *sourceFile) Equals(g *sourceFile) bool {
43+
return f.relativePath.EqualsTo(g.relativePath) &&
44+
f.buildRoot.EqualsTo(g.buildRoot) &&
45+
f.sourceRoot.EqualsTo(g.sourceRoot)
46+
}
47+
48+
// makeSourceFile create a sourceFile object for the given source file path.
49+
// The given sourceFilePath can be absolute, or relative within the sourceRoot root folder.
50+
func makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePath ...*paths.Path) (*sourceFile, error) {
51+
res := &sourceFile{
52+
buildRoot: buildRoot,
53+
sourceRoot: sourceRoot,
54+
}
55+
56+
if len(extraIncludePath) > 1 {
57+
panic("only one extra include path allowed")
58+
}
59+
if len(extraIncludePath) > 0 {
60+
res.extraIncludePath = extraIncludePath[0]
61+
}
62+
63+
if sourceFilePath.IsAbs() {
64+
var err error
65+
sourceFilePath, err = res.sourceRoot.RelTo(sourceFilePath)
66+
if err != nil {
67+
return nil, err
68+
}
69+
}
70+
res.relativePath = sourceFilePath
71+
return res, nil
72+
}
73+
74+
// ExtraIncludePath returns the extra include path required to build the source file.
75+
func (f *sourceFile) ExtraIncludePath() *paths.Path {
76+
return f.extraIncludePath
77+
}
78+
79+
// SourcePath return the full path to the source file.
80+
func (f *sourceFile) SourcePath() *paths.Path {
81+
return f.sourceRoot.JoinPath(f.relativePath)
82+
}
83+
84+
// ObjectPath return the full path to the object file.
85+
func (f *sourceFile) ObjectPath() *paths.Path {
86+
return f.buildRoot.Join(f.relativePath.String() + ".o")
87+
}
88+
89+
// DepfilePath return the full path to the dependency file.
90+
func (f *sourceFile) DepfilePath() *paths.Path {
91+
return f.buildRoot.Join(f.relativePath.String() + ".d")
92+
}

0 commit comments

Comments
 (0)