mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-17 22:29:27 +00:00
ATL-983: Propose installing the required libs.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -11,12 +11,12 @@ import {
|
||||
PlatformListResp, Platform, PlatformUninstallResp, PlatformUninstallReq
|
||||
} from './cli-protocol/commands/core_pb';
|
||||
import { BoardDiscovery } from './board-discovery';
|
||||
import { CoreClientProvider } from './core-client-provider';
|
||||
import { CoreClientAware } from './core-client-provider';
|
||||
import { BoardDetailsReq, BoardDetailsResp } from './cli-protocol/commands/board_pb';
|
||||
import { ListProgrammersAvailableForUploadReq, ListProgrammersAvailableForUploadResp } from './cli-protocol/commands/upload_pb';
|
||||
|
||||
@injectable()
|
||||
export class BoardsServiceImpl implements BoardsService {
|
||||
export class BoardsServiceImpl extends CoreClientAware implements BoardsService {
|
||||
|
||||
@inject(ILogger)
|
||||
protected logger: ILogger;
|
||||
@@ -25,9 +25,6 @@ export class BoardsServiceImpl implements BoardsService {
|
||||
@named('discovery')
|
||||
protected discoveryLogger: ILogger;
|
||||
|
||||
@inject(CoreClientProvider)
|
||||
protected readonly coreClientProvider: CoreClientProvider;
|
||||
|
||||
@inject(OutputService)
|
||||
protected readonly outputService: OutputService;
|
||||
|
||||
@@ -49,25 +46,6 @@ export class BoardsServiceImpl implements BoardsService {
|
||||
return this.boardDiscovery.getAvailablePorts();
|
||||
}
|
||||
|
||||
private async coreClient(): Promise<CoreClientProvider.Client> {
|
||||
const coreClient = await new Promise<CoreClientProvider.Client>(async resolve => {
|
||||
const client = await this.coreClientProvider.client();
|
||||
if (client) {
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
const toDispose = this.coreClientProvider.onClientReady(async () => {
|
||||
const client = await this.coreClientProvider.client();
|
||||
if (client) {
|
||||
toDispose.dispose();
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
return coreClient;
|
||||
}
|
||||
|
||||
async getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined> {
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
|
||||
@@ -76,6 +76,9 @@ export class LibraryInstallReq extends jspb.Message {
|
||||
getVersion(): string;
|
||||
setVersion(value: string): LibraryInstallReq;
|
||||
|
||||
getNodeps(): boolean;
|
||||
setNodeps(value: boolean): LibraryInstallReq;
|
||||
|
||||
|
||||
serializeBinary(): Uint8Array;
|
||||
toObject(includeInstance?: boolean): LibraryInstallReq.AsObject;
|
||||
@@ -92,6 +95,7 @@ export namespace LibraryInstallReq {
|
||||
instance?: commands_common_pb.Instance.AsObject,
|
||||
name: string,
|
||||
version: string,
|
||||
nodeps: boolean,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -965,7 +965,8 @@ proto.cc.arduino.cli.commands.LibraryInstallReq.toObject = function(includeInsta
|
||||
var f, obj = {
|
||||
instance: (f = msg.getInstance()) && commands_common_pb.Instance.toObject(includeInstance, f),
|
||||
name: jspb.Message.getFieldWithDefault(msg, 2, ""),
|
||||
version: jspb.Message.getFieldWithDefault(msg, 3, "")
|
||||
version: jspb.Message.getFieldWithDefault(msg, 3, ""),
|
||||
nodeps: jspb.Message.getBooleanFieldWithDefault(msg, 4, false)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
@@ -1015,6 +1016,10 @@ proto.cc.arduino.cli.commands.LibraryInstallReq.deserializeBinaryFromReader = fu
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setVersion(value);
|
||||
break;
|
||||
case 4:
|
||||
var value = /** @type {boolean} */ (reader.readBool());
|
||||
msg.setNodeps(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
@@ -1066,6 +1071,13 @@ proto.cc.arduino.cli.commands.LibraryInstallReq.serializeBinaryToWriter = functi
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getNodeps();
|
||||
if (f) {
|
||||
writer.writeBool(
|
||||
4,
|
||||
f
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1142,6 +1154,24 @@ proto.cc.arduino.cli.commands.LibraryInstallReq.prototype.setVersion = function(
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional bool noDeps = 4;
|
||||
* @return {boolean}
|
||||
*/
|
||||
proto.cc.arduino.cli.commands.LibraryInstallReq.prototype.getNodeps = function() {
|
||||
return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 4, false));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {boolean} value
|
||||
* @return {!proto.cc.arduino.cli.commands.LibraryInstallReq} returns this
|
||||
*/
|
||||
proto.cc.arduino.cli.commands.LibraryInstallReq.prototype.setNodeps = function(value) {
|
||||
return jspb.Message.setProto3BooleanField(this, 4, value);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -167,3 +167,30 @@ export namespace CoreClientProvider {
|
||||
readonly instance: Instance;
|
||||
}
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export abstract class CoreClientAware {
|
||||
|
||||
@inject(CoreClientProvider)
|
||||
protected readonly coreClientProvider: CoreClientProvider;
|
||||
|
||||
protected async coreClient(): Promise<CoreClientProvider.Client> {
|
||||
const coreClient = await new Promise<CoreClientProvider.Client>(async resolve => {
|
||||
const client = await this.coreClientProvider.client();
|
||||
if (client) {
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
const toDispose = this.coreClientProvider.onClientReady(async () => {
|
||||
const client = await this.coreClientProvider.client();
|
||||
if (client) {
|
||||
toDispose.dispose();
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
return coreClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { relative } from 'path';
|
||||
import * as jspb from 'google-protobuf';
|
||||
import { CoreService } from '../common/protocol/core-service';
|
||||
import { CompileReq, CompileResp } from './cli-protocol/commands/compile_pb';
|
||||
import { CoreClientProvider } from './core-client-provider';
|
||||
import { CoreClientAware } from './core-client-provider';
|
||||
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';
|
||||
@@ -14,10 +14,7 @@ import { firstToUpperCase, firstToLowerCase } from '../common/utils';
|
||||
import { BoolValue } from 'google-protobuf/google/protobuf/wrappers_pb';
|
||||
|
||||
@injectable()
|
||||
export class CoreServiceImpl implements CoreService {
|
||||
|
||||
@inject(CoreClientProvider)
|
||||
protected readonly coreClientProvider: CoreClientProvider;
|
||||
export class CoreServiceImpl extends CoreClientAware implements CoreService {
|
||||
|
||||
@inject(OutputService)
|
||||
protected readonly outputService: OutputService;
|
||||
@@ -152,25 +149,6 @@ export class CoreServiceImpl implements CoreService {
|
||||
}
|
||||
}
|
||||
|
||||
private async coreClient(): Promise<CoreClientProvider.Client> {
|
||||
const coreClient = await new Promise<CoreClientProvider.Client>(async resolve => {
|
||||
const client = await this.coreClientProvider.client();
|
||||
if (client) {
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
const toDispose = this.coreClientProvider.onClientReady(async () => {
|
||||
const client = await this.coreClientProvider.client();
|
||||
if (client) {
|
||||
toDispose.dispose();
|
||||
resolve(client);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
return coreClient;
|
||||
}
|
||||
|
||||
private mergeSourceOverrides(req: { getSourceOverrideMap(): jspb.Map<string, string> }, options: CoreService.Compile.Options): void {
|
||||
const sketchPath = FileUri.fsPath(options.sketchUri);
|
||||
for (const uri of Object.keys(options.sourceOverride)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { injectable, inject, postConstruct } from 'inversify';
|
||||
import { LibraryPackage, LibraryService } from '../common/protocol/library-service';
|
||||
import { CoreClientProvider } from './core-client-provider';
|
||||
import { injectable, inject } from 'inversify';
|
||||
import { LibraryDependency, LibraryPackage, LibraryService } from '../common/protocol/library-service';
|
||||
import { CoreClientAware } from './core-client-provider';
|
||||
import {
|
||||
LibrarySearchReq,
|
||||
LibrarySearchResp,
|
||||
@@ -12,48 +12,28 @@ import {
|
||||
LibraryInstallResp,
|
||||
LibraryUninstallReq,
|
||||
LibraryUninstallResp,
|
||||
Library
|
||||
Library,
|
||||
LibraryResolveDependenciesReq
|
||||
} from './cli-protocol/commands/lib_pb';
|
||||
import { Installable } from '../common/protocol/installable';
|
||||
import { ILogger, notEmpty } from '@theia/core';
|
||||
import { Deferred } from '@theia/core/lib/common/promise-util';
|
||||
import { FileUri } from '@theia/core/lib/node';
|
||||
import { OutputService, NotificationServiceServer } from '../common/protocol';
|
||||
|
||||
@injectable()
|
||||
export class LibraryServiceImpl implements LibraryService {
|
||||
export class LibraryServiceImpl extends CoreClientAware implements LibraryService {
|
||||
|
||||
@inject(ILogger)
|
||||
protected logger: ILogger;
|
||||
|
||||
@inject(CoreClientProvider)
|
||||
protected readonly coreClientProvider: CoreClientProvider;
|
||||
|
||||
@inject(OutputService)
|
||||
protected readonly outputService: OutputService;
|
||||
|
||||
@inject(NotificationServiceServer)
|
||||
protected readonly notificationServer: NotificationServiceServer;
|
||||
|
||||
protected ready = new Deferred<void>();
|
||||
|
||||
@postConstruct()
|
||||
protected init(): void {
|
||||
this.coreClientProvider.client().then(client => {
|
||||
if (client) {
|
||||
this.ready.resolve();
|
||||
} else {
|
||||
this.coreClientProvider.onClientReady(() => this.ready.resolve());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async search(options: { query?: string }): Promise<LibraryPackage[]> {
|
||||
await this.ready.promise;
|
||||
const coreClient = await this.coreClientProvider.client();
|
||||
if (!coreClient) {
|
||||
return [];
|
||||
}
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
|
||||
const listReq = new LibraryListReq();
|
||||
@@ -96,12 +76,7 @@ export class LibraryServiceImpl implements LibraryService {
|
||||
}
|
||||
|
||||
async list({ fqbn }: { fqbn?: string | undefined }): Promise<LibraryPackage[]> {
|
||||
await this.ready.promise;
|
||||
const coreClient = await this.coreClientProvider.client();
|
||||
if (!coreClient) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
const req = new LibraryListReq();
|
||||
req.setInstance(instance);
|
||||
@@ -157,20 +132,42 @@ export class LibraryServiceImpl implements LibraryService {
|
||||
}).filter(notEmpty);
|
||||
}
|
||||
|
||||
async install(options: { item: LibraryPackage, version?: Installable.Version }): Promise<void> {
|
||||
await this.ready.promise;
|
||||
async listDependencies({ item, version, filterSelf }: { item: LibraryPackage, version: Installable.Version, filterSelf?: boolean }): Promise<LibraryDependency[]> {
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
const req = new LibraryResolveDependenciesReq();
|
||||
req.setInstance(instance);
|
||||
req.setName(item.name);
|
||||
req.setVersion(version);
|
||||
const dependencies = await new Promise<LibraryDependency[]>((resolve, reject) => {
|
||||
client.libraryResolveDependencies(req, (error, resp) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve(resp.getDependenciesList().map(dep => <LibraryDependency>{
|
||||
name: dep.getName(),
|
||||
installedVersion: dep.getVersioninstalled(),
|
||||
requiredVersion: dep.getVersionrequired()
|
||||
}));
|
||||
})
|
||||
});
|
||||
return filterSelf ? dependencies.filter(({ name }) => name !== item.name) : dependencies;
|
||||
}
|
||||
|
||||
async install(options: { item: LibraryPackage, version?: Installable.Version, installDependencies?: boolean }): Promise<void> {
|
||||
const item = options.item;
|
||||
const version = !!options.version ? options.version : item.availableVersions[0];
|
||||
const coreClient = await this.coreClientProvider.client();
|
||||
if (!coreClient) {
|
||||
return;
|
||||
}
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
|
||||
const req = new LibraryInstallReq();
|
||||
req.setInstance(instance);
|
||||
req.setName(item.name);
|
||||
req.setVersion(version);
|
||||
if (options.installDependencies === false) {
|
||||
req.setNodeps(true);
|
||||
}
|
||||
|
||||
console.info('>>> Starting library package installation...', item);
|
||||
const resp = client.libraryInstall(req);
|
||||
@@ -193,10 +190,7 @@ export class LibraryServiceImpl implements LibraryService {
|
||||
|
||||
async uninstall(options: { item: LibraryPackage }): Promise<void> {
|
||||
const item = options.item;
|
||||
const coreClient = await this.coreClientProvider.client();
|
||||
if (!coreClient) {
|
||||
return;
|
||||
}
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
|
||||
const req = new LibraryUninstallReq();
|
||||
|
||||
Reference in New Issue
Block a user