Skip to content

Commit 00db9e3

Browse files
committed
Moving sourceFile object in his own file
1 parent 31085df commit 00db9e3

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
@@ -499,97 +499,6 @@ func findIncludeForOldCompilers(source string) string {
499499
return ""
500500
}
501501

502-
type sourceFile struct {
503-
// Path to the source file within the sketch/library root folder
504-
relativePath *paths.Path
505-
506-
// ExtraIncludePath contains an extra include path that must be
507-
// used to compile this source file.
508-
// This is mainly used for source files that comes from old-style libraries
509-
// (Arduino IDE <1.5) requiring an extra include path to the "utility" folder.
510-
extraIncludePath *paths.Path
511-
512-
// The source root for the given origin, where its source files
513-
// can be found. Prepending this to SourceFile.RelativePath will give
514-
// the full path to that source file.
515-
sourceRoot *paths.Path
516-
517-
// The build root for the given origin, where build products will
518-
// be placed. Any directories inside SourceFile.RelativePath will be
519-
// appended here.
520-
buildRoot *paths.Path
521-
}
522-
523-
// Equals fixdoc
524-
func (f *sourceFile) Equals(g *sourceFile) bool {
525-
return f.relativePath.EqualsTo(g.relativePath) &&
526-
f.buildRoot.EqualsTo(g.buildRoot) &&
527-
f.sourceRoot.EqualsTo(g.sourceRoot)
528-
}
529-
530-
// makeSourceFile containing the given source file path within the
531-
// given origin. The given path can be absolute, or relative within the
532-
// origin's root source folder
533-
func makeSourceFile(
534-
sourceDir *paths.Path,
535-
buildDir *paths.Path,
536-
sourceFilePath *paths.Path,
537-
extraIncludePath ...*paths.Path,
538-
) (*sourceFile, error) {
539-
res := &sourceFile{
540-
buildRoot: buildDir,
541-
sourceRoot: sourceDir,
542-
}
543-
544-
if len(extraIncludePath) > 1 {
545-
panic("only one extra include path allowed")
546-
}
547-
if len(extraIncludePath) > 0 {
548-
res.extraIncludePath = extraIncludePath[0]
549-
}
550-
// switch o := origin.(type) {
551-
// case *sketch.Sketch:
552-
// res.buildRoot = sketchBuildPath
553-
// res.sourceRoot = sketchBuildPath
554-
// case *libraries.Library:
555-
// res.buildRoot = librariesBuildPath.Join(o.DirName)
556-
// res.sourceRoot = o.SourceDir
557-
// res.extraIncludePath = o.UtilityDir
558-
// default:
559-
// panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
560-
// }
561-
562-
if sourceFilePath.IsAbs() {
563-
var err error
564-
sourceFilePath, err = res.sourceRoot.RelTo(sourceFilePath)
565-
if err != nil {
566-
return nil, err
567-
}
568-
}
569-
res.relativePath = sourceFilePath
570-
return res, nil
571-
}
572-
573-
// ExtraIncludePath fixdoc
574-
func (f *sourceFile) ExtraIncludePath() *paths.Path {
575-
return f.extraIncludePath
576-
}
577-
578-
// SourcePath fixdoc
579-
func (f *sourceFile) SourcePath() *paths.Path {
580-
return f.sourceRoot.JoinPath(f.relativePath)
581-
}
582-
583-
// ObjectPath fixdoc
584-
func (f *sourceFile) ObjectPath() *paths.Path {
585-
return f.buildRoot.Join(f.relativePath.String() + ".o")
586-
}
587-
588-
// DepfilePath fixdoc
589-
func (f *sourceFile) DepfilePath() *paths.Path {
590-
return f.buildRoot.Join(f.relativePath.String() + ".d")
591-
}
592-
593502
// LibrariesLoader todo
594503
func LibrariesLoader(
595504
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)