Skip to content

Commit c72f35b

Browse files
committed
Moving sourceFile object in his own file
1 parent d25a7e9 commit c72f35b

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
@@ -502,97 +502,6 @@ func findIncludeForOldCompilers(source string) string {
502502
return ""
503503
}
504504

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