Skip to content

Commit 40493d6

Browse files
committed
安装组件时自动安装依赖项
1 parent 3ed8a81 commit 40493d6

File tree

5 files changed

+86
-13
lines changed

5 files changed

+86
-13
lines changed

src/DependenceManager.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,42 @@ export class DependenceManager implements ManagerInterface {
6565
}
6666

6767
InstallComponent(packName: string, component: Component) {
68+
this._installComponent(packName, component, [component.groupName]);
69+
}
70+
71+
private _installComponent(packName: string, component: Component, pendingList: string[]) {
6872

6973
const config = this.project.GetConfiguration();
7074
const toolchain = this.project.getToolchain();
7175
const packageManager = this.project.GetPackManager();
7276
const vSource = this.project.getVirtualSourceManager();
7377

78+
/* 安装此组件的依赖项 */
79+
if (component.condition) {
80+
const r = packageManager.CheckConditionRequire(component.condition, toolchain);
81+
if (r == false)
82+
throw new Error(`This condition '${component.condition}' is not met for component: '${component.groupName}'`);
83+
if (Array.isArray(r)) {
84+
for (const comp of r) {
85+
const compName = comp.replace('Device.', '');
86+
if (!comp.startsWith('Device.'))
87+
continue; /* 排除非 Device 类型的组件 */
88+
if (this.isInstalled(packName, compName))
89+
continue; /* 排除已安装的 */
90+
if (pendingList.includes(compName))
91+
continue; /* 排除队列中已存在的 */
92+
const t = packageManager.FindComponent(compName);
93+
if (t) {
94+
pendingList.push(compName);
95+
this._installComponent(packName, t, pendingList);
96+
pendingList.pop();
97+
} else {
98+
throw new Error(`Not found required sub component: '${comp}'`);
99+
}
100+
}
101+
}
102+
}
103+
74104
const item_filter = function (item: ComponentFileItem): boolean {
75105
return (item.attr != 'template')
76106
&& (item.condition ? packageManager.CheckCondition(item.condition, toolchain) : true);
@@ -83,6 +113,7 @@ export class DependenceManager implements ManagerInterface {
83113
const linkerList = component.linkerList?.filter(item_filter);
84114

85115
const conditionList: Set<string> = new Set();
116+
const includeList: string[] = component.incDirList.map(item => item.path);
86117

87118
// copy file
88119
asmList.forEach((item) => {
@@ -96,6 +127,8 @@ export class DependenceManager implements ManagerInterface {
96127
}
97128
});
98129
headerList.forEach((item) => {
130+
if (includeList.findIndex(p => File.isSubPathOf(p, item.path)) == -1)
131+
includeList.push(NodePath.dirname(item.path));
99132
if (item.condition) {
100133
conditionList.add(item.condition);
101134
}
@@ -115,10 +148,9 @@ export class DependenceManager implements ManagerInterface {
115148
// add condiions to cache
116149
this.addComponentCache(packName, component.groupName, Array.from(conditionList));
117150

118-
const incList = component.incDirList.map(item => item.path);
119151
const dep: Dependence = {
120152
name: component.groupName,
121-
incList: incList,
153+
incList: includeList,
122154
libList: component.libList ? component.libList.map<string>((item) => { return item.path; }) : [],
123155
defineList: component.defineList || []
124156
};

src/EIDEProject.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,11 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
13691369
if (device) {
13701370
const component = this.packManager.FindComponent(name);
13711371
if (component) {
1372-
this.dependenceManager.InstallComponent(device.packInfo.name, component);
1372+
try {
1373+
this.dependenceManager.InstallComponent(device.packInfo.name, component);
1374+
} catch (error) {
1375+
GlobalEvent.emit('msg', ExceptionToMessage(error, 'Warning'));
1376+
}
13731377
}
13741378
}
13751379
}
@@ -2765,7 +2769,11 @@ class EIDEProject extends AbstractProject {
27652769
if (compItem.state === ComponentUpdateType.Expired) { // if need reinstalled
27662770
const comp = this.packManager.FindComponent(compItem.name);
27672771
if (comp) {
2768-
this.dependenceManager.InstallComponent(packInfo.name, comp);
2772+
try {
2773+
this.dependenceManager.InstallComponent(packInfo.name, comp);
2774+
} catch (error) {
2775+
GlobalEvent.emit('globalLog', ExceptionToMessage(error, 'Warning'));
2776+
}
27692777
}
27702778
}
27712779

src/EIDEProjectExplorer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6288,6 +6288,8 @@ export class ProjectExplorer implements CustomConfigurationProvider {
62886288
for (const dep of group.depList) {
62896289
for (const incPath of dep.incList) {
62906290
const repath = prj.toRelativePath(incPath);
6291+
if (includes.includes(repath))
6292+
continue; // skip it existed
62916293
includes.push(repath);
62926294
includesMap.set(repath, group.groupName);
62936295
}

src/EIDEProjectModules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export interface Condition {
9898
Dname?: RegExp;
9999
compiler?: string;
100100
compilerOption?: string;
101+
component?: string;
101102
}
102103

103104
export interface ConditionGroup {

src/PackageManager.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { AbstractProject } from './EIDEProject';
4040
import { ExceptionToMessage, newMessage } from './Message';
4141
import { ResManager } from './ResManager';
4242
import { ExeCmd } from '../lib/node-utility/Executable';
43+
import { ArrayDelRepetition } from '../lib/node-utility/Utility';
4344

4445
export enum ComponentUpdateType {
4546
Disabled = 1,
@@ -326,7 +327,7 @@ export class PackageManager {
326327
}
327328

328329
private _checkConditionGroup(gMap: ConditionMap,
329-
cGroup: ConditionGroup, cDev: CurrentDevice, toolchain?: IToolchian): boolean {
330+
cGroup: ConditionGroup, cDev: CurrentDevice, comp_requires: string[], toolchain?: IToolchian): boolean {
330331

331332
const familyInfo = cDev.packInfo.familyList[cDev.familyIndex];
332333
const devInfo = this.getCurrentDevInfo(cDev);
@@ -356,11 +357,15 @@ export class PackageManager {
356357
return false;
357358
}
358359

360+
if (con.component) {
361+
comp_requires.push(con.component);
362+
}
363+
359364
if (con.condition && !this._recurseList.includes(con.condition)) {
360365
const _group = gMap.get(con.condition);
361366
if (_group) {
362367
this._recurseList.push(con.condition);
363-
if (!this._checkConditionGroup(gMap, _group, cDev, toolchain)) {
368+
if (!this._checkConditionGroup(gMap, _group, cDev, comp_requires, toolchain)) {
364369
return false;
365370
}
366371
}
@@ -413,7 +418,7 @@ export class PackageManager {
413418
const _group = gMap.get(con.condition);
414419
if (_group) {
415420
this._recurseList.push(con.condition);
416-
if (this._checkConditionGroup(gMap, _group, cDev, toolchain)) {
421+
if (this._checkConditionGroup(gMap, _group, cDev, comp_requires, toolchain)) {
417422
passCount++;
418423
}
419424
} else {
@@ -438,13 +443,36 @@ export class PackageManager {
438443
const cGroup = cMap.get(conditionName);
439444
if (cGroup) {
440445
this._recurseList = [conditionName];
441-
return this._checkConditionGroup(cMap, cGroup, this.currentDevice, toolchain);
446+
return this._checkConditionGroup(cMap, cGroup, this.currentDevice, [], toolchain);
442447
}
443448
}
444449

445450
return true;
446451
}
447452

453+
CheckConditionRequire(conditionName: string, toolchain: IToolchian): string[] | boolean {
454+
455+
if (this.currentDevice) {
456+
const cMap = this.currentDevice.packInfo.conditionMap;
457+
const cGroup = cMap.get(conditionName);
458+
if (cGroup) {
459+
this._recurseList = [conditionName];
460+
const components: string[] = [];
461+
const pass = this._checkConditionGroup(cMap, cGroup, this.currentDevice, components, toolchain);
462+
return pass ? ArrayDelRepetition(components) : false;
463+
}
464+
}
465+
466+
return true;
467+
}
468+
469+
makeComponentGroupName(...names: string[]): string {
470+
return names
471+
.filter(n => n !== undefined)
472+
.join('.')
473+
.replace(/\s+/g, '');
474+
}
475+
448476
private _preHandleSubfamily(family: any) {
449477
let _subFamilyList: any[] = [];
450478
for (const subFamily of (<any[]>family.subFamily)) {
@@ -957,7 +985,7 @@ export class PackageManager {
957985
for (let component of componentList) {
958986

959987
const item: Component = {
960-
groupName: component.$Cgroup + (component.$Csub ? ('.' + component.$Csub) : ''),
988+
groupName: this.makeComponentGroupName(component.$Cgroup, component.$Csub),
961989
enable: false,
962990
description: component.description,
963991
incDirList: [],
@@ -969,8 +997,6 @@ export class PackageManager {
969997
condition: component.$condition
970998
};
971999

972-
item.groupName = item.groupName.replace(/\s+/g, '');
973-
9741000
/* category component's files */
9751001

9761002
if (Array.isArray(component.files.file)) {
@@ -984,14 +1010,15 @@ export class PackageManager {
9841010

9851011
switch (f.$category) {
9861012
case 'include':
987-
if (/\.(?:h|hpp|hxx|inc)$/.test(f.$name)) {
1013+
if (AbstractProject.headerFilter.test(f.$name)) {
9881014
item.headerList.push(comp_item);
9891015
} else {
9901016
item.incDirList.push(comp_item);
9911017
}
9921018
break;
9931019
case 'header':
994-
item.headerList.push(comp_item);
1020+
if (AbstractProject.headerFilter.test(f.$name))
1021+
item.headerList.push(comp_item);
9951022
break;
9961023
case 'source':
9971024
case 'library':
@@ -1075,6 +1102,9 @@ export class PackageManager {
10751102
.replace(/\?/g, '.')
10761103
.replace(/\*/g, '.*?'), 'i');
10771104
}
1105+
if (require.$Cclass && require.$Cgroup) {
1106+
condition.component = this.makeComponentGroupName(require.$Cclass, require.$Cgroup, require.$Csub);
1107+
}
10781108

10791109
if (Object.keys(condition).length > 0) {
10801110
cGroup.requireList.push(condition);

0 commit comments

Comments
 (0)