@@ -194,16 +194,23 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
194194
195195 builderCtx .SourceOverride = req .GetSourceOverride ()
196196
197+ r = & rpc.CompileResp {}
198+ defer func () {
199+ if p := builderCtx .BuildPath ; p != nil {
200+ r .BuildPath = p .String ()
201+ }
202+ }()
203+
197204 // if --preprocess or --show-properties were passed, we can stop here
198205 if req .GetShowProperties () {
199- return & rpc. CompileResp {} , builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
206+ return r , builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
200207 } else if req .GetPreprocess () {
201- return & rpc. CompileResp {} , builder .RunPreprocess (builderCtx )
208+ return r , builder .RunPreprocess (builderCtx )
202209 }
203210
204211 // if it's a regular build, go on...
205212 if err := builder .RunBuilder (builderCtx ); err != nil {
206- return & rpc. CompileResp {} , err
213+ return r , err
207214 }
208215
209216 // 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
219226 }
220227 logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
221228 if err := exportPath .MkdirAll (); err != nil {
222- return nil , errors .Wrap (err , "creating output dir" )
229+ return r , errors .Wrap (err , "creating output dir" )
223230 }
224231
225232 // Copy all "sketch.ino.*" artifacts to the export directory
226233 baseName , ok := builderCtx .BuildProperties .GetOk ("build.project_name" ) // == "sketch.ino"
227234 if ! ok {
228- return nil , errors .New ("missing 'build.project_name' build property" )
235+ return r , errors .New ("missing 'build.project_name' build property" )
229236 }
230237 buildFiles , err := builderCtx .BuildPath .ReadDir ()
231238 if err != nil {
232- return nil , errors .Errorf ("reading build directory: %s" , err )
239+ return r , errors .Errorf ("reading build directory: %s" , err )
233240 }
234241 buildFiles .FilterPrefix (baseName )
235242 for _ , buildFile := range buildFiles {
@@ -239,7 +246,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
239246 WithField ("dest" , exportedFile ).
240247 Trace ("Copying artifact." )
241248 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 )
243250 }
244251 }
245252 }
@@ -248,15 +255,14 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
248255 for _ , lib := range builderCtx .ImportedLibraries {
249256 rpcLib , err := lib .ToRPCLibrary ()
250257 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 )
252259 }
253260 importedLibs = append (importedLibs , rpcLib )
254261 }
255262
256263 logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
257264
258265 return & rpc.CompileResp {
259- BuildPath : builderCtx .BuildPath .String (),
260266 UsedLibraries : importedLibs ,
261267 ExecutableSectionsSize : builderCtx .ExecutableSectionsSize .ToRPCExecutableSectionSizeArray (),
262268 }, nil
0 commit comments