-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsolution-outline-tree.ts
More file actions
169 lines (145 loc) · 6.82 KB
/
solution-outline-tree.ts
File metadata and controls
169 lines (145 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* Copyright 2024-2026 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { COutlineItem } from './solution-outline-item';
import { CSolution } from '../../../solutions/csolution';
import path from 'path';
import * as fsUtils from '../../../utils/fs-utils';
import { CTreeItem } from '../../../generic/tree-item';
import * as manifest from '../../../manifest';
import { HardwareItemBuilder } from './solution-outline-hardware-item';
import { ProjectItemsBuilder } from './solution-outline-project-items';
import { getFileNameNoExt } from '../../../utils/path-utils';
import { CProjectYamlFile } from '../../../solutions/files/cproject-yaml-file';
import { SolutionOutlineItemBuilder } from './solution-outline-item-builder';
export class SolutionOutlineTree extends SolutionOutlineItemBuilder {
public createTree(): COutlineItem {
const rootItem = new COutlineItem('solution');
if (!this.csolution) {
this.addLoadError(rootItem);
return rootItem;
}
const treeNodeItems = this.csolution.cbuildYmlRoot.size > 0
? this.processBuildFiles(rootItem, this.csolution)
: this.createProjectsFromCsolution(rootItem, this.csolution);
if (treeNodeItems.length === 0) {
this.addLoadError(rootItem);
}
this.addNodeItems(rootItem, treeNodeItems);
return rootItem;
}
private addLoadError(rootItem: COutlineItem): void {
this.createErrorNode(rootItem, 'Solution could not be loaded', 'Solution could not be loaded');
}
private createErrorNode(rootItem: COutlineItem, message: string, description: string): COutlineItem {
const errorItem = new COutlineItem(message, rootItem);
errorItem.setAttribute('iconPath', 'error');
errorItem.setAttribute('description', description);
rootItem.addChild(errorItem);
return rootItem;
}
private createProjectsFromCsolution(rootItem: COutlineItem, csolution: CSolution): COutlineItem[] {
const projectItems: COutlineItem[] = [];
// no build files are available (yet)
for (const cprojectYml of csolution.projects.values()) {
if (cprojectYml) {
projectItems.push(this.createProjectNode(rootItem, cprojectYml));
}
}
COutlineItem.sortTreeNodesByLabel(projectItems);
return projectItems;
}
private addNodeItems(rootItem: COutlineItem, treeNodeItems: COutlineItem[]): void {
for (const item of treeNodeItems) {
rootItem.addChild(item);
}
}
private processBuildFiles(parent: COutlineItem, csolution: CSolution): COutlineItem[] {
const hardwareTreeNode: Map<string, COutlineItem> = new Map();
let treeNodes: COutlineItem[] = [];
const projectsTreeNode: COutlineItem[] = [];
const hardwareTreeItem = new HardwareItemBuilder(csolution, this.rpcData);
for (const cbuildYml of csolution.cbuildYmlRoot) {
const cbuild = cbuildYml[1].getChildItem();
const cprojectYml = csolution.getCprojectForCbuild(cbuild, true);
if (cprojectYml) {
// add project nodes
const projectTreeNode = this.createProjectNode(parent, cprojectYml, cbuild);
projectsTreeNode.push(projectTreeNode);
}
// add hardware nodes
const hardware = hardwareTreeItem.createHardwareNodes(csolution, cbuild);
hardware.forEach((value, key) => {
hardwareTreeNode.set(key, value);
});
}
const hardwareTreeNodes = [...hardwareTreeNode.values()];
COutlineItem.sortTreeNodesByLabel(projectsTreeNode);
treeNodes = [...hardwareTreeNodes, ...projectsTreeNode];
return treeNodes;
}
private createProjectNode(parent: COutlineItem, cprojectFile: CProjectYamlFile, cbuild?: CTreeItem): COutlineItem {
const cproject = cprojectFile.topItem;
const projectType = cprojectFile.projectType;
const absolutePath = cproject?.rootFileName ?? '';
const projectFile = path.basename(absolutePath);
const projectName = getFileNameNoExt(projectFile);
const context = cbuild?.getValueAsString('context');
const project = context ? context : projectName;
// create project node
const cprojectItem = this.createProjectItem(parent, project, absolutePath, projectType);
// add children
if (cproject) {
const projectItems = new ProjectItemsBuilder(this.csolution, this.rpcData, context);
projectItems.addProjectChildren(this.csolution, cprojectItem, cprojectFile, cbuild);
} else {
cprojectItem.setAttribute('description', 'error loading project');
}
return cprojectItem;
}
private createProjectItem(parent: COutlineItem, project: string, absolutePath: string, projectType?: string): COutlineItem {
const cprojectItem = new COutlineItem('project', parent);
cprojectItem.setAttribute('label', project);
cprojectItem.setAttribute('expandable', '2');
cprojectItem.setAttribute('type', 'projectFile');
cprojectItem.setAttribute('iconPath', 'file-submodule');
cprojectItem.addFeature(`${manifest.PROJECT_CONTEXT}${absolutePath}`);
cprojectItem.setAttribute('resourcePath', absolutePath);
cprojectItem.setAttribute('projectUri', absolutePath);
// Add West-specific features
if (projectType === 'West') {
// Check for prj.conf and set path
const prjConfPath = this.findPrjConfPath(absolutePath);
if (prjConfPath) {
cprojectItem.setAttribute('prjConfPath', prjConfPath);
}
}
if (projectType) {
cprojectItem.setAttribute('description', `(${projectType})`);
cprojectItem.setAttribute('tooltip', `- Project type: \` ${projectType} \``);
} else {
cprojectItem.setAttribute('tooltip', `- File: \` ${absolutePath} \``);
}
return cprojectItem;
}
private findPrjConfPath(projectPath: string): string | undefined {
const appPath = path.dirname(projectPath);
const prjConfPath = path.join(appPath, 'prj.conf');
if (fsUtils.fileExists(prjConfPath)) {
return prjConfPath;
}
return undefined;
}
}