Skip to content

[ATL-1531] Integrate arduino-cli 0.19.1 #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arduino-ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
],
"arduino": {
"cli": {
"version": "0.18.3"
"version": "0.19.1"
},
"fwuploader": {
"version": "2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class BurnBootloader extends SketchContribution {
}
try {
const { boardsConfig } = this.boardsServiceClientImpl;
const port = boardsConfig.selectedPort?.address;
const port = boardsConfig.selectedPort;
const [fqbn, { selectedProgrammer: programmer }, verify, verbose] =
await Promise.all([
this.boardsDataStore.appendConfigToFqbn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class UploadSketch extends SketchContribution {
const sketchUri = sketch.uri;
const optimizeForDebug = this.editorMode.compileForDebug;
const { selectedPort } = boardsConfig;
const port = selectedPort?.address;
const port = selectedPort;

if (usingProgrammer) {
const programmer = selectedProgrammer;
Expand Down
5 changes: 3 additions & 2 deletions arduino-ide-extension/src/common/protocol/core-service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Port } from '../../common/protocol/boards-service';
import { Programmer } from './boards-service';

export const CompilerWarningLiterals = [
Expand Down Expand Up @@ -39,7 +40,7 @@ export namespace CoreService {

export namespace Upload {
export interface Options extends Compile.Options {
readonly port?: string | undefined;
readonly port?: Port | undefined;
readonly programmer?: Programmer | undefined;
readonly verify: boolean;
}
Expand All @@ -48,7 +49,7 @@ export namespace CoreService {
export namespace Bootloader {
export interface Options {
readonly fqbn?: string | undefined;
readonly port?: string | undefined;
readonly port?: Port | undefined;
readonly programmer?: Programmer | undefined;
readonly verbose: boolean;
readonly verify: boolean;
Expand Down
33 changes: 26 additions & 7 deletions arduino-ide-extension/src/node/board-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { injectable, inject, postConstruct, named } from 'inversify';
import { ClientDuplexStream } from '@grpc/grpc-js';
import { ILogger } from '@theia/core/lib/common/logger';
import { deepClone } from '@theia/core/lib/common/objects';
import { CoreClientAware } from './core-client-provider';
import { CoreClientAware, CoreClientProvider } from './core-client-provider';
import {
BoardListWatchRequest,
BoardListWatchResponse,
Expand All @@ -29,6 +29,10 @@ export class BoardDiscovery extends CoreClientAware {
@inject(NotificationServiceServer)
protected readonly notificationService: NotificationServiceServer;

// Used to know if the board watch process is already running to avoid
// starting it multiple times
private watching: boolean;

protected boardWatchDuplex:
| ClientDuplexStream<BoardListWatchRequest, BoardListWatchResponse>
| undefined;
Expand All @@ -51,11 +55,26 @@ export class BoardDiscovery extends CoreClientAware {

@postConstruct()
protected async init(): Promise<void> {
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
this.startBoardListWatch(coreClient);
}

startBoardListWatch(coreClient: CoreClientProvider.Client): void {
if (this.watching) {
// We want to avoid starting the board list watch process multiple
// times to meet unforseen consequences
return
}
this.watching = true;
const { client, instance } = coreClient;
const req = new BoardListWatchRequest();
req.setInstance(instance);
this.boardWatchDuplex = client.boardListWatch();
this.boardWatchDuplex.on('end', () => {
this.watching = false;
console.info('board watch ended')
})
this.boardWatchDuplex.on('data', (resp: BoardListWatchResponse) => {
const detectedPort = resp.getPort();
if (detectedPort) {
Expand All @@ -75,12 +94,14 @@ export class BoardDiscovery extends CoreClientAware {
const oldState = deepClone(this._state);
const newState = deepClone(this._state);

const address = detectedPort.getAddress();
const protocol = Port.Protocol.toProtocol(detectedPort.getProtocol());
const address = (detectedPort as any).getPort().getAddress();
const protocol = Port.Protocol.toProtocol(
(detectedPort as any).getPort().getProtocol()
);
// const label = detectedPort.getProtocolLabel();
const port = { address, protocol };
const boards: Board[] = [];
for (const item of detectedPort.getBoardsList()) {
for (const item of detectedPort.getMatchingBoardsList()) {
boards.push({
fqbn: item.getFqbn(),
name: item.getName() || 'unknown',
Expand All @@ -92,9 +113,7 @@ export class BoardDiscovery extends CoreClientAware {
if (newState[port.address] !== undefined) {
const [, knownBoards] = newState[port.address];
console.warn(
`Port '${
port.address
}' was already available. Known boards before override: ${JSON.stringify(
`Port '${port.address}' was already available. Known boards before override: ${JSON.stringify(
knownBoards
)}`
);
Expand Down
30 changes: 20 additions & 10 deletions arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import { InstallWithProgress } from './grpc-installable';
@injectable()
export class BoardsServiceImpl
extends CoreClientAware
implements BoardsService
{
implements BoardsService {
@inject(ILogger)
protected logger: ILogger;

Expand Down Expand Up @@ -75,6 +74,7 @@ export class BoardsServiceImpl
async getBoardDetails(options: {
fqbn: string;
}): Promise<BoardDetails | undefined> {
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
const { client, instance } = coreClient;
const { fqbn } = options;
Expand Down Expand Up @@ -165,13 +165,13 @@ export class BoardsServiceImpl

let VID = 'N/A';
let PID = 'N/A';
const usbId = detailsResp
.getIdentificationPrefsList()
.map((item) => item.getUsbId())
const prop = detailsResp
.getIdentificationPropertiesList()
.map((item) => item.getPropertiesMap())
.find(notEmpty);
if (usbId) {
VID = usbId.getVid();
PID = usbId.getPid();
if (prop) {
VID = prop.get('vid') || '';
PID = prop.get('pid') || '';
}

return {
Expand Down Expand Up @@ -214,6 +214,7 @@ export class BoardsServiceImpl
}: {
query?: string;
}): Promise<BoardWithPackage[]> {
await this.coreClientProvider.initialized;
const { instance, client } = await this.coreClient();
const req = new BoardSearchRequest();
req.setSearchArgs(query || '');
Expand Down Expand Up @@ -244,6 +245,7 @@ export class BoardsServiceImpl
}

async search(options: { query?: string }): Promise<BoardsPackage[]> {
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
const { client, instance } = coreClient;

Expand Down Expand Up @@ -361,6 +363,7 @@ export class BoardsServiceImpl
const version = !!options.version
? options.version
: item.availableVersions[0];
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
const { client, instance } = coreClient;

Expand All @@ -382,7 +385,10 @@ export class BoardsServiceImpl
})
);
await new Promise<void>((resolve, reject) => {
resp.on('end', resolve);
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
resolve();
});
resp.on('error', (error) => {
this.responseService.appendToOutput({
chunk: `Failed to install platform: ${item.id}.\n`,
Expand All @@ -406,6 +412,7 @@ export class BoardsServiceImpl
progressId?: string;
}): Promise<void> {
const { item, progressId } = options;
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
const { client, instance } = coreClient;

Expand All @@ -426,7 +433,10 @@ export class BoardsServiceImpl
})
);
await new Promise<void>((resolve, reject) => {
resp.on('end', resolve);
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
resolve();
});
resp.on('error', reject);
});

Expand Down
Loading