@@ -24,69 +24,70 @@ import (
24
24
)
25
25
26
26
type SourceFile struct {
27
- // Sketch or Library pointer that this source file lives in
28
- Origin interface {}
29
27
// Path to the source file within the sketch/library root folder
30
28
RelativePath * paths.Path
29
+
30
+ // Set to the Library object of origin if this source file comes
31
+ // from a library
32
+ Library * libraries.Library
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
38
+
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
31
43
}
32
44
33
45
func (f * SourceFile ) Equals (g * SourceFile ) bool {
34
- return f .Origin == g .Origin &&
35
- f .RelativePath .EqualsTo (g .RelativePath )
46
+ return f .Library == g .Library &&
47
+ f .RelativePath .EqualsTo (g .RelativePath ) &&
48
+ f .buildRoot .EqualsTo (g .buildRoot ) &&
49
+ f .sourceRoot .EqualsTo (g .sourceRoot )
36
50
}
37
51
38
52
// Create a SourceFile containing the given source file path within the
39
53
// given origin. The given path can be absolute, or relative within the
40
54
// origin's root source folder
41
55
func MakeSourceFile (ctx * Context , origin interface {}, path * paths.Path ) (* SourceFile , error ) {
42
- if path .IsAbs () {
43
- var err error
44
- path , err = sourceRoot (ctx , origin ).RelTo (path )
45
- if err != nil {
46
- return nil , err
47
- }
48
- }
49
- return & SourceFile {Origin : origin , RelativePath : path }, nil
50
- }
56
+ res := & SourceFile {}
51
57
52
- // Return the build root for the given origin, where build products will
53
- // be placed. Any directories inside SourceFile.RelativePath will be
54
- // appended here.
55
- func buildRoot (ctx * Context , origin interface {}) * paths.Path {
56
58
switch o := origin .(type ) {
57
59
case * sketch.Sketch :
58
- return ctx .SketchBuildPath
60
+ res .buildRoot = ctx .SketchBuildPath
61
+ res .sourceRoot = ctx .SketchBuildPath
59
62
case * libraries.Library :
60
- return ctx .LibrariesBuildPath .Join (o .DirName )
63
+ res .buildRoot = ctx .LibrariesBuildPath .Join (o .DirName )
64
+ res .sourceRoot = o .SourceDir
65
+ res .Library = o
61
66
default :
62
67
panic ("Unexpected origin for SourceFile: " + fmt .Sprint (origin ))
63
68
}
64
- }
65
69
66
- // Return the source root for the given origin, where its source files
67
- // can be found. Prepending this to SourceFile.RelativePath will give
68
- // the full path to that source file.
69
- func sourceRoot (ctx * Context , origin interface {}) * paths.Path {
70
- switch o := origin .(type ) {
71
- case * sketch.Sketch :
72
- return ctx .SketchBuildPath
73
- case * libraries.Library :
74
- return o .SourceDir
75
- default :
76
- panic ("Unexpected origin for SourceFile: " + fmt .Sprint (origin ))
70
+ if path .IsAbs () {
71
+ var err error
72
+ path , err = res .sourceRoot .RelTo (path )
73
+ if err != nil {
74
+ return nil , err
75
+ }
77
76
}
77
+ res .RelativePath = path
78
+ return res , nil
78
79
}
79
80
80
- func (f * SourceFile ) SourcePath (ctx * Context ) * paths.Path {
81
- return sourceRoot ( ctx , f . Origin ) .JoinPath (f .RelativePath )
81
+ func (f * SourceFile ) SourcePath () * paths.Path {
82
+ return f . sourceRoot .JoinPath (f .RelativePath )
82
83
}
83
84
84
- func (f * SourceFile ) ObjectPath (ctx * Context ) * paths.Path {
85
- return buildRoot ( ctx , f . Origin ) .Join (f .RelativePath .String () + ".o" )
85
+ func (f * SourceFile ) ObjectPath () * paths.Path {
86
+ return f . buildRoot .Join (f .RelativePath .String () + ".o" )
86
87
}
87
88
88
- func (f * SourceFile ) DepfilePath (ctx * Context ) * paths.Path {
89
- return buildRoot ( ctx , f . Origin ) .Join (f .RelativePath .String () + ".d" )
89
+ func (f * SourceFile ) DepfilePath () * paths.Path {
90
+ return f . buildRoot .Join (f .RelativePath .String () + ".d" )
90
91
}
91
92
92
93
type LibraryResolutionResult struct {
0 commit comments