Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 61367fc

Browse files
possible fix for #1473
1 parent 05c4f1c commit 61367fc

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/arduino/arduino.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,18 @@ export class ArduinoApp {
673673
if (buildDir || dc.output) {
674674
// 2020-02-29, EW: This whole code appears a bit wonky to me.
675675
// What if the user specifies an output directory "../builds/my project"
676-
buildDir = path.resolve(ArduinoWorkspace.rootPath, buildDir || dc.output);
676+
677+
// the first choice of the path should be from the users explicit settings.
678+
if (dc.output) {
679+
buildDir = path.resolve(ArduinoWorkspace.rootPath, dc.output);
680+
} else {
681+
buildDir = path.resolve(ArduinoWorkspace.rootPath, buildDir);
682+
}
683+
684+
677685
const dirPath = path.dirname(buildDir);
678686
if (!util.directoryExistsSync(dirPath)) {
679-
logger.notifyUserError("InvalidOutPutPath", new Error(constants.messages.INVALID_OUTPUT_PATH + buildDir));
680-
return false;
687+
util.mkdirRecursivelySync(dirPath);
681688
}
682689

683690
if (this.useArduinoCli()) {

src/debug/configurationProvider.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)