From e957ac4331f604c5e9224c26c22346ed33ec92d2 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 1 Feb 2021 16:40:18 +0100 Subject: [PATCH] ATL-74: Added `Export compiled Binary`. Signed-off-by: Akos Kitta --- .../browser/arduino-frontend-contribution.tsx | 4 ++-- .../browser/contributions/upload-sketch.ts | 4 ++-- .../browser/contributions/verify-sketch.ts | 22 ++++++++++++++++--- .../src/common/protocol/core-service.ts | 2 +- .../protocol/sketches-service-client-impl.ts | 5 ++--- .../src/node/core-service-impl.ts | 5 +++-- .../src/node/sketches-service-impl.ts | 4 ++-- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx index b9d439c9..7df51e81 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx +++ b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx @@ -320,10 +320,10 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut } registry.registerSubmenu(ArduinoMenus.SKETCH, 'Sketch'); registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools'); - registry.registerMenuAction(ArduinoMenus.SKETCH, { + registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, { commandId: ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG.id, label: 'Optimize for Debugging', - order: '1' + order: '4' }); registry.registerMenuAction(ArduinoMenus.HELP__CONTROL_GROUP, { commandId: ArduinoCommands.TOGGLE_ADVANCED_MODE.id, diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 85c287cd..06a1fd6e 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -43,12 +43,12 @@ export class UploadSketch extends SketchContribution { registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, { commandId: UploadSketch.Commands.UPLOAD_SKETCH.id, label: 'Upload', - order: '0' + order: '1' }); registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, { commandId: UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER.id, label: 'Upload Using Programmer', - order: '1' + order: '2' }); } diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index 0ab3a5f1..606b4095 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -26,6 +26,9 @@ export class VerifySketch extends SketchContribution { registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, { execute: () => this.verifySketch() }); + registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, { + execute: () => this.verifySketch(true) + }); registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, { isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left', execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id) @@ -36,7 +39,12 @@ export class VerifySketch extends SketchContribution { registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, { commandId: VerifySketch.Commands.VERIFY_SKETCH.id, label: 'Verify/Compile', - order: '2' + order: '0' + }); + registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, { + commandId: VerifySketch.Commands.EXPORT_BINARIES.id, + label: 'Export compiled Binary', + order: '3' }); } @@ -45,6 +53,10 @@ export class VerifySketch extends SketchContribution { command: VerifySketch.Commands.VERIFY_SKETCH.id, keybinding: 'CtrlCmd+R' }); + registry.registerKeybinding({ + command: VerifySketch.Commands.EXPORT_BINARIES.id, + keybinding: 'CtrlCmd+Alt+S' + }); } registerToolbarItems(registry: TabBarToolbarRegistry): void { @@ -56,7 +68,7 @@ export class VerifySketch extends SketchContribution { }); } - async verifySketch(): Promise { + async verifySketch(exportBinaries: boolean = false): Promise { const uri = await this.sketchServiceClient.currentSketchFile(); if (!uri) { return; @@ -70,7 +82,8 @@ export class VerifySketch extends SketchContribution { sketchUri: uri, fqbn, optimizeForDebug: this.editorMode.compileForDebug, - verbose + verbose, + exportBinaries }); this.messageService.info('Done compiling.', { timeout: 1000 }); } catch (e) { @@ -85,6 +98,9 @@ export namespace VerifySketch { export const VERIFY_SKETCH: Command = { id: 'arduino-verify-sketch' }; + export const EXPORT_BINARIES: Command = { + id: 'arduino-export-binaries' + }; export const VERIFY_SKETCH_TOOLBAR: Command = { id: 'arduino-verify-sketch--toolbar' }; diff --git a/arduino-ide-extension/src/common/protocol/core-service.ts b/arduino-ide-extension/src/common/protocol/core-service.ts index 6854c2a2..19edf661 100644 --- a/arduino-ide-extension/src/common/protocol/core-service.ts +++ b/arduino-ide-extension/src/common/protocol/core-service.ts @@ -3,7 +3,7 @@ import { Programmer } from './boards-service'; export const CoreServicePath = '/services/core-service'; export const CoreService = Symbol('CoreService'); export interface CoreService { - compile(options: CoreService.Compile.Options): Promise; + compile(options: CoreService.Compile.Options & Readonly<{ exportBinaries: boolean }>): Promise; upload(options: CoreService.Upload.Options): Promise; uploadUsingProgrammer(options: CoreService.Upload.Options): Promise; burnBootloader(options: CoreService.Bootloader.Options): Promise; diff --git a/arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts b/arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts index 2e892216..3ad64af3 100644 --- a/arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts +++ b/arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts @@ -43,10 +43,9 @@ export class SketchesServiceClientImpl implements FrontendApplicationContributio this.toDispose.push(this.fileService.watch(new URI(sketchDirUri), { recursive: true, excludes: [] })); this.toDispose.push(this.fileService.onDidFilesChange(async event => { for (const { type, resource } of event.changes) { - // We track main sketch files changes only. + // We track main sketch files changes only. // TODO: check sketch folder changes. One can rename the folder without renaming the `.ino` file. if (sketchbookUri.isEqualOrParent(resource)) { - const { ext } = resource.path; // TODO: add support for `.pde`. - if (ext === '.ino') { + if (Sketch.isSketchFile(resource)) { if (type === FileChangeType.ADDED) { try { const toAdd = await this.sketchService.loadSketch(resource.parent.toString()); diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 6e68105e..801b869d 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -23,7 +23,7 @@ export class CoreServiceImpl implements CoreService { @inject(NotificationServiceServer) protected readonly notificationService: NotificationServiceServer; - async compile(options: CoreService.Compile.Options): Promise { + async compile(options: CoreService.Compile.Options & { exportBinaries: boolean }): Promise { this.outputService.append({ name: 'compile', chunk: 'Compile...\n' + JSON.stringify(options, null, 2) + '\n--------------------------\n' }); const { sketchUri, fqbn } = options; const sketchFilePath = FileUri.fsPath(sketchUri); @@ -42,6 +42,7 @@ export class CoreServiceImpl implements CoreService { compilerReq.setPreprocess(false); compilerReq.setVerbose(options.verbose); compilerReq.setQuiet(false); + compilerReq.setExportBinaries(options.exportBinaries); const result = client.compile(compilerReq); try { @@ -74,7 +75,7 @@ export class CoreServiceImpl implements CoreService { responseHandler: (client: ArduinoCoreClient, req: UploadReq | UploadUsingProgrammerReq) => ClientReadableStream, task: string = 'upload'): Promise { - await this.compile(options); + await this.compile(Object.assign(options, { exportBinaries: false })); const chunk = firstToUpperCase(task) + '...\n'; this.outputService.append({ name: 'upload', chunk: chunk + JSON.stringify(options, null, 2) + '\n--------------------------\n' }); const { sketchUri, fqbn, port, programmer } = options; diff --git a/arduino-ide-extension/src/node/sketches-service-impl.ts b/arduino-ide-extension/src/node/sketches-service-impl.ts index f1f3135b..5cc23af9 100644 --- a/arduino-ide-extension/src/node/sketches-service-impl.ts +++ b/arduino-ide-extension/src/node/sketches-service-impl.ts @@ -329,8 +329,8 @@ void loop() { const { client } = await this.coreClient(); const archivePath = FileUri.fsPath(destinationUri); // The CLI cannot override existing archives, so we have to wipe it manually: https://github.com/arduino/arduino-cli/issues/1160 - if (await fs.exists(archivePath)) { - await fs.unlink(archivePath); + if (await promisify(fs.exists)(archivePath)) { + await promisify(fs.unlink)(archivePath); } const req = new ArchiveSketchReq(); req.setSketchPath(FileUri.fsPath(sketch.uri));