@@ -118,9 +118,15 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
118118 const dc = DeviceContext . getInstance ( ) ;
119119
120120 if ( ! config . program || config . program === "${file}" ) {
121- // make a unique temp folder because keeping same temp folder will corrupt the build when board is changed
122- const outputFolder = path . join ( dc . output || `.build` , ArduinoContext . boardManager . currentBoard . board ) ;
123- util . mkdirRecursivelySync ( path . join ( ArduinoWorkspace . rootPath , outputFolder ) ) ;
121+ const outputFolder = path . join ( dc . output || `.build` ) ;
122+ const outputPath = path . join ( ArduinoWorkspace . rootPath , outputFolder ) ;
123+
124+ // if the directory was already there, clear the folder so that it's not corrupted from previous builds.
125+ if ( util . directoryExistsSync ( outputPath ) ) {
126+ util . rmdirRecursivelySync ( outputPath ) ;
127+ }
128+
129+ util . mkdirRecursivelySync ( outputPath ) ;
124130 if ( ! dc . sketch || ! util . fileExistsSync ( path . join ( ArduinoWorkspace . rootPath , dc . sketch ) ) ) {
125131 await dc . resolveMainSketch ( ) ;
126132 }
@@ -134,7 +140,7 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
134140 vscode . window . showErrorMessage ( `Cannot find ${ dc . sketch } , Please specify the sketch in the arduino.json file` ) ;
135141 return false ;
136142 }
137- config . program = path . join ( ArduinoWorkspace . rootPath , outputFolder , `${ path . basename ( dc . sketch ) } .elf` ) ;
143+ config . program = path . join ( outputPath , `${ path . basename ( dc . sketch ) } .elf` ) ;
138144
139145 // always compile elf to make sure debug the right elf
140146 if ( ! await ArduinoContext . arduinoApp . build ( BuildMode . Verify , outputFolder ) ) {
0 commit comments