Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added compatibility for IAR 9.0 #39

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# Change Log

## 1.8.1
- Added small debugger setup guide

## 1.8.0
- Added action picker

## 1.7.1
- Added compatibility for IAR 9.0

## 1.6.0
- Add iar.json file saved event

## 1.5.0
## 1.5.0
- cpp support
- parallel flag

Expand Down
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ As IAR works on Windows environment only, the extension is not been tested on di

This is NOT an official IAR Systems extension.

## THIS IS A FORK
The original project can be found here:

https://github.com/politoleo/iar

## Getting Started:

### 1) Create `iar.json` file inside `.vscode` folder:
Example `iar.json` configuration, customize it according to your setup:
```javascript
{
"version": 1,
"path": "C:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 8.0\\",
"path": "C:\\Program Files\\IAR Systems\\Embedded Workbench 9.0\\",
"project": "C:\\Projects\\TEST\\TEST.ewp",
"config": "Debug"
}
Expand All @@ -26,15 +31,30 @@ Example `iar.json` configuration, customize it according to your setup:
```

### 3) Run `ctrl+shift+b` to start build.

The extension automatically replaces your `c_cpp_properties.json` [Microsoft C++ Tools][cpptools] configuration to matches the IAR Project ones.

It supports browsing to external files, includepath, common defines and user included one.

### 4) Run `ctrl+shift+b` to pick action.
There are 3 different actions to choose between.

## Debug
IAR: Build

IAR: Clean

IAR: Rebuild

Example `launch.json` configuration for debug with J-Link:
Add the following in `iar.json` inside the `.vscode` folder to enable action picker:
```javascript
{
"iarPicker.enabled": true
}
```


## Debug

### Example `launch.json` configuration for debug with J-Link:
```javascript
{
"version": "0.2.1",
Expand Down Expand Up @@ -67,4 +87,44 @@ Example `launch.json` configuration for debug with J-Link:
]
}
```

### Example `launch.json` configuration for debug with st-util:

#### 1. Install vs code extension `Cortex-Debug`
https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug

#### 2. Install ARM GCC Toolchain
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads

#### 3. Install Texae's `st-util` GDB server
https://github.com/texane/stlink

#### 4. add `launch.json` to `.vscode` in project folder
svdFile can be found in IAR directory or downloaded from ST's website

The executable is found in the project directory

```javascript
{
"version": "0.2.0",
"configurations": [
{
"type": "cortex-debug",
"request": "launch",
"servertype": "stutil",
"cwd": "${workspaceRoot}",
"executable": "C:/Projects/TEST.out",
"svdFile": "C:/ST/STM32H743.svd",
"name": "Debug (ST-Util)",
"device": "STM32H743ZL2",
"runToMain": true,
"v1": false,
"serverpath": "C:/stlink/bin/st-util.exe",
"serverArgs": [
"--freq=4000k"
]
}
]
}
```
[cpptools]: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
"displayName": "IAR Embedded Workbench",
"icon": "icon.png",
"description": "Provide Intellisense and Build support for IAR Embedded Workbench IDE",
"version": "1.6.0",
"publisher": "politoleo",
"version": "1.8.1",
"publisher": "ChristofferRingtved",
"engines": {
"vscode": "^1.18.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:iar.build"
"onCommand:iar.picker"
],
"repository": {
"type": "git",
"url": "https://github.com/politoleo/iar.git"
"url": "https://github.com/HelligeChris/iar.git"
},
"main": "./src/main",
"contributes": {
"commands": [
{
"command": "iar.build",
"title": "IAR: Build Project"
"command": "iar.picker",
"title": "IAR: Choose Action"
}
],
"keybindings": [
{
"command": "iar.build",
"command": "iar.picker",
"key": "ctrl+shift+B",
"when": "!inDebugMode && config.iar.enabled"
}
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"__metadata": {
"id": "8e4967c3-c5a3-4f54-adf9-83f7daaff7db",
"publisherDisplayName": "Leonardo Polito",
"publisherDisplayName": "Christoffer Ringtved",
"publisherId": "ae8a33b2-c6ae-4f52-9d5e-110b0065517e"
}
}
135 changes: 99 additions & 36 deletions src/iar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ class Iar {
this.projectname = '';
}

arg_replacer(match, p1) {
var newstring = ' "' + p1 + '" -';
return newstring;
}

build_database_args(cmd) {
cmd += " --predef_macros"
var next = 1;
var arg_fixed = cmd.replace(/\s([a-zA-Z]:[\\\S|*\S].*?)\s-/gm, this.arg_replacer);
arg_fixed = arg_fixed.replace(/(.*?)( -\S+)/, "\"$1\"$2") // Fix the lack of quotes on the first filename.
var regex = /'.*?'|".*?"|\S+/g;
cmd = cmd.replace(/\"/g, '');
var arg_fixed = cmd.replace(/([a-zA-Z]:\\.*?)( -\S|$)/gm, "\"$1\"$2");
var regex = /".*?"|'.*?'|\S+/g;
var args = ['--IDE3', '--NCG'];
var temp;
while (temp = regex.exec(arg_fixed)) {
Expand All @@ -56,7 +52,7 @@ class Iar {
build_database_single(cmd, inc, def) {
var args = this.build_database_args(cmd);
var defs;
var tmpfile = os.tmpdir() + "\\" + path.basename(args[2].replace("\"", ""));
var tmpfile = os.tmpdir() + "\\" + path.basename(args[2].replace("\"", "")) + ".tmp";
args.push(tmpfile);
var spw = ch.spawnSync(this.path + "arm\\bin\\iccarm.exe", args);
var temp;
Expand Down Expand Up @@ -103,11 +99,15 @@ class Iar {

build_database() {
var i = 0;
for (var i = 0, icc_len = this.commands.length; i < icc_len; i++) {
if (this.commands.length > 0) {

var inc = [];
var def = [];
var command = this.commands[i][1] + " " + this.commands[i][2]
var tmpfile = os.tmpdir() + "\\temp1234.c";
fs.writeFileSync(tmpfile, "#include <stdio.h>\nint main(void) {return 0}\n");
var command = tmpfile + " " + this.commands[i][this.commands[i].length - 1]
this.build_database_single(command, inc, def);
fs.unlinkSync(tmpfile);
for (var j = 0, inc_len = inc.length; j < inc_len; j++) {
var tmp = path.normalize(inc[j]);
if (this.includes.indexOf(tmp) < 0)
Expand Down Expand Up @@ -154,7 +154,7 @@ class Iar {
}

//Check compile commands:
var icc_regex = new RegExp("^iccarm.exe (.*\\.c|.*\\.cpp) (.*)$", "gm");
var icc_regex = new RegExp('(^.*iccarm.exe|^.*iccarm.exe") (.*\\.cpp("|)|.*\\.c("|)) (.*)$', "gm");
while (temp = icc_regex.exec(build_output)) {
this.commands.push(temp);
}
Expand All @@ -178,7 +178,7 @@ class Iar {
var iar_config = {
name: "IAR",
intelliSenseMode: "clang-x64",
compilerPath:"",
compilerPath: "",
browse: browse_config,
includePath: this.includes,
defines: this.defines
Expand Down Expand Up @@ -215,7 +215,76 @@ class Iar {
return this.progress;
}

build() {
pickerItems = ["IAR: Build", "IAR: Clean", "IAR: Rebuild"];

picker(pickerEnable) {
if (!pickerEnable["iarPicker.enabled"]) {
this.build()
}
else {
vscode.window.showQuickPick(this.pickerItems).then(value => {
switch (value) {
case "IAR: Build":
{
this.build(false)
break
}
case "IAR: Clean":
{
this.clean()
break
}
case "IAR: Rebuild":
{
this.build(false)
break
}
default:
{
break
}
}
})
}
}
clean() {
iar.progress = true;

iar.parse_project();

if (!iar.terminal)
iar.terminal = vscode.window.createOutputChannel('IAR');
iar.terminal.show();
iar.terminal.clear();
vscode.workspace.saveAll(false);

iar.terminal.appendLine('Building configuration: ' + iar.config);

var task = os.cpus().length;

var args = [iar.project.split("\\").join("\\\\"), '-clean', iar.config];
var out = ch.spawn(iar.path + "common\\bin\\IarBuild.exe", args, {
stdio: ['ignore', 'pipe', 'ignore']
});

out.stdout.on('data', function (data) {
iar.terminal.appendLine(data);
})

out.on('close', function () {
iar.progress = false
})
out.on('error', function () {
iar.terminal.appendLine('Error while starting IarBuild.exe. Open it with IAR Ide to fix it.')
})
}

build(rebuild) {
var buildParameter = "-make"
if (rebuild) {
buildParameter = "-build"
}


var iar = this;

Expand All @@ -230,39 +299,32 @@ class Iar {

iar.parse_project();

if(!iar.terminal)
if (!iar.terminal)
iar.terminal = vscode.window.createOutputChannel('IAR');
iar.terminal.show();
iar.terminal.clear();
vscode.workspace.saveAll(false);
iar.terminal.clear();
vscode.workspace.saveAll(false);

iar.terminal.appendLine('Building configuration: ' + iar.config);

var task = os.cpus().length;

var args = [iar.project.split("\\").join("\\\\"), '-make', iar.config ,'-log', 'all', '-parallel', task];
var args = [iar.project.split("\\").join("\\\\"), buildParameter, iar.config, '-log', 'all', '-parallel', task];
var out = ch.spawn(iar.path + "common\\bin\\IarBuild.exe", args, {
stdio: ['ignore', 'pipe', 'ignore']
});

var build_output = '';
out.stdout.on('data', function (data) {
var buffer = data;
var temp;
var asm_regex = new RegExp("^iasmarm.exe (.*\\.s) (.*)$", "gmi");
while (temp = asm_regex.exec(buffer)) {
iar.terminal.appendLine(path.basename(temp[1]));
}
var icc_regex = new RegExp("^iccarm.exe (.*\\.c|.*\\.cpp) (.*)$", "gmi");
while (temp = icc_regex.exec(buffer)) {
iar.terminal.appendLine(path.basename(temp[1]));
}
var link_regex = new RegExp("^ilinkarm.exe.*\\.o.*$", "gmi");
if (temp = link_regex.exec(buffer)) {
iar.terminal.appendLine(' ');
iar.terminal.appendLine("Linking...");
}
var buf2 = String(buffer);
build_output += buffer;

buf2 = buf2.replace(new RegExp('^\n$', 'gm'), "");
buf2 = buf2.replace(new RegExp('(^.*iasmarm.exe|^.*iasmarm.exe") (.*)$', "gmi"), "")
buf2 = buf2.replace(new RegExp('(^.*iccarm.exe|^.*iccarm.exe") (.*)$', "gmi"), "")
buf2 = buf2.replace(new RegExp('(^.*ilinkarm.exe|^.*ilinkarm.exe") (.*)$', "gmi"), "Linking...")
iar.terminal.appendLine(buf2);
});

out.on('close', function (code) {
Expand All @@ -284,12 +346,10 @@ class Iar {
iar.build_database_config();
iar.terminal.appendLine(' ');

iar.terminal.appendLine('Errors: ' + iar.errors);
iar.terminal.appendLine('Warning: ' + iar.warnings);
iar.terminal.appendLine("Done");
}
}
else
{
else {
iar.terminal.appendLine('Something went wrong...');
}

Expand All @@ -300,7 +360,10 @@ class Iar {
out.on('error', function (data) {
iar.terminal.appendLine('Error while starting IarBuild.exe. Open it with IAR Ide to fix it.');
})


}

}

module.exports = Iar;
Loading