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