-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparser.go
More file actions
312 lines (283 loc) · 9.43 KB
/
parser.go
File metadata and controls
312 lines (283 loc) · 9.43 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package maker
import (
"os"
"path"
"path/filepath"
"slices"
"gopkg.in/yaml.v3"
log "github.com/sirupsen/logrus"
)
type CbuildIndex struct {
BuildIdx struct {
GeneratedBy string `yaml:"generated-by"`
Cdefault string `yaml:"cdefault"`
Csolution string `yaml:"csolution"`
TmpDir string `yaml:"tmpdir"`
Cprojects []Cprojects `yaml:"cprojects"`
Cbuilds []Cbuilds `yaml:"cbuilds"`
Executes []Executes `yaml:"executes"`
} `yaml:"build-idx"`
BaseDir string
}
type CbuildSet struct {
BuildSet struct {
GeneratedBy string `yaml:"generated-by"`
Contexts []Contexts `yaml:"contexts"`
Compiler string `yaml:"compiler"`
} `yaml:"cbuild-set"`
}
type Cbuild struct {
BuildDescType struct {
GeneratedBy string `yaml:"generated-by"`
CurrentGenerator struct{} `yaml:"current-generator"`
Solution string `yaml:"solution"`
Project string `yaml:"project"`
Context string `yaml:"context"`
Compiler string `yaml:"compiler"`
Board string `yaml:"board"`
BoardPack string `yaml:"board-pack"`
Device string `yaml:"device"`
DevicePack string `yaml:"device-pack"`
Processor Processor `yaml:"processor"`
Packs []Packs `yaml:"packs"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
LanguageC string `yaml:"language-C"`
LanguageCpp string `yaml:"language-CPP"`
Misc Misc `yaml:"misc"`
Define []interface{} `yaml:"define"`
DefineAsm []interface{} `yaml:"define-asm"`
AddPath []string `yaml:"add-path"`
AddPathAsm []string `yaml:"add-path-asm"`
OutputDirs OutputDirs `yaml:"output-dirs"`
Output []Output `yaml:"output"`
Components []Components `yaml:"components"`
Apis []Apis `yaml:"apis"`
Linker Linker `yaml:"linker"`
Groups []Groups `yaml:"groups"`
Generators []struct{} `yaml:"generators"`
ConstructedFiles []Files `yaml:"constructed-files"`
Licenses []struct{} `yaml:"licenses"`
} `yaml:"build"`
BaseDir string
ContextRoot string
SolutionRoot string
Languages []string
PreIncludeGlobal []string
LibraryGlobal []string
IncludeGlobal LanguageMap
UserIncGlobal LanguageMap
BuildGroups []string
Toolchain string
GeneratedFiles []string
}
type Cbuilds struct {
Cbuild string `yaml:"cbuild"`
Project string `yaml:"project"`
Configuration string `yaml:"configuration"`
DependsOn []string `yaml:"depends-on"`
}
type Clayers struct {
Clayer string `yaml:"clayer"`
}
type Contexts struct {
Context string `yaml:"context"`
}
type Cprojects struct {
Cproject string `yaml:"cproject"`
Clayers []Clayers `yaml:"clayers"`
}
type Apis struct {
API string `yaml:"api"`
Files []Files `yaml:"files"`
FromPack string `yaml:"from-pack"`
}
type Components struct {
Component string `yaml:"component"`
Condition string `yaml:"condition"`
SelectedBy string `yaml:"selected-by"`
Implements string `yaml:"implements"`
Rtedir string `yaml:"rtedir"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
LanguageC string `yaml:"language-C"`
LanguageCpp string `yaml:"language-CPP"`
Define []interface{} `yaml:"define"`
DefineAsm []interface{} `yaml:"define-asm"`
Undefine []string `yaml:"undefine"`
AddPath []string `yaml:"add-path"`
AddPathAsm []string `yaml:"add-path-asm"`
DelPath []string `yaml:"del-path"`
Misc Misc `yaml:"misc"`
Files []Files `yaml:"files"`
Generator Generator `yaml:"generator"`
FromPack string `yaml:"from-pack"`
}
type Executes struct {
Execute string `yaml:"execute"`
Run string `yaml:"run"`
Always map[string]interface{} `yaml:"always,inline"`
Input []string `yaml:"input"`
Output []string `yaml:"output"`
DependsOn []string `yaml:"depends-on"`
}
type Files struct {
File string `yaml:"file"`
Category string `yaml:"category"`
Scope string `yaml:"scope"`
Language string `yaml:"language"`
Attr string `yaml:"attr"`
Version string `yaml:"version"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
LanguageC string `yaml:"language-C"`
LanguageCpp string `yaml:"language-CPP"`
Define []interface{} `yaml:"define"`
DefineAsm []interface{} `yaml:"define-asm"`
Undefine []string `yaml:"undefine"`
AddPath []string `yaml:"add-path"`
AddPathAsm []string `yaml:"add-path-asm"`
DelPath []string `yaml:"del-path"`
Misc Misc `yaml:"misc"`
}
type Generator struct {
ID string `yaml:"id"`
Path string `yaml:"path"`
FromPack string `yaml:"from-pack"`
Files []Files `yaml:"files"`
}
type Groups struct {
Group string `yaml:"group"`
Groups []Groups `yaml:"groups"`
Files []Files `yaml:"files"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
LanguageC string `yaml:"language-C"`
LanguageCpp string `yaml:"language-CPP"`
Define []interface{} `yaml:"define"`
DefineAsm []interface{} `yaml:"define-asm"`
Undefine []string `yaml:"undefine"`
AddPath []string `yaml:"add-path"`
AddPathAsm []string `yaml:"add-path-asm"`
DelPath []string `yaml:"del-path"`
Misc Misc `yaml:"misc"`
}
type Linker struct {
Regions string `yaml:"regions"`
Script string `yaml:"script"`
Define []interface{} `yaml:"define"`
}
type Misc struct {
C []string `yaml:"C"`
CPP []string `yaml:"CPP"`
CCPP []string `yaml:"C-CPP"`
ASM []string `yaml:"ASM"`
Link []string `yaml:"Link"`
LinkC []string `yaml:"Link-C"`
LinkCPP []string `yaml:"Link-CPP"`
Library []string `yaml:"Library"`
Lib []string `yaml:"Lib"`
}
type OutputDirs struct {
Intdir string `yaml:"intdir"`
Outdir string `yaml:"outdir"`
Cprjdir string `yaml:"cprjdir"`
Rtedir string `yaml:"rtedir"`
}
type Output struct {
File string `yaml:"file"`
Type string `yaml:"type"`
}
type Processor struct {
Fpu string `yaml:"fpu"`
Dsp string `yaml:"dsp"`
Mve string `yaml:"mve"`
Endian string `yaml:"endian"`
Trustzone string `yaml:"trustzone"`
BranchProtection string `yaml:"branch-protection"`
Core string `yaml:"core"`
}
type Packs struct {
Pack string `yaml:"pack"`
Path string `yaml:"path"`
}
func (m *Maker) ParseCbuildIndexFile(cbuildIndexFile string) (data CbuildIndex, err error) {
yfile, err := os.ReadFile(cbuildIndexFile)
if err != nil {
return
}
err = yaml.Unmarshal(yfile, &data)
return
}
func (m *Maker) ParseCbuildSetFile(cbuildSetFile string) (data CbuildSet, err error) {
yfile, err := os.ReadFile(cbuildSetFile)
if err != nil {
return
}
err = yaml.Unmarshal(yfile, &data)
return
}
func (m *Maker) ParseCbuildFile(cbuildFile string) (data Cbuild, err error) {
yfile, err := os.ReadFile(cbuildFile)
if err != nil {
return
}
err = yaml.Unmarshal(yfile, &data)
return
}
func (m *Maker) ParseCbuildFiles() error {
// Parse cbuild-idx file
cbuildIndex, err := m.ParseCbuildIndexFile(m.Params.InputFile)
if err != nil {
return err
}
cbuildIndex.BaseDir, _ = filepath.Abs(path.Dir(m.Params.InputFile))
cbuildIndex.BaseDir = filepath.ToSlash(cbuildIndex.BaseDir)
m.CbuildIndex = cbuildIndex
m.SolutionRoot = filepath.ToSlash(filepath.Dir(filepath.Join(cbuildIndex.BaseDir, cbuildIndex.BuildIdx.Csolution)))
// Parse cbuild-set file
if m.Options.UseContextSet {
cbuildSetFile, _ := filepath.Abs(m.Params.InputFile[:len(m.Params.InputFile)-len(".cbuild-idx.yml")] + ".cbuild-set.yml")
cbuildSetFile = filepath.ToSlash(cbuildSetFile)
cbuildSet, err := m.ParseCbuildSetFile(cbuildSetFile)
if err != nil {
return err
}
for _, item := range cbuildSet.BuildSet.Contexts {
m.Contexts = append(m.Contexts, item.Context)
}
m.CbuildSet = cbuildSet
}
// Parse cbuild files
for _, cbuildRef := range m.CbuildIndex.BuildIdx.Cbuilds {
if m.Options.UseContextSet && !slices.Contains(m.Contexts, cbuildRef.Project+cbuildRef.Configuration) {
continue
}
cbuildFile := path.Join(m.CbuildIndex.BaseDir, cbuildRef.Cbuild)
if _, err := os.Stat(cbuildFile); os.IsNotExist(err) {
log.Warn("file " + cbuildFile + " was not found")
continue
}
cbuild, err := m.ParseCbuildFile(cbuildFile)
if err != nil {
return err
}
if !m.Options.UseContextSet {
m.Contexts = append(m.Contexts, cbuild.BuildDescType.Context)
}
cbuild.BaseDir, _ = filepath.Abs(path.Dir(cbuildFile))
cbuild.BaseDir = filepath.ToSlash(cbuild.BaseDir)
cbuild.SolutionRoot = m.SolutionRoot
m.Cbuilds = append(m.Cbuilds, cbuild)
}
return err
}