@@ -118,9 +118,15 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
118
118
const dc = DeviceContext . getInstance ( ) ;
119
119
120
120
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 ) ;
124
130
if ( ! dc . sketch || ! util . fileExistsSync ( path . join ( ArduinoWorkspace . rootPath , dc . sketch ) ) ) {
125
131
await dc . resolveMainSketch ( ) ;
126
132
}
@@ -134,7 +140,7 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
134
140
vscode . window . showErrorMessage ( `Cannot find ${ dc . sketch } , Please specify the sketch in the arduino.json file` ) ;
135
141
return false ;
136
142
}
137
- config . program = path . join ( ArduinoWorkspace . rootPath , outputFolder , `${ path . basename ( dc . sketch ) } .elf` ) ;
143
+ config . program = path . join ( outputPath , `${ path . basename ( dc . sketch ) } .elf` ) ;
138
144
139
145
// always compile elf to make sure debug the right elf
140
146
if ( ! await ArduinoContext . arduinoApp . build ( BuildMode . Verify , outputFolder ) ) {
0 commit comments