mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-15 05:09:29 +00:00
ATL-530: No checks before upload/verify/burn
Made the port/fqbn/programmer optional for upload, verify, and burn bootloader. From now on, the IDE does not warn the user before performing the desired CLI command. Closes arduino/arduino-pro-ide#364 Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -4,9 +4,12 @@ import { dirname } from 'path';
|
||||
import { CoreService } from '../common/protocol/core-service';
|
||||
import { CompileReq, CompileResp } from './cli-protocol/commands/compile_pb';
|
||||
import { CoreClientProvider } from './core-client-provider';
|
||||
import { UploadReq, UploadResp, BurnBootloaderReq, BurnBootloaderResp } from './cli-protocol/commands/upload_pb';
|
||||
import { UploadReq, UploadResp, BurnBootloaderReq, BurnBootloaderResp, UploadUsingProgrammerReq, UploadUsingProgrammerResp } from './cli-protocol/commands/upload_pb';
|
||||
import { OutputService } from '../common/protocol/output-service';
|
||||
import { NotificationServiceServer } from '../common/protocol';
|
||||
import { ClientReadableStream } from '@grpc/grpc-js';
|
||||
import { ArduinoCoreClient } from './cli-protocol/commands/commands_grpc_pb';
|
||||
import { firstToUpperCase, firstToLowerCase } from '../common/utils';
|
||||
|
||||
@injectable()
|
||||
export class CoreServiceImpl implements CoreService {
|
||||
@@ -21,7 +24,7 @@ export class CoreServiceImpl implements CoreService {
|
||||
protected readonly notificationService: NotificationServiceServer;
|
||||
|
||||
async compile(options: CoreService.Compile.Options): Promise<void> {
|
||||
this.outputService.append({ name: 'compile', chunk: 'Compiling...\n' + JSON.stringify(options, null, 2) + '\n--------------------------\n' });
|
||||
this.outputService.append({ name: 'compile', chunk: 'Compile...\n' + JSON.stringify(options, null, 2) + '\n--------------------------\n' });
|
||||
const { sketchUri, fqbn } = options;
|
||||
const sketchFilePath = FileUri.fsPath(sketchUri);
|
||||
const sketchpath = dirname(sketchFilePath);
|
||||
@@ -32,14 +35,12 @@ export class CoreServiceImpl implements CoreService {
|
||||
}
|
||||
const { client, instance } = coreClient;
|
||||
|
||||
if (!fqbn) {
|
||||
throw new Error('The selected board has no FQBN.');
|
||||
}
|
||||
|
||||
const compilerReq = new CompileReq();
|
||||
compilerReq.setInstance(instance);
|
||||
compilerReq.setSketchpath(sketchpath);
|
||||
compilerReq.setFqbn(fqbn);
|
||||
if (fqbn) {
|
||||
compilerReq.setFqbn(fqbn);
|
||||
}
|
||||
compilerReq.setOptimizefordebug(options.optimizeForDebug);
|
||||
compilerReq.setPreprocess(false);
|
||||
compilerReq.setVerbose(true);
|
||||
@@ -63,9 +64,23 @@ export class CoreServiceImpl implements CoreService {
|
||||
}
|
||||
|
||||
async upload(options: CoreService.Upload.Options): Promise<void> {
|
||||
await this.doUpload(options, () => new UploadReq(), (client, req) => client.upload(req));
|
||||
}
|
||||
|
||||
async uploadUsingProgrammer(options: CoreService.Upload.Options): Promise<void> {
|
||||
await this.doUpload(options, () => new UploadUsingProgrammerReq(), (client, req) => client.uploadUsingProgrammer(req), 'upload using programmer');
|
||||
}
|
||||
|
||||
protected async doUpload(
|
||||
options: CoreService.Upload.Options,
|
||||
requestProvider: () => UploadReq | UploadUsingProgrammerReq,
|
||||
responseHandler: (client: ArduinoCoreClient, req: UploadReq | UploadUsingProgrammerReq) => ClientReadableStream<UploadResp | UploadUsingProgrammerResp>,
|
||||
task: string = 'upload'): Promise<void> {
|
||||
|
||||
await this.compile(options);
|
||||
this.outputService.append({ name: 'upload', chunk: 'Uploading...\n' + JSON.stringify(options, null, 2) + '\n--------------------------\n' });
|
||||
const { sketchUri, fqbn } = options;
|
||||
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;
|
||||
const sketchFilePath = FileUri.fsPath(sketchUri);
|
||||
const sketchpath = dirname(sketchFilePath);
|
||||
|
||||
@@ -75,34 +90,32 @@ export class CoreServiceImpl implements CoreService {
|
||||
}
|
||||
const { client, instance } = coreClient;
|
||||
|
||||
if (!fqbn) {
|
||||
throw new Error('The selected board has no FQBN.');
|
||||
const req = requestProvider();
|
||||
req.setInstance(instance);
|
||||
req.setSketchPath(sketchpath);
|
||||
if (fqbn) {
|
||||
req.setFqbn(fqbn);
|
||||
}
|
||||
|
||||
const uploadReq = new UploadReq();
|
||||
uploadReq.setInstance(instance);
|
||||
uploadReq.setSketchPath(sketchpath);
|
||||
uploadReq.setFqbn(fqbn);
|
||||
if ('programmer' in options) {
|
||||
uploadReq.setProgrammer(options.programmer.id);
|
||||
if (port) {
|
||||
req.setPort(port);
|
||||
}
|
||||
if (options.port) {
|
||||
uploadReq.setPort(options.port);
|
||||
if (programmer) {
|
||||
req.setProgrammer(programmer.id);
|
||||
}
|
||||
const result = client.upload(uploadReq);
|
||||
const result = responseHandler(client, req);
|
||||
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
result.on('data', (resp: UploadResp) => {
|
||||
this.outputService.append({ name: 'upload', chunk: Buffer.from(resp.getOutStream_asU8()).toString() });
|
||||
this.outputService.append({ name: 'upload', chunk: Buffer.from(resp.getErrStream_asU8()).toString() });
|
||||
this.outputService.append({ name: task, chunk: Buffer.from(resp.getOutStream_asU8()).toString() });
|
||||
this.outputService.append({ name: task, chunk: Buffer.from(resp.getErrStream_asU8()).toString() });
|
||||
});
|
||||
result.on('error', error => reject(error));
|
||||
result.on('end', () => resolve());
|
||||
});
|
||||
this.outputService.append({ name: 'upload', chunk: '\n--------------------------\nUpload complete.\n' });
|
||||
this.outputService.append({ name: 'upload', chunk: '\n--------------------------\n' + firstToLowerCase(task) + ' complete.\n' });
|
||||
} catch (e) {
|
||||
this.outputService.append({ name: 'upload', chunk: `Upload error: ${e}\n`, severity: 'error' });
|
||||
this.outputService.append({ name: 'upload', chunk: `${firstToUpperCase(task)} error: ${e}\n`, severity: 'error' });
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -113,19 +126,19 @@ export class CoreServiceImpl implements CoreService {
|
||||
return;
|
||||
}
|
||||
const { fqbn, port, programmer } = options;
|
||||
if (!fqbn) {
|
||||
throw new Error('The selected board has no FQBN.');
|
||||
}
|
||||
if (!port) {
|
||||
throw new Error('Port must be specified.');
|
||||
}
|
||||
const { client, instance } = coreClient;
|
||||
const req = new BurnBootloaderReq();
|
||||
req.setFqbn(fqbn);
|
||||
req.setPort(port);
|
||||
req.setProgrammer(programmer.id);
|
||||
req.setInstance(instance);
|
||||
const result = client.burnBootloader(req);
|
||||
const burnReq = new BurnBootloaderReq();
|
||||
burnReq.setInstance(instance);
|
||||
if (fqbn) {
|
||||
burnReq.setFqbn(fqbn);
|
||||
}
|
||||
if (port) {
|
||||
burnReq.setPort(port);
|
||||
}
|
||||
if (programmer) {
|
||||
burnReq.setProgrammer(programmer.id);
|
||||
}
|
||||
const result = client.burnBootloader(burnReq);
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
result.on('data', (resp: BurnBootloaderResp) => {
|
||||
|
||||
Reference in New Issue
Block a user