Skip to content

Commit 89e7bb5

Browse files
committed
[projmgr] External Generator PoC - Initial commit
1 parent afa82b5 commit 89e7bb5

35 files changed

Lines changed: 1113 additions & 78 deletions

tools/projmgr/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT projmgr)
1313
SET(PROJMGR_SOURCE_FILES ProjMgr.cpp ProjMgrKernel.cpp ProjMgrCallback.cpp
1414
ProjMgrParser.cpp ProjMgrWorker.cpp ProjMgrGenerator.cpp ProjMgrXmlParser.cpp
1515
ProjMgrYamlParser.cpp ProjMgrLogger.cpp ProjMgrYamlSchemaChecker.cpp
16-
ProjMgrYamlEmitter.cpp ProjMgrUtils.cpp
16+
ProjMgrYamlEmitter.cpp ProjMgrUtils.cpp ProjMgrExtGenerator.cpp
1717
)
1818
SET(PROJMGR_HEADER_FILES ProjMgr.h ProjMgrKernel.h ProjMgrCallback.h
1919
ProjMgrParser.h ProjMgrWorker.h ProjMgrGenerator.h ProjMgrXmlParser.h
2020
ProjMgrYamlParser.h ProjMgrLogger.h ProjMgrYamlSchemaChecker.h
21-
ProjMgrYamlEmitter.h ProjMgrUtils.h
21+
ProjMgrYamlEmitter.h ProjMgrUtils.h ProjMgrExtGenerator.h
2222
)
2323

2424
list(TRANSFORM PROJMGR_SOURCE_FILES PREPEND src/)

tools/projmgr/include/ProjMgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ProjMgr {
8888
ProjMgrWorker m_worker;
8989
ProjMgrGenerator m_generator;
9090
ProjMgrYamlEmitter m_emitter;
91+
ProjMgrExtGenerator m_extGenerator;
9192

9293
std::string m_csolutionFile;
9394
std::string m_cdefaultFile;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2020-2023 Arm Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef PROJMGREXTGENERATOR_H
8+
#define PROJMGREXTGENERATOR_H
9+
10+
#include "ProjMgrParser.h"
11+
#include "ProjMgrUtils.h"
12+
13+
/**
14+
* @brief external generator item containing
15+
* component identifier
16+
* directory for generated files
17+
* project type
18+
*/
19+
struct ExtGeneratorItem {
20+
std::string componentId;
21+
std::string genDir;
22+
std::string projectType;
23+
};
24+
25+
26+
struct CbuildGenItem {
27+
StrVec forContext;
28+
std::string device;
29+
std::string board;
30+
std::string projectPart;
31+
};
32+
33+
/**
34+
* @brief map of used generators, directories and contexts
35+
*/
36+
typedef std::map<std::string, StrVecMap> GeneratorContextVecMap;
37+
38+
/**
39+
* @brief vector of external generator items
40+
*/
41+
typedef std::vector<ExtGeneratorItem> ExtGeneratorVec;
42+
43+
/**
44+
* @brief map of vector of external generator items
45+
*/
46+
typedef std::map<std::string, ExtGeneratorVec> ExtGeneratorVecMap;
47+
48+
/**
49+
* @brief solution/project types
50+
*/
51+
static constexpr const char* TYPE_SINGLE_CORE = "single-core";
52+
static constexpr const char* TYPE_MULTI_CORE = "multi-core";
53+
static constexpr const char* TYPE_TRUSTZONE = "trustzone";
54+
static constexpr const char* PROCESSOR_CORE = "processor-core";
55+
56+
/**
57+
* @brief projmgr external generator class responsible for handling global generators
58+
*/
59+
class ProjMgrExtGenerator {
60+
public:
61+
/**
62+
* @brief class constructor
63+
*/
64+
ProjMgrExtGenerator(ProjMgrParser* parser);
65+
66+
67+
/**
68+
* @brief class destructor
69+
*/
70+
~ProjMgrExtGenerator(void);
71+
72+
73+
bool RetrieveGlobalGenerators(void);
74+
75+
bool IsGlobalGenerator(const std::string& generatorId);
76+
bool CheckGeneratorId(const std::string& generatorId, const std::string& componentId);
77+
const std::string& GetGlobalGenDir(const std::string& generatorId);
78+
const std::string& GetGlobalGenRunCmd(const std::string& generatorId);
79+
void AddUsedGenerator(const std::string& generatorId, const std::string& genDir, const std::string& contextId);
80+
const GeneratorContextVecMap& GetUsedGenerators(void);
81+
bool GetCgen(const std::string& contextId, ClayerItem& cgen);
82+
83+
protected:
84+
ProjMgrParser* m_parser = nullptr;
85+
StrVec m_globalGeneratorFiles;
86+
std::map<std::string, GlobalGeneratorItem> m_globalGenerators;
87+
GeneratorContextVecMap m_usedGenerators;
88+
89+
bool m_checkSchema;
90+
std::string m_compilerRoot;
91+
92+
93+
94+
95+
};
96+
97+
#endif // PROJMGREXTGENERATOR_H

tools/projmgr/include/ProjMgrParser.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,14 @@ struct TargetType {
140140
* @brief directories item containing
141141
* intdir directory,
142142
* outdir directory,
143+
* cbuild directory,
143144
* cprj directory,
144145
* rte directory,
145146
*/
146147
struct DirectoriesItem {
147148
std::string intdir;
148149
std::string outdir;
150+
std::string cbuild;
149151
std::string cprj;
150152
std::string rte;
151153
};
@@ -402,6 +404,20 @@ struct ClayerItem {
402404
GeneratorsItem generators;
403405
};
404406

407+
/**
408+
* @brief global generator item containing
409+
* generator id,
410+
* download url,
411+
* bridge program,
412+
* output
413+
*/
414+
struct GlobalGeneratorItem {
415+
std::string id;
416+
std::string downloadUrl;
417+
std::string run;
418+
std::string output;
419+
};
420+
405421
/**
406422
* @brief projmgr parser class for public interfacing
407423
*/
@@ -448,6 +464,12 @@ class ProjMgrParser {
448464
*/
449465
bool ParseGenericClayer(const std::string& input, bool checkSchema);
450466

467+
/**
468+
* @brief parse global generator
469+
* @param input generator.yml file
470+
*/
471+
bool ParseGlobalGenerator(const std::string& input, bool checkSchema);
472+
451473
/**
452474
* @brief get cdefault
453475
* @return cdefault item
@@ -478,12 +500,19 @@ class ProjMgrParser {
478500
*/
479501
std::map<std::string, ClayerItem>& GetGenericClayers(void);
480502

503+
/**
504+
* @brief get global generators
505+
* @return global generators map
506+
*/
507+
std::map<std::string, GlobalGeneratorItem>& GetGlobalGenerators(void);
508+
481509
protected:
482510
CdefaultItem m_cdefault;
483511
CsolutionItem m_csolution;
484512
std::map<std::string, CprojectItem> m_cprojects;
485513
std::map<std::string, ClayerItem> m_clayers;
486514
std::map<std::string, ClayerItem> m_genericClayers;
515+
std::map<std::string, GlobalGeneratorItem> m_globalGenerators;
487516
};
488517

489518
#endif // PROJMGRPARSER_H

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef PROJMGRWORKER_H
88
#define PROJMGRWORKER_H
99

10+
#include "ProjMgrExtGenerator.h"
1011
#include "ProjMgrKernel.h"
1112
#include "ProjMgrParser.h"
1213
#include "ProjMgrUtils.h"
@@ -252,6 +253,7 @@ struct ContextTypesItem {
252253
* output type,
253254
* device selection,
254255
* board selection,
256+
* device item struct,
255257
* list of package requirements,
256258
* map of required pdsc files and optionally its local path
257259
* list of component requirements,
@@ -269,6 +271,7 @@ struct ContextTypesItem {
269271
* valid connections,
270272
* linker options,
271273
* map of variables,
274+
* external generator directory,
272275
* boolean processed precedences
273276
*/
274277
struct ContextItem {
@@ -289,6 +292,7 @@ struct ContextItem {
289292
OutputTypes outputTypes;
290293
std::string device;
291294
std::string board;
295+
DeviceItem deviceItem;
292296
std::vector<PackageItem> packRequirements;
293297
std::map<std::string, std::pair<std::string, std::string>> pdscFiles;
294298
std::vector<PackInfo>missingPacks;
@@ -310,6 +314,7 @@ struct ContextItem {
310314
std::vector<ConnectionsCollectionVec> validConnections;
311315
LinkerContextItem linker;
312316
std::map<std::string, std::string> variables;
317+
StrMap extGenDir;
313318
bool precedences;
314319
};
315320

@@ -362,28 +367,22 @@ class ProjMgrWorker {
362367
/**
363368
* @brief class constructor
364369
*/
365-
ProjMgrWorker(void);
370+
ProjMgrWorker(ProjMgrParser* parser, ProjMgrExtGenerator* extGenerator);
366371

367372
/**
368373
* @brief class destructor
369374
*/
370375
~ProjMgrWorker(void);
371376

372-
/**
373-
* @brief set parser
374-
* @param pointer to parser
375-
*/
376-
void SetParser(ProjMgrParser* parser);
377-
378377
/**
379378
* @brief process context
380379
* @param reference to context
381-
* @param loadGpdsc boolean automatically load gpdsc, default true
380+
* @param loadGenFiles boolean automatically load generated files, default true
382381
* @param resolveDependencies boolean automatically resolve dependencies, default true
383382
* @param updateRteFiles boolean update RTE files, default true
384383
* @return true if executed successfully
385384
*/
386-
bool ProcessContext(ContextItem& context, bool loadGpdsc = true, bool resolveDependencies = true, bool updateRteFiles = true);
385+
bool ProcessContext(ContextItem& context, bool loadGenFiles = true, bool resolveDependencies = true, bool updateRteFiles = true);
387386

388387
/**
389388
* @brief list available packs
@@ -554,6 +553,8 @@ class ProjMgrWorker {
554553
*/
555554
bool ExecuteGenerator(std::string& generatorId);
556555

556+
bool ExecuteExtGenerator(std::string& generatorId);
557+
557558
/**
558559
* @brief initialize model
559560
* @return true if executed successfully
@@ -605,10 +606,14 @@ class ProjMgrWorker {
605606
*/
606607
void PrintMissingFilters(void);
607608

609+
bool ProcessGlobalGenerators(ContextItem* selectedContext, const std::string& generatorId,
610+
std::string& projectType, StrVec& siblings);
611+
608612
protected:
609613
ProjMgrParser* m_parser = nullptr;
610614
ProjMgrKernel* m_kernel = nullptr;
611615
RteGlobalModel* m_model = nullptr;
616+
ProjMgrExtGenerator* m_extGenerator = nullptr;
612617
std::list<RtePackage*> m_loadedPacks;
613618
std::vector<ToolchainItem> m_toolchains;
614619
StrVec m_toolchainConfigFiles;
@@ -640,7 +645,7 @@ class ProjMgrWorker {
640645
bool GetProjectSetup(ContextItem& context);
641646
bool InitializeTarget(ContextItem& context);
642647
bool SetTargetAttributes(ContextItem& context, std::map<std::string, std::string>& attributes);
643-
bool ProcessPrecedences(ContextItem& context);
648+
bool ProcessPrecedences(ContextItem& context, bool rerun = false);
644649
bool ProcessPrecedence(StringCollection& item);
645650
bool ProcessCompilerPrecedence(StringCollection& item, bool acceptRedefinition = false);
646651
bool ProcessDevice(ContextItem& context);
@@ -722,10 +727,13 @@ class ProjMgrWorker {
722727
void UpdatePartialReferencedContext(ContextItem& context, std::string& contextName);
723728
void ExpandAccessSequence(const ContextItem& context, const ContextItem& refContext, const std::string& sequence, std::string& item, bool withHeadingDot);
724729
bool GetGeneratorDir(const RteGenerator* generator, ContextItem& context, const std::string& layer, std::string& genDir);
730+
bool GetGeneratorDir(const std::string& generatorId, ContextItem& context, const std::string& layer, std::string& genDir);
731+
bool GetExtGeneratorDir(const std::string& generatorId, ContextItem& context, const std::string& layer, std::string& genDir);
725732
bool ParseContextLayers(ContextItem& context);
726733
bool AddPackRequirements(ContextItem& context, const std::vector<PackItem> packRequirements);
727734
void CheckTypeFilterSpelling(const TypeFilter& typeFilter);
728735
void CheckCompilerFilterSpelling(const std::string& compiler);
736+
bool ProcessGeneratedLayers(ContextItem& context);
729737
};
730738

731739
#endif // PROJMGRWORKER_H

tools/projmgr/include/ProjMgrYamlEmitter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ class ProjMgrYamlEmitter {
3333
*/
3434
static bool GenerateCbuildIndex(ProjMgrParser& parser, const std::vector<ContextItem*> contexts, const std::string& outputDir);
3535

36+
static bool GenerateCbuildGenIndex(ProjMgrParser& parser, const std::vector<ContextItem*> siblings,
37+
const std::string& type, const std::string& outputDir);
38+
3639
/**
3740
* @brief generate cbuild.yml file
3841
* @param context pointer to the context
3942
* @return true if executed successfully
4043
*/
4144
static bool GenerateCbuild(ContextItem* context);
45+
46+
static bool GenerateCbuildGen(ContextItem* context, const std::string& output);
4247
};
4348

4449
#endif // PROJMGRYAMLEMITTER_H

tools/projmgr/include/ProjMgrYamlParser.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ static constexpr const char* YAML_BASE_DIR = "base-dir";
2121
static constexpr const char* YAML_BASE_NAME = "base-name";
2222
static constexpr const char* YAML_BOARD = "board";
2323
static constexpr const char* YAML_BUILD = "build";
24+
static constexpr const char* YAML_BUILD_GEN = "build-gen";
2425
static constexpr const char* YAML_BUILD_IDX = "build-idx";
26+
static constexpr const char* YAML_BUILD_GEN_IDX = "build-gen-idx";
2527
static constexpr const char* YAML_BUILDTYPES = "build-types";
2628
static constexpr const char* YAML_CATEGORY = "category";
2729
static constexpr const char* YAML_CBUILDS = "cbuilds";
2830
static constexpr const char* YAML_CBUILD = "cbuild";
31+
static constexpr const char* YAML_CBUILD_GENS = "cbuild-gens";
32+
static constexpr const char* YAML_CBUILD_GEN = "cbuild-gen";
2933
static constexpr const char* YAML_CDEFAULT = "cdefault";
3034
static constexpr const char* YAML_CLAYERS = "clayers";
3135
static constexpr const char* YAML_CLAYER = "clayer";
@@ -53,6 +57,7 @@ static constexpr const char* YAML_DEFINE = "define";
5357
static constexpr const char* YAML_DELPATH = "del-path";
5458
static constexpr const char* YAML_DESCRIPTION = "description";
5559
static constexpr const char* YAML_DEVICE = "device";
60+
static constexpr const char* YAML_DOWNLOAD_URL = "download-url";
5661
static constexpr const char* YAML_ENDIAN = "endian";
5762
static constexpr const char* YAML_FILE = "file";
5863
static constexpr const char* YAML_FILES = "files";
@@ -61,6 +66,7 @@ static constexpr const char* YAML_FORBOARD = "for-board";
6166
static constexpr const char* YAML_FORCOMPILER = "for-compiler";
6267
static constexpr const char* YAML_FORCONTEXT = "for-context";
6368
static constexpr const char* YAML_FORDEVICE = "for-device";
69+
static constexpr const char* YAML_FORPROJECTPART = "for-project-part";
6470
static constexpr const char* YAML_FPU = "fpu";
6571
static constexpr const char* YAML_GENERATED_BY = "generated-by";
6672
static constexpr const char* YAML_GENERATOR = "generator";
@@ -106,16 +112,19 @@ static constexpr const char* YAML_PATH = "path";
106112
static constexpr const char* YAML_PROCESSOR = "processor";
107113
static constexpr const char* YAML_PROJECT = "project";
108114
static constexpr const char* YAML_PROJECTS = "projects";
115+
static constexpr const char* YAML_PROJECT_TYPE = "project-type";
109116
static constexpr const char* YAML_PROVIDES = "provides";
110117
static constexpr const char* YAML_REGIONS = "regions";
111118
static constexpr const char* YAML_RTE = "rte";
119+
static constexpr const char* YAML_RUN = "run";
112120
static constexpr const char* YAML_SCOPE = "scope";
113121
static constexpr const char* YAML_SCRIPT = "script";
114122
static constexpr const char* YAML_SOLUTION = "solution";
115123
static constexpr const char* YAML_SELECTED_BY = "selected-by";
116124
static constexpr const char* YAML_SETUPS = "setups";
117125
static constexpr const char* YAML_SETUP = "setup";
118126
static constexpr const char* YAML_SET = "set";
127+
static constexpr const char* YAML_SUB_DIR = "sub-dir";
119128
static constexpr const char* YAML_SWITCH = "switch";
120129
static constexpr const char* YAML_TARGETTYPES = "target-types";
121130
static constexpr const char* YAML_TRUSTZONE = "trustzone";
@@ -177,6 +186,15 @@ class ProjMgrYamlParser {
177186
bool ParseClayer(const std::string& input, std::map<std::string,
178187
ClayerItem>& clayers, bool checkSchema);
179188

189+
/**
190+
* @brief parse global generator
191+
* @param input generator.yml file
192+
* @param reference to store parsed generator item
193+
* @param checkSchema false to skip schema validation
194+
*/
195+
bool ParseGlobalGenerator(const std::string& input,
196+
std::map<std::string, GlobalGeneratorItem>& generators, bool checkSchema);
197+
180198
protected:
181199
void ParseMisc(const YAML::Node& parent, std::vector<MiscItem>& misc);
182200
void ParseDefine(const YAML::Node& parent, std::vector<std::string>& define);

0 commit comments

Comments
 (0)