@@ -194,16 +194,23 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
194
194
195
195
builderCtx .SourceOverride = req .GetSourceOverride ()
196
196
197
+ r = & rpc.CompileResp {}
198
+ defer func () {
199
+ if p := builderCtx .BuildPath ; p != nil {
200
+ r .BuildPath = p .String ()
201
+ }
202
+ }()
203
+
197
204
// if --preprocess or --show-properties were passed, we can stop here
198
205
if req .GetShowProperties () {
199
- return & rpc. CompileResp {} , builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
206
+ return r , builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
200
207
} else if req .GetPreprocess () {
201
- return & rpc. CompileResp {} , builder .RunPreprocess (builderCtx )
208
+ return r , builder .RunPreprocess (builderCtx )
202
209
}
203
210
204
211
// if it's a regular build, go on...
205
212
if err := builder .RunBuilder (builderCtx ); err != nil {
206
- return & rpc. CompileResp {} , err
213
+ return r , err
207
214
}
208
215
209
216
// If the export directory is set we assume you want to export the binaries
@@ -219,17 +226,17 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
219
226
}
220
227
logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
221
228
if err := exportPath .MkdirAll (); err != nil {
222
- return nil , errors .Wrap (err , "creating output dir" )
229
+ return r , errors .Wrap (err , "creating output dir" )
223
230
}
224
231
225
232
// Copy all "sketch.ino.*" artifacts to the export directory
226
233
baseName , ok := builderCtx .BuildProperties .GetOk ("build.project_name" ) // == "sketch.ino"
227
234
if ! ok {
228
- return nil , errors .New ("missing 'build.project_name' build property" )
235
+ return r , errors .New ("missing 'build.project_name' build property" )
229
236
}
230
237
buildFiles , err := builderCtx .BuildPath .ReadDir ()
231
238
if err != nil {
232
- return nil , errors .Errorf ("reading build directory: %s" , err )
239
+ return r , errors .Errorf ("reading build directory: %s" , err )
233
240
}
234
241
buildFiles .FilterPrefix (baseName )
235
242
for _ , buildFile := range buildFiles {
@@ -239,7 +246,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
239
246
WithField ("dest" , exportedFile ).
240
247
Trace ("Copying artifact." )
241
248
if err = buildFile .CopyTo (exportedFile ); err != nil {
242
- return nil , errors .Wrapf (err , "copying output file %s" , buildFile )
249
+ return r , errors .Wrapf (err , "copying output file %s" , buildFile )
243
250
}
244
251
}
245
252
}
@@ -248,15 +255,14 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
248
255
for _ , lib := range builderCtx .ImportedLibraries {
249
256
rpcLib , err := lib .ToRPCLibrary ()
250
257
if err != nil {
251
- return nil , fmt .Errorf ("converting library %s to rpc struct: %w" , lib .Name , err )
258
+ return r , fmt .Errorf ("converting library %s to rpc struct: %w" , lib .Name , err )
252
259
}
253
260
importedLibs = append (importedLibs , rpcLib )
254
261
}
255
262
256
263
logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
257
264
258
265
return & rpc.CompileResp {
259
- BuildPath : builderCtx .BuildPath .String (),
260
266
UsedLibraries : importedLibs ,
261
267
ExecutableSectionsSize : builderCtx .ExecutableSectionsSize .ToRPCExecutableSectionSizeArray (),
262
268
}, nil
0 commit comments