diff --git a/src/arduino/arduino.ts b/src/arduino/arduino.ts index 492bf57d..790dd48d 100644 --- a/src/arduino/arduino.ts +++ b/src/arduino/arduino.ts @@ -298,7 +298,7 @@ export class ArduinoApp { if (this.useArduinoCli()) { args.push("--programmer", programmer) } else { - args.push("--useprogrammer", "--pref", "programmer=arduino:" + programmer) + args.push("--useprogrammer", "--pref", `programmer=arduino:${programmer}`); } args.push("--port", dc.port); @@ -315,6 +315,14 @@ export class ArduinoApp { } } + if (dc.buildPreferences) { + for (const pref of dc.buildPreferences) { + // Note: BuildPrefSetting makes sure that each preference + // value consists of exactly two items (key and value). + args.push("--pref", `${pref[0]}=${pref[1]}`); + } + } + // We always build verbosely but filter the output based on the settings args.push("--verbose-build"); if (verbose) { diff --git a/src/deviceContext.ts b/src/deviceContext.ts index f655ed6e..710782f1 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -264,6 +264,10 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { this.saveContext(); } + public get buildPreferences() { + return this._settings.buildPreferences.value; + } + public async initialize() { if (ArduinoWorkspace.rootPath && util.fileExistsSync(path.join(ArduinoWorkspace.rootPath, ARDUINO_CONFIG_FILE))) { vscode.window.showInformationMessage("Arduino.json already generated."); diff --git a/src/deviceSettings.ts b/src/deviceSettings.ts index 65c7a7b6..439c4ee0 100644 --- a/src/deviceSettings.ts +++ b/src/deviceSettings.ts @@ -99,6 +99,35 @@ class StrSetting extends Setting { } } +class BuildPrefSetting extends Setting { + public get value() { + return super.value; + } + public set value(value: string[][]) { + if (!Array.isArray(value)) { + super.value = super.default; + return; + } + if (value.length <= 0) { + super.value = super.default; + return; + } + for (const pref of value) { + if (!Array.isArray(pref) || pref.length !== 2) { + super.value = super.default; + return; + } + for (const i of pref) { + if (typeof i !== "string") { + super.value = super.default; + return; + } + } + } + super.value = value; + } +} + /** * This class encapsulates all device/project specific settings and * provides common operations on them. @@ -114,6 +143,7 @@ export class DeviceSettings { public prebuild = new StrSetting(); public postbuild = new StrSetting(); public programmer = new StrSetting(); + public buildPreferences = new BuildPrefSetting(); /** * @returns true if any of the settings values has its modified flag @@ -129,7 +159,8 @@ export class DeviceSettings { this.configuration.modified || this.prebuild.modified || this.postbuild.modified || - this.programmer.modified; + this.programmer.modified || + this.buildPreferences.modified; } /** * Clear modified flags of all settings values. @@ -145,6 +176,7 @@ export class DeviceSettings { this.prebuild.commit(); this.postbuild.commit(); this.programmer.commit(); + this.buildPreferences.commit(); } /** * Resets all settings values to their default values. @@ -162,6 +194,7 @@ export class DeviceSettings { this.prebuild.reset(); this.postbuild.reset(); this.programmer.reset(); + this.buildPreferences.reset(); if (commit) { this.commit(); } @@ -187,6 +220,7 @@ export class DeviceSettings { this.prebuild.value = settings.prebuild; this.postbuild.value = settings.postbuild; this.programmer.value = settings.programmer; + this.buildPreferences.value = settings.buildPreferences; if (commit) { this.commit(); }