-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjMgrExtGenerator.cpp
109 lines (94 loc) · 3.41 KB
/
ProjMgrExtGenerator.cpp
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
/*
* Copyright (c) 2020-2023 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "ProjMgrExtGenerator.h"
#include "ProjMgrLogger.h"
#include "ProjMgrYamlEmitter.h"
#include "RteFsUtils.h"
using namespace std;
ProjMgrExtGenerator::ProjMgrExtGenerator(ProjMgrParser* parser) :
m_parser(parser),
m_checkSchema(false) {
}
ProjMgrExtGenerator::~ProjMgrExtGenerator(void) {
// Reserved
}
void ProjMgrExtGenerator::SetCheckSchema(bool checkSchema) {
m_checkSchema = checkSchema;
}
bool ProjMgrExtGenerator::RetrieveGlobalGenerators(void) {
if (m_globalGeneratorFiles.empty()) {
// get global generator files
ProjMgrUtils::GetCompilerRoot(m_compilerRoot);
StrVec toolchainConfigFiles;
error_code ec;
for (auto const& entry : fs::recursive_directory_iterator(m_compilerRoot, ec)) {
if (entry.path().filename().string().find(".generator.yml") == string::npos) {
continue;
}
m_globalGeneratorFiles.push_back(entry.path().generic_string());
}
// parse global generator files
for (auto const& generatorFile : m_globalGeneratorFiles) {
if (!m_parser->ParseGlobalGenerator(generatorFile, m_checkSchema)) {
return false;
}
}
m_globalGenerators = m_parser->GetGlobalGenerators();
}
return true;
}
bool ProjMgrExtGenerator::IsGlobalGenerator(const string& generatorId) {
if (m_globalGenerators.find(generatorId) == m_globalGenerators.end()) {
return false;
}
return true;
}
bool ProjMgrExtGenerator::CheckGeneratorId(const string& generatorId, const string& componentId) {
if (!IsGlobalGenerator(generatorId)) {
ProjMgrLogger::Error("generator '" + generatorId + "' required by component '" +
componentId + "' was not found in global register");
return false;
}
return true;
}
const string& ProjMgrExtGenerator::GetGlobalGenDir(const string& generatorId) {
return(m_globalGenerators[generatorId].path);
}
const string& ProjMgrExtGenerator::GetGlobalGenRunCmd(const string& generatorId) {
return(m_globalGenerators[generatorId].run);
}
const string& ProjMgrExtGenerator::GetGlobalDescription(const string& generatorId) {
return(m_globalGenerators[generatorId].description);
}
void ProjMgrExtGenerator::AddUsedGenerator(const string& generatorId, const string& genDir, const string& contextId) {
m_usedGenerators[generatorId][genDir].push_back(contextId);
}
const GeneratorContextVecMap& ProjMgrExtGenerator::GetUsedGenerators(void) {
return m_usedGenerators;
}
ClayerItem* ProjMgrExtGenerator::GetGeneratorImport(const string& contextId, bool& success) {
ContextName context;
ProjMgrUtils::ParseContextEntry(contextId, context);
success = true;
for (const auto& [generator, genDirs] : GetUsedGenerators()) {
for (const auto& [genDir, contexts] : genDirs) {
if (find(contexts.begin(), contexts.end(), contextId) != contexts.end()) {
const string cgenFile = fs::path(genDir).append(context.project + ".cgen.yml").generic_string();
if (!RteFsUtils::Exists(cgenFile)) {
ProjMgrLogger::Error(cgenFile, "cgen file was not found, run generator '" + generator + "' for context '" + contextId + "'");
success = false;
return nullptr;
}
if (!m_parser->ParseClayer(cgenFile, m_checkSchema)) {
success = false;
return nullptr;
}
return &m_parser->GetClayers().at(cgenFile);
}
}
}
return nullptr;
}