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

Fix for Issue #1266 #1267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ The following settings are as per sketch settings of the Arduino extension. You
"output": "../build",
"debugger": "jlink",
"prebuild": "./prebuild.sh",
"succesfullbuild": "./successfulbuild.sh",
"failedbuild": "./successfulbuild.sh",
"postbuild": "./postbuild.sh",
"intelliSenseGen": "global"
}
Expand All @@ -122,7 +124,9 @@ The following settings are as per sketch settings of the Arduino extension. You
- `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.
- `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.
- `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.
- `postbuild` - External command to be run after the sketch has been built successfully. See the afore mentioned section for more details.
- `successfulbuild` - External command to be run after the sketch has been built successfully. See the afore mentioned section for more details.
- `failedbuild` - External command to be run if the sketch fails to be built. See the afore mentioned section for more details.
- `postbuild` - External command to be run after every sketch build. See the afore mentioned section for more details.
- `intelliSenseGen` - Override the global setting for auto-generation of the IntelliSense configuration (i.e. `.vscode/c_cpp_properties.json`). Three options are available:
- `"global"`: Use the global settings (default)
- `"disable"`: Disable the auto-generation even if globally enabled
Expand All @@ -136,7 +140,7 @@ The following settings are as per sketch settings of the Arduino extension. You
}
```

## Pre- and Post-Build Commands
## Pre-, Successful-, Failed-, and Post-Build Commands
On Windows the commands run within a `cmd`-, on Linux and OSX within a `bash`-instance. Therefore your command can be anything what you can run within those shells. Instead of running a command you can invoke a script. This makes writing more complex pre-/post-build mechanisms much easier and opens up the possibility to run python or other scripting languages.
The commands run within the workspace root directory and vscode-arduino sets the following environment variables:
**`VSCA_BUILD_MODE`** The current build mode, one of `Verifying`, `Uploading`, `Uploading (programmer)` or `Analyzing`. This allows you to run your script on certain build modes only.
Expand Down
10 changes: 10 additions & 0 deletions misc/arduinoValidator.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
"type": "string",
"minLength": 1
},
"successfulbuild": {
"description": "Command to be run after every successful build",
"type": "string",
"minLength": 1
},
"failedbuild": {
"description": "Command to be run after every failed build",
"type": "string",
"minLength": 1
},
"postbuild": {
"description": "Command to be run after every build",
"type": "string",
Expand Down
32 changes: 27 additions & 5 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,29 @@ export class ArduinoApp {
*/
protected async runPrePostBuildCommand(dc: DeviceContext,
environment: any,
what: "pre" | "post"): Promise<boolean> {
const cmdline = what === "pre"
? dc.prebuild
: dc.postbuild;
what: "pre" | "success" | "failed" | "post"): Promise<boolean> {
let cmdline;
switch(what) {
case "pre": {
cmdline = dc.prebuild;
break;
}
case "success": {
cmdline = dc.successfulbuild;
break;
}
case "failed": {
cmdline = dc.failedbuild;
break;
}
case "post": {
cmdline = dc.postbuild;
break;
}
default: {
break;
}
}

if (!cmdline) {
return true; // Successfully done nothing.
Expand Down Expand Up @@ -714,8 +733,11 @@ export class ArduinoApp {
const cleanup = async (result: "ok" | "error") => {
let ret = true;
if (result === "ok") {
ret = await this.runPrePostBuildCommand(dc, env, "post");
ret = await this.runPrePostBuildCommand(dc, env, "success");
} else {
ret = await this.runPrePostBuildCommand(dc, env, "failed");
}
ret = await this.runPrePostBuildCommand(dc, env, "post");
await cocopa.conclude();
if (buildMode === BuildMode.Upload || buildMode === BuildMode.UploadProgrammer) {
UsbDetector.getInstance().resumeListening();
Expand Down
10 changes: 10 additions & 0 deletions src/deviceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
public get onChangeISAutoGen() { return this._settings.intelliSenseGen.emitter.event }
public get onChangeConfiguration() { return this._settings.configuration.emitter.event }
public get onChangePrebuild() { return this._settings.prebuild.emitter.event }
public get onChangeSuccessfulbuild() { return this._settings.successfulbuild.emitter.event }
public get onChangeFailedbuild() { return this._settings.failedbuild.emitter.event }
public get onChangePostbuild() { return this._settings.postbuild.emitter.event }
public get onChangeProgrammer() { return this._settings.programmer.emitter.event }

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

public get successfulbuild() {
return this._settings.successfulbuild.value;
}

public get failedbuild() {
return this._settings.failedbuild.value;
}

public get postbuild() {
return this._settings.postbuild.value;
}
Expand Down
10 changes: 10 additions & 0 deletions src/deviceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export class DeviceSettings {
public intelliSenseGen = new StrSetting();
public configuration = new StrSetting();
public prebuild = new StrSetting();
public successfulbuild = new StrSetting();
public failedbuild = new StrSetting();
public postbuild = new StrSetting();
public programmer = new StrSetting();
public buildPreferences = new BuildPrefSetting();
Expand All @@ -158,6 +160,8 @@ export class DeviceSettings {
this.intelliSenseGen.modified ||
this.configuration.modified ||
this.prebuild.modified ||
this.successfulbuild.modified ||
this.failedbuild.modified ||
this.postbuild.modified ||
this.programmer.modified ||
this.buildPreferences.modified;
Expand All @@ -174,6 +178,8 @@ export class DeviceSettings {
this.intelliSenseGen.commit();
this.configuration.commit();
this.prebuild.commit();
this.successfulbuild.commit();
this.failedbuild.commit();
this.postbuild.commit();
this.programmer.commit();
this.buildPreferences.commit();
Expand All @@ -192,6 +198,8 @@ export class DeviceSettings {
this.intelliSenseGen.reset();
this.configuration.reset();
this.prebuild.reset();
this.successfulbuild.reset();
this.failedbuild.reset();
this.postbuild.reset();
this.programmer.reset();
this.buildPreferences.reset();
Expand All @@ -218,6 +226,8 @@ export class DeviceSettings {
this.debugger.value = settings.debugger;
this.intelliSenseGen.value = settings.intelliSenseGen;
this.prebuild.value = settings.prebuild;
this.successfulbuild.value = settings.successfulbuild;
this.failedbuild.value = settings.failedbuild;
this.postbuild.value = settings.postbuild;
this.programmer.value = settings.programmer;
this.buildPreferences.value = settings.buildPreferences;
Expand Down