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

Commit 5a49b97

Browse files
hlovdaladiazulay
authored andcommitted
Remove compile argument and expand BuildMode with CliUpload and CliUploadProgrammer
1 parent 8b83873 commit 5a49b97

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

src/arduino/arduino.ts

+42-25
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export enum BuildMode {
3636
Verify = "Verifying",
3737
Analyze = "Analyzing",
3838
Upload = "Uploading",
39+
CliUpload = "Uploading using Arduino CLI",
3940
UploadProgrammer = "Uploading (programmer)",
41+
CliUploadProgrammer = "Uploading (programmer) using Arduino CLI",
4042
};
4143

4244
/**
@@ -74,7 +76,7 @@ export class ArduinoApp {
7476
const analysisDelayMs = 1000 * 3;
7577
this._analysisManager = new AnalysisManager(
7678
() => this._building,
77-
async () => { await this.build(BuildMode.Analyze, true); },
79+
async () => { await this.build(BuildMode.Analyze); },
7880
analysisDelayMs);
7981
}
8082

@@ -159,23 +161,22 @@ export class ArduinoApp {
159161
* something is missing, it tries to query the user for the missing piece
160162
* of information (sketch, board, etc.). Analyze runs non interactively and
161163
* just returns false.
162-
* @param {bool} compile - Indicates whether to compile the code when using the CLI to upload
163164
* @param buildDir Override the build directory set by the project settings
164165
* with the given directory.
165166
* @returns true on success, false if
166167
* * another build is currently in progress
167168
* * board- or programmer-manager aren't initialized yet
168169
* * or something went wrong during the build
169170
*/
170-
public async build(buildMode: BuildMode, compile: boolean, buildDir?: string) {
171+
public async build(buildMode: BuildMode, buildDir?: string) {
171172

172173
if (!this._boardManager || !this._programmerManager || this._building) {
173174
return false;
174175
}
175176

176177
this._building = true;
177178

178-
return await this._build(buildMode, compile, buildDir)
179+
return await this._build(buildMode, buildDir)
179180
.then((ret) => {
180181
this._building = false;
181182
return ret;
@@ -498,7 +499,7 @@ export class ArduinoApp {
498499
* @param buildDir See build()
499500
* @see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc
500501
*/
501-
private async _build(buildMode: BuildMode, compile: boolean, buildDir?: string): Promise<boolean> {
502+
private async _build(buildMode: BuildMode, buildDir?: string): Promise<boolean> {
502503
const dc = DeviceContext.getInstance();
503504
const args: string[] = [];
504505
let restoreSerialMonitor: boolean = false;
@@ -549,22 +550,28 @@ export class ArduinoApp {
549550
return false;
550551
}
551552

552-
if (!compile && !this.useArduinoCli()) {
553-
arduinoChannel.error("This command is only available when using the Arduino CLI");
553+
if (!this.useArduinoCli()) {
554+
args.push("--upload");
555+
} else {
556+
args.push("compile", "--upload");
557+
}
558+
559+
if (dc.port) {
560+
args.push("--port", dc.port);
561+
}
562+
} else if (buildMode === BuildMode.CliUpload) {
563+
if ((!dc.configuration || !/upload_method=[^=,]*st[^,]*link/i.test(dc.configuration)) && !dc.port) {
564+
await selectSerial();
554565
return false;
555566
}
556567

557568
if (!this.useArduinoCli()) {
558-
args.push("--upload");
559-
} else {
560-
// TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
561-
if (compile) {
562-
args.push("compile", "--upload");
563-
} else {
564-
args.push("upload");
565-
}
569+
arduinoChannel.error("This command is only available when using the Arduino CLI");
570+
return false;
566571
}
567572

573+
args.push("upload");
574+
568575
if (dc.port) {
569576
args.push("--port", dc.port);
570577
}
@@ -578,20 +585,12 @@ export class ArduinoApp {
578585
await selectSerial();
579586
return false;
580587
}
581-
if (!compile && !this.useArduinoCli()) {
582-
arduinoChannel.error("This command is only available when using the Arduino CLI");
583-
return false;
584-
}
585588

586589
if (!this.useArduinoCli()) {
587590
args.push("--upload");
588591
} else {
589592
// TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
590-
if (compile) {
591-
args.push("compile", "--upload");
592-
} else {
593-
args.push("upload");
594-
}
593+
args.push("upload");
595594
}
596595

597596
if (this.useArduinoCli()) {
@@ -604,6 +603,24 @@ export class ArduinoApp {
604603
if (!this.useArduinoCli()) {
605604
args.push("--verify");
606605
}
606+
} else if (buildMode === BuildMode.CliUploadProgrammer) {
607+
const programmer = this.programmerManager.currentProgrammer;
608+
if (!programmer) {
609+
logger.notifyUserError("programmerManager.currentProgrammer", new Error(constants.messages.NO_PROGRAMMMER_SELECTED));
610+
return false;
611+
}
612+
if (!dc.port) {
613+
await selectSerial();
614+
return false;
615+
}
616+
if (!this.useArduinoCli()) {
617+
arduinoChannel.error("This command is only available when using the Arduino CLI");
618+
return false;
619+
}
620+
621+
args.push("compile", "--upload");
622+
args.push("--programmer", programmer)
623+
args.push("--port", dc.port);
607624
} else {
608625
if (!this.useArduinoCli()) {
609626
args.push("--verify");
@@ -631,7 +648,7 @@ export class ArduinoApp {
631648
arduinoChannel.show();
632649
arduinoChannel.start(`${buildMode} sketch '${dc.sketch}'`);
633650

634-
if ((buildDir || dc.output) && compile) {
651+
if (buildDir || dc.output) {
635652
// 2020-02-29, EW: This whole code appears a bit wonky to me.
636653
// What if the user specifies an output directory "../builds/my project"
637654
buildDir = path.resolve(ArduinoWorkspace.rootPath, buildDir || dc.output);

src/debug/configurationProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurat
137137
config.program = path.join(ArduinoWorkspace.rootPath, outputFolder, `${path.basename(dc.sketch)}.elf`);
138138

139139
// always compile elf to make sure debug the right elf
140-
if (!await ArduinoContext.arduinoApp.build(BuildMode.Verify, true, outputFolder)) {
140+
if (!await ArduinoContext.arduinoApp.build(BuildMode.Verify, outputFolder)) {
141141
vscode.window.showErrorMessage("Failed to verify the program, please check the output for details.");
142142
return false;
143143
}

src/extension.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export async function activate(context: vscode.ExtensionContext) {
120120
location: vscode.ProgressLocation.Window,
121121
title: "Arduino: Verifying...",
122122
}, async () => {
123-
await arduinoContextModule.default.arduinoApp.build(BuildMode.Verify, true);
123+
await arduinoContextModule.default.arduinoApp.build(BuildMode.Verify);
124124
});
125125
}
126126
}, () => {
@@ -136,7 +136,7 @@ export async function activate(context: vscode.ExtensionContext) {
136136
location: vscode.ProgressLocation.Window,
137137
title: "Arduino: Uploading...",
138138
}, async () => {
139-
await arduinoContextModule.default.arduinoApp.build(BuildMode.Upload, true);
139+
await arduinoContextModule.default.arduinoApp.build(BuildMode.Upload);
140140
});
141141
}
142142
}, () => {
@@ -149,7 +149,7 @@ export async function activate(context: vscode.ExtensionContext) {
149149
location: vscode.ProgressLocation.Window,
150150
title: "Arduino: Using CLI to upload...",
151151
}, async () => {
152-
await arduinoContextModule.default.arduinoApp.build(BuildMode.Upload, false);
152+
await arduinoContextModule.default.arduinoApp.build(BuildMode.CliUpload);
153153
});
154154
}
155155
}, () => {
@@ -183,7 +183,7 @@ export async function activate(context: vscode.ExtensionContext) {
183183
location: vscode.ProgressLocation.Window,
184184
title: "Arduino: Uploading (programmer)...",
185185
}, async () => {
186-
await arduinoContextModule.default.arduinoApp.build(BuildMode.UploadProgrammer, true);
186+
await arduinoContextModule.default.arduinoApp.build(BuildMode.UploadProgrammer);
187187
});
188188
}
189189
}, () => {
@@ -196,7 +196,7 @@ export async function activate(context: vscode.ExtensionContext) {
196196
location: vscode.ProgressLocation.Window,
197197
title: "Arduino: Using CLI to upload (programmer)...",
198198
}, async () => {
199-
await arduinoContextModule.default.arduinoApp.build(BuildMode.UploadProgrammer, false);
199+
await arduinoContextModule.default.arduinoApp.build(BuildMode.CliUploadProgrammer);
200200
});
201201
}
202202
}, () => {
@@ -209,7 +209,7 @@ export async function activate(context: vscode.ExtensionContext) {
209209
location: vscode.ProgressLocation.Window,
210210
title: "Arduino: Rebuilding IS Configuration...",
211211
}, async () => {
212-
await arduinoContextModule.default.arduinoApp.build(BuildMode.Analyze, true);
212+
await arduinoContextModule.default.arduinoApp.build(BuildMode.Analyze);
213213
});
214214
}
215215
}, () => {

0 commit comments

Comments
 (0)