Skip to content

Commit b096501

Browse files
authored
more log for '_installComponent'
1 parent 2ee70be commit b096501

2 files changed

Lines changed: 55 additions & 44 deletions

File tree

src/DependenceManager.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,35 @@ export class DependenceManager implements ManagerInterface {
7979

8080
/* 安装此组件的依赖项 */
8181
if (component.condition) {
82-
const result = packageManager.CheckConditionRequire(component.condition, toolchain);
83-
if (result == false)
82+
// check and get dependences
83+
let depList: string[] = [];
84+
try {
85+
depList= packageManager.checkComponentRequirement(component.condition, toolchain);
86+
} catch (error) {
87+
GlobalEvent.emit('globalLog.append', `[Warn] ${(<Error>error).message}\n`);
8488
throw new Error(`Condition '${component.condition}' is not fit for this component: '${component.groupName}'`);
85-
if (Array.isArray(result)) {
86-
for (const fullname of result) {
87-
if (!fullname.startsWith('Device.'))
88-
continue; /* 排除非 Device 类型的组件 */
89-
const reqName = fullname.replace('Device.', '');
90-
const compList = packageManager.FindAllComponents(reqName);
91-
if (compList) {
92-
for (const item of compList) {
93-
if (this.isInstalled(packName, item.groupName))
94-
continue; /* 排除已安装的 */
95-
if (pendingList.includes(item.groupName))
96-
continue; /* 排除队列中已存在的 */
97-
pendingList.push(item.groupName);
98-
GlobalEvent.emit('globalLog.append', `[Info] ${' '.repeat(pendingList.length)}-> install dependence component: ${item.groupName}\n`);
99-
this._installComponent(packName, item, pendingList);
100-
pendingList.pop();
101-
}
102-
} else {
103-
//throw new Error(`Not found required sub component: '${comp}'`);
104-
GlobalEvent.emit('globalLog.append',
105-
`[Warn] ${' '.repeat(pendingList.length)}Not found required sub component: '${reqName}'\n`);
89+
}
90+
// try install dependences
91+
for (const fullname of depList) {
92+
if (!fullname.startsWith('Device.'))
93+
continue; /* 排除非 Device 类型的组件 */
94+
const reqName = fullname.replace('Device.', '');
95+
const compList = packageManager.FindAllComponents(reqName);
96+
if (compList) {
97+
for (const item of compList) {
98+
if (this.isInstalled(packName, item.groupName))
99+
continue; /* 排除已安装的 */
100+
if (pendingList.includes(item.groupName))
101+
continue; /* 排除队列中已存在的 */
102+
pendingList.push(item.groupName);
103+
GlobalEvent.emit('globalLog.append', `[Info] ${' '.repeat(pendingList.length)}-> install dependence component: ${item.groupName}\n`);
104+
this._installComponent(packName, item, pendingList);
105+
pendingList.pop();
106106
}
107+
} else {
108+
//throw new Error(`Not found required sub component: '${comp}'`);
109+
GlobalEvent.emit('globalLog.append',
110+
`[Warn] ${' '.repeat(pendingList.length)}Not found required sub component: '${reqName}'\n`);
107111
}
108112
}
109113
}

src/PackageManager.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,35 +326,36 @@ export class PackageManager {
326326
this.packRootDir = new File(this.project.ToAbsolutePath(PackageManager.PACK_DIR));
327327
}
328328

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

332333
const familyInfo = cDev.packInfo.familyList[cDev.familyIndex];
333334
const devInfo = this.getCurrentDevInfo(cDev);
334335

335336
if (devInfo == undefined) {
336-
return false;
337+
throw new Error(`No such device info: deviceIndex=${cDev.deviceIndex}`);
337338
}
338339

339340
for (const con of cGroup.requireList) {
340341

341342
if (toolchain) {
342343

343344
if (con.compiler && con.compiler !== toolchain.categoryName) {
344-
return false;
345+
throw new Error(`Compiler category '${toolchain.categoryName}' not match, expect: ${con.compiler}`);
345346
}
346347

347348
if (con.compilerOption && con.compilerOption !== toolchain.name) {
348-
return false;
349+
throw new Error(`Compiler name '${toolchain.name}' not match, expect: ${con.compilerOption}`);
349350
}
350351
}
351352

352353
if (con.Dvendor && con.Dvendor !== familyInfo.vendor) {
353-
return false;
354+
throw new Error(`Family vendor '${familyInfo.vendor}' not match, expect: ${con.Dvendor}`);
354355
}
355356

356357
if (con.Dname && !con.Dname.test(devInfo.name)) {
357-
return false;
358+
throw new Error(`Device name '${devInfo.name}' not match, expect: ${con.Dname}`);
358359
}
359360

360361
if (con.component) {
@@ -365,18 +366,16 @@ export class PackageManager {
365366
const _group = gMap.get(con.condition);
366367
if (_group) {
367368
this._recurseList.push(con.condition);
368-
if (!this._checkConditionGroup(gMap, _group, cDev, comp_requires, toolchain)) {
369-
return false;
370-
}
369+
this._checkConditionGroup(gMap, _group, cDev, comp_requires, toolchain);
371370
}
372371
}
373372
}
374373

375374
if (cGroup.acceptList.length === 0) {
376-
return true;
375+
return;
377376
}
378377

379-
// return true, if one passed
378+
// return, if one passed
380379
let passCount = 0;
381380
for (const con of cGroup.acceptList) {
382381

@@ -418,8 +417,11 @@ export class PackageManager {
418417
const _group = gMap.get(con.condition);
419418
if (_group) {
420419
this._recurseList.push(con.condition);
421-
if (this._checkConditionGroup(gMap, _group, cDev, comp_requires, toolchain)) {
420+
try {
421+
this._checkConditionGroup(gMap, _group, cDev, comp_requires, toolchain);
422422
passCount++;
423+
} catch (error) {
424+
// nothing todo for accept condition
423425
}
424426
} else {
425427
passCount++;
@@ -429,11 +431,11 @@ export class PackageManager {
429431
}
430432

431433
if (passCount === 5) {
432-
return true;
434+
return;
433435
}
434436
}
435437

436-
return false;
438+
throw new Error(`Not match any 'accept' conditions !`);
437439
}
438440

439441
CheckCondition(conditionName: string, toolchain: IToolchian): boolean {
@@ -443,27 +445,32 @@ export class PackageManager {
443445
const cGroup = cMap.get(conditionName);
444446
if (cGroup) {
445447
this._recurseList = [conditionName];
446-
return this._checkConditionGroup(cMap, cGroup, this.currentDevice, [], toolchain);
448+
try {
449+
this._checkConditionGroup(cMap, cGroup, this.currentDevice, [], toolchain);
450+
return true;
451+
} catch (error) {
452+
return false;
453+
}
447454
}
448455
}
449456

450457
return true;
451458
}
452459

453-
CheckConditionRequire(conditionName: string, toolchain: IToolchian): string[] | boolean {
460+
checkComponentRequirement(conditionName: string, toolchain: IToolchian): string[] {
454461

455462
if (this.currentDevice) {
456463
const cMap = this.currentDevice.packInfo.conditionMap;
457464
const cGroup = cMap.get(conditionName);
458465
if (cGroup) {
459-
this._recurseList = [conditionName];
460466
const components: string[] = [];
461-
const pass = this._checkConditionGroup(cMap, cGroup, this.currentDevice, components, toolchain);
462-
return pass ? ArrayDelRepetition(components) : false;
467+
this._recurseList = [conditionName];
468+
this._checkConditionGroup(cMap, cGroup, this.currentDevice, components, toolchain);
469+
return ArrayDelRepetition(components);
463470
}
464471
}
465472

466-
return true;
473+
return [];
467474
}
468475

469476
makeComponentGroupName(...names: string[]): string {

0 commit comments

Comments
 (0)