Skip to content

Commit f2927ec

Browse files
committed
Added successfulbuild and failedbuild External commands.
Issue: Provide the option to run a script/command after every verify. microsoft#1266
1 parent 18b5b3e commit f2927ec

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ The following settings are as per sketch settings of the Arduino extension. You
112112
"output": "../build",
113113
"debugger": "jlink",
114114
"prebuild": "./prebuild.sh",
115+
"succesfullbuild": "./successfulbuild.sh",
116+
"failedbuild": "./successfulbuild.sh",
115117
"postbuild": "./postbuild.sh",
116118
"intelliSenseGen": "global"
117119
}
@@ -122,7 +124,9 @@ The following settings are as per sketch settings of the Arduino extension. You
122124
- `output` - Arduino build output path. If not set, Arduino will create a new temporary output folder each time, which means it cannot reuse the intermediate result of the previous build leading to long verify/upload time, so it is recommended to set the field. Arduino requires that the output path should not be the workspace itself or in a subfolder of the workspace, otherwise, it may not work correctly. By default, this option is not set. It's worth noting that the contents of this file could be deleted during the build process, so pick (or create) a directory that will not store files you want to keep.
123125
- `debugger` - The short name of the debugger that will be used when the board itself does not have a debugger and there is more than one debugger available. You can find the list of debuggers [here](https://github.com/Microsoft/vscode-arduino/blob/master/misc/debuggerUsbMapping.json). By default, this option is not set.
124126
- `prebuild` - External command which will be invoked before any sketch build (verify, upload, ...). For details see the [Pre- and Post-Build Commands](#Pre--and-Post-Build-Commands) section.
125-
- `postbuild` - External command to be run after the sketch has been built successfully. See the afore mentioned section for more details.
127+
- `successfulbuild` - External command to be run if the sketch fails to be built.
128+
- `successfulbuild` - External command to be run after the sketch has been built successfully. See the afore mentioned section for more details.
129+
- `postbuild` - External command to be run after every sketch build.
126130
- `intelliSenseGen` - Override the global setting for auto-generation of the IntelliSense configuration (i.e. `.vscode/c_cpp_properties.json`). Three options are available:
127131
- `"global"`: Use the global settings (default)
128132
- `"disable"`: Disable the auto-generation even if globally enabled

misc/arduinoValidator.json

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
"type": "string",
4949
"minLength": 1
5050
},
51+
"successfulbuild": {
52+
"description": "Command to be run after every successful build",
53+
"type": "string",
54+
"minLength": 1
55+
},
56+
"failedbuild": {
57+
"description": "Command to be run after every failed build",
58+
"type": "string",
59+
"minLength": 1
60+
},
5161
"postbuild": {
5262
"description": "Command to be run after every build",
5363
"type": "string",

src/arduino/arduino.ts

+28-5
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,29 @@ export class ArduinoApp {
443443
*/
444444
protected async runPrePostBuildCommand(dc: DeviceContext,
445445
environment: any,
446-
what: "pre" | "post"): Promise<boolean> {
447-
const cmdline = what === "pre"
448-
? dc.prebuild
449-
: dc.postbuild;
446+
what: "pre" | "success" | "failed" | "post"): Promise<boolean> {
447+
let cmdline;
448+
switch(what) {
449+
case "pre": {
450+
cmdline = dc.prebuild;
451+
break;
452+
}
453+
case "success": {
454+
cmdline = dc.successfulbuild;
455+
break;
456+
}
457+
case "failed": {
458+
cmdline = dc.failedbuild;
459+
break;
460+
}
461+
case "post": {
462+
cmdline = dc.postbuild;
463+
break;
464+
}
465+
default: {
466+
break;
467+
}
468+
}
450469

451470
if (!cmdline) {
452471
return true; // Successfully done nothing.
@@ -714,8 +733,12 @@ export class ArduinoApp {
714733
const cleanup = async (result: "ok" | "error") => {
715734
let ret = true;
716735
if (result === "ok") {
717-
ret = await this.runPrePostBuildCommand(dc, env, "post");
736+
ret = await this.runPrePostBuildCommand(dc, env, "success");
737+
} else {
738+
ret = await this.runPrePostBuildCommand(dc, env, "failed");
718739
}
740+
// Do we need to handle a return value for this case?
741+
await this.runPrePostBuildCommand(dc, env, "post");
719742
await cocopa.conclude();
720743
if (buildMode === BuildMode.Upload || buildMode === BuildMode.UploadProgrammer) {
721744
UsbDetector.getInstance().resumeListening();

src/deviceContext.ts

+10
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
187187
public get onChangeISAutoGen() { return this._settings.intelliSenseGen.emitter.event }
188188
public get onChangeConfiguration() { return this._settings.configuration.emitter.event }
189189
public get onChangePrebuild() { return this._settings.prebuild.emitter.event }
190+
public get onChangeSuccessfulbuild() { return this._settings.successfulbuild.emitter.event }
191+
public get onChangeFailedbuild() { return this._settings.failedbuild.emitter.event }
190192
public get onChangePostbuild() { return this._settings.postbuild.emitter.event }
191193
public get onChangeProgrammer() { return this._settings.programmer.emitter.event }
192194

@@ -221,6 +223,14 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
221223
return this._settings.prebuild.value;
222224
}
223225

226+
public get successfulbuild() {
227+
return this._settings.successfulbuild.value;
228+
}
229+
230+
public get failedbuild() {
231+
return this._settings.failedbuild.value;
232+
}
233+
224234
public get postbuild() {
225235
return this._settings.postbuild.value;
226236
}

src/deviceSettings.ts

+10
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export class DeviceSettings {
141141
public intelliSenseGen = new StrSetting();
142142
public configuration = new StrSetting();
143143
public prebuild = new StrSetting();
144+
public successfulbuild = new StrSetting();
145+
public failedbuild = new StrSetting();
144146
public postbuild = new StrSetting();
145147
public programmer = new StrSetting();
146148
public buildPreferences = new BuildPrefSetting();
@@ -158,6 +160,8 @@ export class DeviceSettings {
158160
this.intelliSenseGen.modified ||
159161
this.configuration.modified ||
160162
this.prebuild.modified ||
163+
this.successfulbuild.modified ||
164+
this.failedbuild.modified ||
161165
this.postbuild.modified ||
162166
this.programmer.modified ||
163167
this.buildPreferences.modified;
@@ -174,6 +178,8 @@ export class DeviceSettings {
174178
this.intelliSenseGen.commit();
175179
this.configuration.commit();
176180
this.prebuild.commit();
181+
this.successfulbuild.commit();
182+
this.failedbuild.commit();
177183
this.postbuild.commit();
178184
this.programmer.commit();
179185
this.buildPreferences.commit();
@@ -192,6 +198,8 @@ export class DeviceSettings {
192198
this.intelliSenseGen.reset();
193199
this.configuration.reset();
194200
this.prebuild.reset();
201+
this.successfulbuild.reset();
202+
this.failedbuild.reset();
195203
this.postbuild.reset();
196204
this.programmer.reset();
197205
this.buildPreferences.reset();
@@ -218,6 +226,8 @@ export class DeviceSettings {
218226
this.debugger.value = settings.debugger;
219227
this.intelliSenseGen.value = settings.intelliSenseGen;
220228
this.prebuild.value = settings.prebuild;
229+
this.successfulbuild.value = settings.successfulbuild;
230+
this.failedbuild.value = settings.failedbuild;
221231
this.postbuild.value = settings.postbuild;
222232
this.programmer.value = settings.programmer;
223233
this.buildPreferences.value = settings.buildPreferences;

0 commit comments

Comments
 (0)