diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f667c9..5d1af0c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. ### Fixed - When using the bundled Arduino CLI, the extension will no longer attempt to make the CLI executable if it is already executable. Additionally, any errors that occur while attempting to make the CLI executable are shown in a notification. [#1601](https://github.com/microsoft/vscode-arduino/pull/1601) +- Refreshing the index in the board manager or library manager now works correctly with the Arduino CLI, and additional URLs from the `arduino.additionalUrls` setting are passed to the Arduino CLI. [#1611](https://github.com/microsoft/vscode-arduino/pull/1611) ## Version 0.5.0 diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index dcc4b585..6d6f27b6 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +import * as child_process from "child_process"; import * as fs from "fs"; import * as glob from "glob"; import * as os from "os"; @@ -129,6 +130,17 @@ export class ArduinoApp { } } + public getAdditionalUrls(): string[] { + // For better compatibility, merge urls both in user settings and arduino IDE preferences. + const settingsUrls = VscodeSettings.getInstance().additionalUrls; + let preferencesUrls = []; + const preferences = this._settings.preferences; + if (preferences && preferences.has("boardsmanager.additional.urls")) { + preferencesUrls = util.toStringArray(preferences.get("boardsmanager.additional.urls")); + } + return util.union(settingsUrls, preferencesUrls); + } + /** * Set the Arduino preferences value. * @param {string} key - The preference key @@ -259,10 +271,17 @@ export class ArduinoApp { arduinoChannel.info(`${packageName}${arch && ":" + arch}${version && ":" + version}`); try { if (this.useArduinoCli()) { - await util.spawn(this._settings.commandPath, - ["core", "install", `${packageName}${arch && ":" + arch}${version && "@" + version}`], - undefined, - { channel: showOutput ? arduinoChannel.channel : null }); + if (updatingIndex) { + await this.spawnCli( + ["core", "update-index"], + undefined, + { channel: showOutput ? arduinoChannel.channel : null }); + } else { + await this.spawnCli( + ["core", "install", `${packageName}${arch && ":" + arch}${version && "@" + version}`], + undefined, + { channel: showOutput ? arduinoChannel.channel : null }); + } } else { await util.spawn(this._settings.commandPath, ["--install-boards", `${packageName}${arch && ":" + arch}${version && ":" + version}`], @@ -311,10 +330,17 @@ export class ArduinoApp { } try { if (this.useArduinoCli()) { - await util.spawn(this._settings.commandPath, - ["lib", "install", `${libName}${version && "@" + version}`], - undefined, - { channel: showOutput ? arduinoChannel.channel : undefined }); + if (updatingIndex) { + this.spawnCli( + ["lib", "update-index"], + undefined, + { channel: showOutput ? arduinoChannel.channel : undefined }); + } else { + await this.spawnCli( + ["lib", "install", `${libName}${version && "@" + version}`], + undefined, + { channel: showOutput ? arduinoChannel.channel : undefined }); + } } else { await util.spawn(this._settings.commandPath, ["--install-library", `${libName}${version && ":" + version}`], @@ -816,7 +842,12 @@ export class ArduinoApp { arduinoChannel.channel.append(line); }); - return await util.spawn( + const run = (...args: any[]) => + this.useArduinoCli() ? + this.spawnCli(...(args.slice(1))) : + util.spawn.apply(undefined, args); + + return await run( this._settings.commandPath, args, { cwd: ArduinoWorkspace.rootPath }, @@ -836,4 +867,19 @@ export class ArduinoApp { return false; }); } + + private spawnCli( + args: string[] = [], + options: child_process.SpawnOptions = {}, + output?: {channel?: vscode.OutputChannel, + stdout?: (s: string) => void, + stderr?: (s: string) => void}, + ): Thenable { + const additionalUrls = this.getAdditionalUrls(); + return util.spawn( + this._settings.commandPath, + args.concat(["--additional-urls", additionalUrls.join(",")]), + options, + output); + } } diff --git a/src/arduino/boardManager.ts b/src/arduino/boardManager.ts index 81af5526..ee3f45c1 100644 --- a/src/arduino/boardManager.ts +++ b/src/arduino/boardManager.ts @@ -47,7 +47,7 @@ export class BoardManager { this._platforms = []; this._installedPlatforms = []; - const additionalUrls = this.getAdditionalUrls(); + const additionalUrls = this._arduinoApp.getAdditionalUrls(); if (update) { // Update index files. await this.setPreferenceUrls(additionalUrls); await this._arduinoApp.initialize(true); @@ -113,11 +113,11 @@ export class BoardManager { } public async updatePackageIndex(indexUri: string): Promise { - let allUrls = this.getAdditionalUrls(); + let allUrls = this._arduinoApp.getAdditionalUrls(); if (!(allUrls.indexOf(indexUri) >= 0)) { allUrls = allUrls.concat(indexUri); VscodeSettings.getInstance().updateAdditionalUrls(allUrls); - await this._arduinoApp.setPref("boardsmanager.additional.urls", this.getAdditionalUrls().join(",")); + await this._arduinoApp.setPref("boardsmanager.additional.urls", this._arduinoApp.getAdditionalUrls().join(",")); } return true; } @@ -527,17 +527,6 @@ export class BoardManager { return normalizedUrl.pathname.substr(normalizedUrl.pathname.lastIndexOf("/") + 1); } - private getAdditionalUrls(): string[] { - // For better compatibility, merge urls both in user settings and arduino IDE preferences. - const settingsUrls = VscodeSettings.getInstance().additionalUrls; - let preferencesUrls = []; - const preferences = this._settings.preferences; - if (preferences && preferences.has("boardsmanager.additional.urls")) { - preferencesUrls = util.toStringArray(preferences.get("boardsmanager.additional.urls")); - } - return util.union(settingsUrls, preferencesUrls); - } - private async setPreferenceUrls(additionalUrls: string[]) { const settingsUrls = additionalUrls.join(","); if (this._settings.preferences.get("boardsmanager.additional.urls") !== settingsUrls) {