-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathcontext.go
159 lines (136 loc) · 4.93 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package types
import (
"strings"
"github.com/arduino/arduino-builder/i18n"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-map"
"github.com/bcmi-labs/arduino-cli/arduino/cores"
"github.com/bcmi-labs/arduino-cli/arduino/cores/packagemanager"
"github.com/bcmi-labs/arduino-cli/arduino/libraries"
)
type ProgressStruct struct {
PrintEnabled bool
Steps float64
Progress float64
}
// Context structure
type Context struct {
// Build options
HardwareFolders paths.PathList
ToolsFolders paths.PathList
BuiltInToolsFolders paths.PathList
LibrariesFolders paths.PathList
BuiltInLibrariesFolders paths.PathList
OtherLibrariesFolders paths.PathList
SketchLocation *paths.Path
WatchedLocations paths.PathList
ArduinoAPIVersion string
FQBN string
CodeCompleteAt string
// Build options are serialized here
BuildOptionsJson string
BuildOptionsJsonPrevious string
PackageManager *packagemanager.PackageManager
Hardware *cores.Packages
AllTools []*cores.ToolRelease
RequiredTools []*cores.ToolRelease
TargetBoard *cores.Board
TargetPackage *cores.Package
TargetPlatform *cores.PlatformRelease
ActualPlatform *cores.PlatformRelease
USBVidPid string
PlatformKeyRewrites PlatforKeysRewrite
HardwareRewriteResults map[*cores.PlatformRelease][]PlatforKeyRewrite
BuildProperties properties.Map
BuildCore string
BuildPath *paths.Path
BuildCachePath *paths.Path
SketchBuildPath *paths.Path
CoreBuildPath *paths.Path
CoreBuildCachePath *paths.Path
CoreArchiveFilePath *paths.Path
CoreObjectsFiles paths.PathList
LibrariesBuildPath *paths.Path
LibrariesObjectFiles paths.PathList
PreprocPath *paths.Path
SketchObjectFiles paths.PathList
CollectedSourceFiles *UniqueSourceFileQueue
Sketch *Sketch
Source string
SourceGccMinusE string
CodeCompletions string
WarningsLevel string
// Libraries handling
Libraries []*libraries.Library
HeaderToLibraries map[string][]*libraries.Library
ImportedLibraries []*libraries.Library
LibrariesResolutionResults map[string]LibraryResolutionResult
IncludeFolders paths.PathList
//OutputGccMinusM string
// C++ Parsing
CTagsOutput string
CTagsTargetFile *paths.Path
CTagsOfPreprocessedSource []*CTag
IncludeSection string
LineOffset int
PrototypesSection string
PrototypesLineWhereToInsert int
Prototypes []*Prototype
// Verbosity settings
Verbose bool
DebugPreprocessor bool
// Dry run, only create progress map
Progress ProgressStruct
// Contents of a custom build properties file (line by line)
CustomBuildProperties []string
// Logging
logger i18n.Logger
DebugLevel int
// Reuse old tools since the backing storage didn't change
CanUseCachedTools bool
// Experimental: use arduino-preprocessor to create prototypes
UseArduinoPreprocessor bool
}
func (ctx *Context) ExtractBuildOptions() properties.Map {
opts := make(properties.Map)
opts["hardwareFolders"] = strings.Join(ctx.HardwareFolders.AsStrings(), ",")
opts["toolsFolders"] = strings.Join(ctx.ToolsFolders.AsStrings(), ",")
opts["builtInLibrariesFolders"] = strings.Join(ctx.BuiltInLibrariesFolders.AsStrings(), ",")
opts["otherLibrariesFolders"] = strings.Join(ctx.OtherLibrariesFolders.AsStrings(), ",")
opts["sketchLocation"] = ctx.SketchLocation.String()
var additionalFilesRelative []string
if ctx.Sketch != nil {
for _, sketch := range ctx.Sketch.AdditionalFiles {
absPath := ctx.SketchLocation.Parent()
relPath, err := sketch.Name.RelTo(absPath)
if err != nil {
continue // ignore
}
additionalFilesRelative = append(additionalFilesRelative, relPath.String())
}
}
opts["fqbn"] = ctx.FQBN
opts["runtime.ide.version"] = ctx.ArduinoAPIVersion
opts["customBuildProperties"] = strings.Join(ctx.CustomBuildProperties, ",")
opts["additionalFiles"] = strings.Join(additionalFilesRelative, ",")
return opts
}
func (ctx *Context) InjectBuildOptions(opts properties.Map) {
ctx.HardwareFolders = paths.NewPathList(strings.Split(opts["hardwareFolders"], ",")...)
ctx.ToolsFolders = paths.NewPathList(strings.Split(opts["toolsFolders"], ",")...)
ctx.BuiltInLibrariesFolders = paths.NewPathList(strings.Split(opts["builtInLibrariesFolders"], ",")...)
ctx.OtherLibrariesFolders = paths.NewPathList(strings.Split(opts["otherLibrariesFolders"], ",")...)
ctx.SketchLocation = paths.New(opts["sketchLocation"])
ctx.FQBN = opts["fqbn"]
ctx.ArduinoAPIVersion = opts["runtime.ide.version"]
ctx.CustomBuildProperties = strings.Split(opts["customBuildProperties"], ",")
}
func (ctx *Context) GetLogger() i18n.Logger {
if ctx.logger == nil {
return &i18n.HumanLogger{}
}
return ctx.logger
}
func (ctx *Context) SetLogger(l i18n.Logger) {
ctx.logger = l
}