@@ -18,30 +18,30 @@ import (
18
18
"github.com/arduino/arduino-cli/rpc"
19
19
paths "github.com/arduino/go-paths-helper"
20
20
properties "github.com/arduino/go-properties-orderedmap"
21
- flags "github.com/jessevdk/go-flags"
22
21
"github.com/sirupsen/logrus"
23
22
)
24
23
25
24
func Compile (ctx context.Context , req * rpc.CompileReq ) (* rpc.CompileResp , error ) {
26
25
logrus .Info ("Executing `arduino compile`" )
27
26
var sketchPath * paths.Path
28
- if len ( args ) > 0 {
29
- sketchPath = paths .New (args [ 0 ] )
27
+ if req . GetSketchPath () != "" {
28
+ sketchPath = paths .New (req . GetSketchPath () )
30
29
}
31
30
sketch , err := cli .InitSketch (sketchPath )
32
31
if err != nil {
33
32
formatter .PrintError (err , "Error opening sketch." )
34
33
os .Exit (cli .ErrGeneric )
35
34
}
36
35
37
- if flags .fqbn == "" && sketch != nil && sketch .Metadata != nil {
38
- flags .fqbn = sketch .Metadata .CPU .Fqbn
36
+ fqbnIn := req .GetFqbn ()
37
+ if fqbnIn == "" && sketch != nil && sketch .Metadata != nil {
38
+ fqbnIn = sketch .Metadata .CPU .Fqbn
39
39
}
40
- if flags . fqbn == "" {
40
+ if fqbnIn == "" {
41
41
formatter .PrintErrorMessage ("No Fully Qualified Board Name provided." )
42
42
os .Exit (cli .ErrGeneric )
43
43
}
44
- fqbn , err := cores .ParseFQBN (flags . fqbn )
44
+ fqbn , err := cores .ParseFQBN (fqbnIn )
45
45
if err != nil {
46
46
formatter .PrintErrorMessage ("Fully Qualified Board Name has incorrect format." )
47
47
os .Exit (cli .ErrBadArgument )
@@ -80,64 +80,64 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
80
80
os .Exit (cli .ErrCoreConfig )
81
81
}
82
82
83
- ctx := & types.Context {}
84
- ctx .PackageManager = pm
85
- ctx .FQBN = fqbn
86
- ctx .SketchLocation = sketch .FullPath
83
+ builderCtx := & types.Context {}
84
+ builderCtx .PackageManager = pm
85
+ builderCtx .FQBN = fqbn
86
+ builderCtx .SketchLocation = sketch .FullPath
87
87
88
88
// FIXME: This will be redundant when arduino-builder will be part of the cli
89
89
if packagesDir , err := cli .Config .HardwareDirectories (); err == nil {
90
- ctx .HardwareDirs = packagesDir
90
+ builderCtx .HardwareDirs = packagesDir
91
91
} else {
92
92
formatter .PrintError (err , "Cannot get hardware directories." )
93
93
os .Exit (cli .ErrCoreConfig )
94
94
}
95
95
96
96
if toolsDir , err := cli .Config .BundleToolsDirectories (); err == nil {
97
- ctx .ToolsDirs = toolsDir
97
+ builderCtx .ToolsDirs = toolsDir
98
98
} else {
99
99
formatter .PrintError (err , "Cannot get bundled tools directories." )
100
100
os .Exit (cli .ErrCoreConfig )
101
101
}
102
102
103
- ctx .OtherLibrariesDirs = paths .NewPathList ()
104
- ctx .OtherLibrariesDirs .Add (cli .Config .LibrariesDir ())
103
+ builderCtx .OtherLibrariesDirs = paths .NewPathList ()
104
+ builderCtx .OtherLibrariesDirs .Add (cli .Config .LibrariesDir ())
105
105
106
- if flags . buildPath != "" {
107
- ctx .BuildPath = paths .New (flags . buildPath )
108
- err = ctx .BuildPath .MkdirAll ()
106
+ if req . GetBuildPath () != "" {
107
+ builderCtx .BuildPath = paths .New (req . GetBuildPath () )
108
+ err = builderCtx .BuildPath .MkdirAll ()
109
109
if err != nil {
110
110
formatter .PrintError (err , "Cannot create the build directory." )
111
111
os .Exit (cli .ErrBadCall )
112
112
}
113
113
}
114
114
115
- ctx .Verbose = flags . verbose
115
+ builderCtx .Verbose = req . GetVerbose ()
116
116
117
- ctx .CoreBuildCachePath = paths .TempDir ().Join ("arduino-core-cache" )
117
+ builderCtx .CoreBuildCachePath = paths .TempDir ().Join ("arduino-core-cache" )
118
118
119
- ctx .USBVidPid = flags . vidPid
120
- ctx .WarningsLevel = flags . warnings
119
+ builderCtx .USBVidPid = req . GetVidPid ()
120
+ builderCtx .WarningsLevel = req . GetWarnings ()
121
121
122
122
if cli .GlobalFlags .Debug {
123
- ctx .DebugLevel = 100
123
+ builderCtx .DebugLevel = 100
124
124
} else {
125
- ctx .DebugLevel = 5
125
+ builderCtx .DebugLevel = 5
126
126
}
127
127
128
- ctx .CustomBuildProperties = append (flags . buildProperties , "build.warn_data_percentage=75" )
128
+ builderCtx .CustomBuildProperties = append (req . GetBuildProperties () , "build.warn_data_percentage=75" )
129
129
130
- if flags . buildCachePath != "" {
131
- ctx .BuildCachePath = paths .New (flags . buildCachePath )
132
- err = ctx .BuildCachePath .MkdirAll ()
130
+ if req . GetBuildCachePath () != "" {
131
+ builderCtx .BuildCachePath = paths .New (req . GetBuildCachePath () )
132
+ err = builderCtx .BuildCachePath .MkdirAll ()
133
133
if err != nil {
134
134
formatter .PrintError (err , "Cannot create the build cache directory." )
135
135
os .Exit (cli .ErrBadCall )
136
136
}
137
137
}
138
138
139
139
// Will be deprecated.
140
- ctx .ArduinoAPIVersion = "10607"
140
+ builderCtx .ArduinoAPIVersion = "10607"
141
141
142
142
// Check if Arduino IDE is installed and get it's libraries location.
143
143
preferencesTxt := cli .Config .DataDir .Join ("preferences.txt" )
@@ -154,15 +154,15 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
154
154
sort .Strings (pathVariants )
155
155
ideHardwarePath := lastIdeSubProperties .Get (pathVariants [len (pathVariants )- 1 ])
156
156
ideLibrariesPath := filepath .Join (filepath .Dir (ideHardwarePath ), "libraries" )
157
- ctx .BuiltInLibrariesDirs = paths .NewPathList (ideLibrariesPath )
157
+ builderCtx .BuiltInLibrariesDirs = paths .NewPathList (ideLibrariesPath )
158
158
}
159
159
160
- if flags . showProperties {
161
- err = builder .RunParseHardwareAndDumpBuildProperties (ctx )
162
- } else if flags . preprocess {
163
- err = builder .RunPreprocess (ctx )
160
+ if req . GetShowProperties () {
161
+ err = builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
162
+ } else if req . GetPreprocess () {
163
+ err = builder .RunPreprocess (builderCtx )
164
164
} else {
165
- err = builder .RunBuilder (ctx )
165
+ err = builder .RunBuilder (builderCtx )
166
166
}
167
167
168
168
if err != nil {
@@ -171,7 +171,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
171
171
}
172
172
173
173
// FIXME: Make a function to obtain these info...
174
- outputPath := ctx .BuildProperties .ExpandPropsInString ("{build.path}/{recipe.output.tmp_file}" )
174
+ outputPath := builderCtx .BuildProperties .ExpandPropsInString ("{build.path}/{recipe.output.tmp_file}" )
175
175
ext := filepath .Ext (outputPath )
176
176
177
177
// FIXME: Make a function to produce a better name...
@@ -181,12 +181,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
181
181
182
182
var exportPath * paths.Path
183
183
var exportFile string
184
- if flags . exportFile == "" {
184
+ if req . GetExportFile () == "" {
185
185
exportPath = sketch .FullPath
186
186
exportFile = sketch .Name + "." + fqbnSuffix
187
187
} else {
188
- exportPath = paths .New (flags . exportFile ).Parent ()
189
- exportFile = paths .New (flags . exportFile ).Base ()
188
+ exportPath = paths .New (req . GetExportFile () ).Parent ()
189
+ exportFile = paths .New (req . GetExportFile () ).Base ()
190
190
if strings .HasSuffix (exportFile , ext ) {
191
191
exportFile = exportFile [:len (exportFile )- len (ext )]
192
192
}
0 commit comments