@@ -305,37 +305,35 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
305305 return r , err
306306 }
307307
308- var exportPath * paths.Path
309- if exportDir := req .GetExportDir (); exportDir != "" {
310- exportPath = paths .New (exportDir )
311- } else {
308+ exportPath := paths .New (req .GetExportDir ())
309+ if exportPath == nil {
312310 // Add FQBN (without configs part) to export path
313311 fqbnSuffix := strings .ReplaceAll (fqbn .StringWithoutConfig (), ":" , "." )
314312 exportPath = sk .FullPath .Join ("build" , fqbnSuffix )
315313 }
316- logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
317- if err := exportPath .MkdirAll (); err != nil {
318- return r , & arduino.PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
319- }
320314
321315 // Copy all "sketch.ino.*" artifacts to the export directory
322- baseName , ok := sketchBuilder .GetBuildProperties ().GetOk ("build.project_name" ) // == "sketch.ino"
323- if ! ok {
324- return r , & arduino.MissingPlatformPropertyError {Property : "build.project_name" }
325- }
326- buildFiles , err := sketchBuilder .GetBuildPath ().ReadDir ()
327- if err != nil {
328- return r , & arduino.PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
329- }
330- buildFiles .FilterPrefix (baseName )
331- for _ , buildFile := range buildFiles {
332- exportedFile := exportPath .Join (buildFile .Base ())
333- logrus .
334- WithField ("src" , buildFile ).
335- WithField ("dest" , exportedFile ).
336- Trace ("Copying artifact." )
337- if err = buildFile .CopyTo (exportedFile ); err != nil {
338- return r , & arduino.PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
316+ if ! buildPath .EqualsTo (exportPath ) {
317+ logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
318+ if err := exportPath .MkdirAll (); err != nil {
319+ return r , & arduino.PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
320+ }
321+
322+ baseName , ok := sketchBuilder .GetBuildProperties ().GetOk ("build.project_name" ) // == "sketch.ino"
323+ if ! ok {
324+ return r , & arduino.MissingPlatformPropertyError {Property : "build.project_name" }
325+ }
326+ buildFiles , err := sketchBuilder .GetBuildPath ().ReadDir ()
327+ if err != nil {
328+ return r , & arduino.PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
329+ }
330+ buildFiles .FilterPrefix (baseName )
331+ for _ , buildFile := range buildFiles {
332+ exportedFile := exportPath .Join (buildFile .Base ())
333+ logrus .WithField ("src" , buildFile ).WithField ("dest" , exportedFile ).Trace ("Copying artifact." )
334+ if err = buildFile .CopyTo (exportedFile ); err != nil {
335+ return r , & arduino.PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
336+ }
339337 }
340338 }
341339
0 commit comments