diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d97038..eb3f653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 064833e..0a75903 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ 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: @@ -12,7 +17,7 @@ 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" } @@ -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", @@ -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 diff --git a/package.json b/package.json index c072077..edb43cb 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "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" }, @@ -12,23 +12,23 @@ "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" } @@ -57,7 +57,7 @@ }, "__metadata": { "id": "8e4967c3-c5a3-4f54-adf9-83f7daaff7db", - "publisherDisplayName": "Leonardo Polito", + "publisherDisplayName": "Christoffer Ringtved", "publisherId": "ae8a33b2-c6ae-4f52-9d5e-110b0065517e" } } \ No newline at end of file diff --git a/src/iar.js b/src/iar.js index 5262fc6..242bd71 100644 --- a/src/iar.js +++ b/src/iar.js @@ -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)) { @@ -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; @@ -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 \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) @@ -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); } @@ -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 @@ -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; @@ -230,17 +299,17 @@ 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'] }); @@ -248,21 +317,14 @@ class Iar { 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) { @@ -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...'); } @@ -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; diff --git a/src/main.js b/src/main.js index 41c2cc9..e8c13c0 100644 --- a/src/main.js +++ b/src/main.js @@ -19,23 +19,21 @@ function activate(context) { folder = vscode.workspace.rootPath; config_file = folder + "\\.vscode\\iar.json"; - vscode.workspace.onDidSaveTextDocument((e) => - { - if(config_file === e.fileName) - { - if (!(typeof iar === 'undefined' || iar === null)) + vscode.workspace.onDidSaveTextDocument((e) => { + if (config_file === e.fileName) { + if (!(typeof iar === 'undefined' || iar === null)) delete iar } }) - let disposable = vscode.commands.registerCommand('iar.build', function () { + let disposable = vscode.commands.registerCommand('iar.picker', function () { if (fs.existsSync(config_file)) { var obj = JSON.parse(fs.readFileSync(config_file)); if (obj["config"] && obj["path"] && obj["project"]) { - if (typeof iar === 'undefined' || iar === null) + if (typeof iar === 'undefined' || iar === null) iar = new Iar(resolve(obj.path), resolve(obj.project), obj.config, folder); - if(iar.in_progress() == false) - iar.build(); + if (iar.in_progress() == false) + iar.picker(obj); } } else {