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

add prebuild for build and verify #551

Merged
merged 2 commits into from
May 7, 2018
Merged
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ The following settings are per sketch settings of the Arduino extension. You can
"port": "COM5",
"board": "adafruit:samd:adafruit_feather_m0",
"output": "../build",
"debugger": "jlink"
"debugger": "jlink",
"prebuild": "bash prebuild.sh"
}
```
- `sketch` - The main sketch file name of Arduino.
- `port` - Name of the serial port connected to the device. Can be set by the `Arduino: Select Serial Port` command.
- `board` - Current selected Arduino board alias. Can be set by the `Arduino: Change Board Type` command. Also, you can find the board list there.
- `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 subfolder of the workspace, otherwise, it may not work correctly. By default, this option is not set.
- `debugger` - The short name of the debugger that will be used when the board itself does not have any debugger and there are 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 before build sketch file. You should only set one prebuild command. `command1 && command2` doesn't work. If you need run multiple commands before build, write them into a script.

## Debugging Arduino Code <sup>preview</sup>
Before you start debug your Arduino code, read [this doc](https://code.visualstudio.com/docs/editor/debugging) and get to know the basic mechanism about debugging in Visual Studio Code. Also see [debugging for C++ in VSCode](https://code.visualstudio.com/docs/languages/cpp#_debugging) for your reference.
Expand Down
25 changes: 25 additions & 0 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ export class ArduinoApp {
UsbDetector.getInstance().pauseListening();
await vscode.workspace.saveAll(false);

if (dc.prebuild) {
arduinoChannel.info(`Run prebuild command: ${dc.prebuild}`);
const prebuildargs = dc.prebuild.split(" ");
const prebuildCommand = prebuildargs.shift();
try {
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, {shell: true, cwd: ArduinoWorkspace.rootPath});
} catch (ex) {
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
return;
}
}

const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch);
const args = ["--upload", "--board", boardDescriptor, "--port", dc.port, appPath];
if (VscodeSettings.getInstance().logLevel === "verbose") {
Expand Down Expand Up @@ -161,6 +173,19 @@ export class ArduinoApp {
await vscode.workspace.saveAll(false);

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

if (dc.prebuild) {
arduinoChannel.info(`Run prebuild command: ${dc.prebuild}`);
const prebuildargs = dc.prebuild.split(" ");
const prebuildCommand = prebuildargs.shift();
try {
await util.spawn(prebuildCommand, arduinoChannel.channel, prebuildargs, {shell: true, cwd: ArduinoWorkspace.rootPath});
} catch (ex) {
arduinoChannel.error(`Run prebuild failed: \n${ex.error}`);
return;
}
}

const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch);
const args = ["--verify", "--board", boardDescriptor, appPath];
if (VscodeSettings.getInstance().logLevel === "verbose") {
Expand Down
9 changes: 9 additions & 0 deletions src/deviceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {

private _sketchStatusBar: vscode.StatusBarItem;

private _prebuild: string;

/**
* @constructor
*/
Expand Down Expand Up @@ -142,6 +144,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._output = deviceConfigJson.output;
this._debugger = deviceConfigJson["debugger"];
this._onDidChange.fire();
this._prebuild = deviceConfigJson.prebuild;
} else {
Logger.notifyUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
}
Expand All @@ -153,6 +156,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._output = null;
this._debugger = null;
this._onDidChange.fire();
this._prebuild = null;
}
return this;
}, (reason) => {
Expand All @@ -169,6 +173,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._output = null;
this._debugger = null;
this._onDidChange.fire();
this._prebuild = null;

return this;
});
Expand Down Expand Up @@ -243,6 +248,10 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this.saveContext();
}

public get prebuild() {
return this._prebuild.trim();
}

public get output() {
return this._output;
}
Expand Down