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

Commit baaf069

Browse files
elektronikworkshopadiazulay
authored andcommitted
Pre-build command updates
* Moved pre-build command into separate member function to reduce code replication, better maintainablility and readability * Added pre-build command to "upload using programmer" since it was (probably unintentional) missing there
1 parent 79bd476 commit baaf069

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/arduino/arduino.ts

+35-20
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,8 @@ export class ArduinoApp {
139139
UsbDetector.getInstance().pauseListening();
140140
await vscode.workspace.saveAll(false);
141141

142-
if (dc.prebuild) {
143-
arduinoChannel.info(`Run prebuild command: ${dc.prebuild}`);
144-
const prebuildargs = dc.prebuild.split(" ");
145-
const prebuildCommand = prebuildargs.shift();
146-
try {
147-
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, { shell: true, cwd: ArduinoWorkspace.rootPath });
148-
} catch (ex) {
149-
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
150-
return;
151-
}
142+
if (!await this.runPreBuildCommand(dc)) {
143+
return;
152144
}
153145

154146
if (!compile && !this.useArduinoCli()) {
@@ -174,6 +166,10 @@ export class ArduinoApp {
174166
args.push("--port", dc.port);
175167
}
176168
args.push(appPath);
169+
if (!await this.runPreBuildCommand(dc)) {
170+
return;
171+
}
172+
177173
if (VscodeSettings.getInstance().logLevel === "verbose") {
178174
args.push("--verbose");
179175
}
@@ -228,16 +224,8 @@ export class ArduinoApp {
228224

229225
arduinoChannel.start(`Verify sketch - ${dc.sketch}`);
230226

231-
if (dc.prebuild) {
232-
arduinoChannel.info(`Run prebuild command: ${dc.prebuild}`);
233-
const prebuildargs = dc.prebuild.split(" ");
234-
const prebuildCommand = prebuildargs.shift();
235-
try {
236-
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, { shell: true, cwd: ArduinoWorkspace.rootPath });
237-
} catch (ex) {
238-
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
239-
return;
240-
}
227+
if (!await this.runPreBuildCommand(dc)) {
228+
return false;
241229
}
242230

243231
const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch);
@@ -779,6 +767,33 @@ export class ArduinoApp {
779767
this._programmerManager = value;
780768
}
781769

770+
/**
771+
* Runs the pre build command.
772+
* Usually before one of
773+
* * verify
774+
* * upload
775+
* * upload using programmer
776+
* @param dc Device context prepared during one of the above actions
777+
* @returns True if successful, false on error.
778+
*/
779+
protected async runPreBuildCommand(dc: DeviceContext): Promise<boolean> {
780+
if (dc.prebuild) {
781+
arduinoChannel.info(`Running pre-build command: ${dc.prebuild}`);
782+
const prebuildargs = dc.prebuild.split(" ");
783+
const prebuildCommand = prebuildargs.shift();
784+
try {
785+
await util.spawn(prebuildCommand,
786+
arduinoChannel.channel,
787+
prebuildargs,
788+
{ shell: true, cwd: ArduinoWorkspace.rootPath });
789+
} catch (ex) {
790+
arduinoChannel.error(`Running pre-build command failed: ${os.EOL}${ex.error}`);
791+
return false;
792+
}
793+
}
794+
return true;
795+
}
796+
782797
/**
783798
* Checks if the arduino cli is being used
784799
* @returns {bool} - true if arduino cli is being use

0 commit comments

Comments
 (0)