Skip to content

Commit 0e9ccd6

Browse files
authored
[projmgr] Initial zephyr/west integration support
1 parent b84ff71 commit 0e9ccd6

19 files changed

+522
-23
lines changed

tools/projmgr/include/ProjMgrParser.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct TargetSetItem {
209209
* misc compiler controls,
210210
* platform processor
211211
* context map
212+
* west defines
212213
*/
213214
struct BuildType {
214215
std::string compiler;
@@ -228,6 +229,7 @@ struct BuildType {
228229
ProcessorItem processor;
229230
std::vector<std::pair<std::string, std::string>> variables;
230231
std::vector<ContextName> contextMap;
232+
std::vector<std::string> westDefs;
231233
};
232234

233235
/**
@@ -452,6 +454,18 @@ struct GroupNode {
452454
TypeFilter type;
453455
};
454456

457+
/**
458+
* @brief west descriptor
459+
*/
460+
struct WestDesc {
461+
std::string projectId;
462+
std::string app;
463+
std::string board;
464+
std::string device;
465+
std::vector<std::string> westDefs;
466+
std::vector<std::string> westOpt;
467+
};
468+
455469
/**
456470
* @brief context descriptor containing
457471
* cproject filename,
@@ -460,6 +474,7 @@ struct GroupNode {
460474
struct ContextDesc {
461475
std::string cproject;
462476
TypeFilter type;
477+
WestDesc west;
463478
};
464479

465480
/**
@@ -506,6 +521,7 @@ typedef std::vector<std::pair<std::string, TargetType>> TargetTypes;
506521
* target types,
507522
* target properties,
508523
* list of cprojects,
524+
* list of west apps,
509525
* list of contexts descriptors,
510526
* list of packs,
511527
* cdefault enable switch,
@@ -524,6 +540,7 @@ struct CsolutionItem {
524540
TargetTypes targetTypes;
525541
TargetType target;
526542
std::vector<std::string> cprojects;
543+
std::vector<std::string> westApps;
527544
std::vector<ContextDesc> contexts;
528545
std::vector<PackItem> packs;
529546
bool enableCdefault;

tools/projmgr/include/ProjMgrUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ class ProjMgrUtils {
321321
*/
322322
static const std::string NormalizeLineEndings(const std::string& in);
323323

324+
/**
325+
* @brief convert board string to west board string
326+
* @param board string
327+
* @return output west board string
328+
*/
329+
static const std::string GetWestBoard(const std::string& board);
330+
324331
protected:
325332
/**
326333
* @brief get filtered list of contexts

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ struct DebuggerType {
429429
* load offset for generated binary
430430
* elf load mode
431431
* image only flag
432+
* west options
433+
* west on flag
432434
*/
433435
struct ContextItem {
434436
CdefaultItem* cdefault = nullptr;
@@ -498,6 +500,8 @@ struct ContextItem {
498500
std::string loadOffset;
499501
std::string elfLoadMode;
500502
bool imageOnly = false;
503+
WestDesc west;
504+
bool westOn = false;
501505
};
502506

503507
/**
@@ -509,6 +513,11 @@ static constexpr const char* PLM_STATUS_UPDATE_REQUIRED = "update required";
509513
static constexpr const char* PLM_STATUS_UPDATE_RECOMMENDED = "update recommended";
510514
static constexpr const char* PLM_STATUS_UPDATE_SUGGESTED = "update suggested";
511515

516+
/**
517+
* @brief west board variable
518+
*/
519+
static constexpr const char* WEST_BOARD = "west-board";
520+
512521
/**
513522
* @brief set policy for packs loading [latest|all|required]
514523
*/

tools/projmgr/include/ProjMgrYamlParser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static constexpr const char* YAML_ARGUMENTS = "arguments";
2727
static constexpr const char* YAML_APID = "apid";
2828
static constexpr const char* YAML_APIS = "apis";
2929
static constexpr const char* YAML_API = "api";
30+
static constexpr const char* YAML_APP_PATH = "app-path";
3031
static constexpr const char* YAML_ATOMIC = "atomic";
3132
static constexpr const char* YAML_ATTR = "attr";
3233
static constexpr const char* YAML_AUTO = "auto";
@@ -189,6 +190,7 @@ static constexpr const char* YAML_PROCESSORS = "processors";
189190
static constexpr const char* YAML_PROCESSOR = "processor";
190191
static constexpr const char* YAML_PROGRAMMING = "programming";
191192
static constexpr const char* YAML_PROJECT = "project";
193+
static constexpr const char* YAML_PROJECT_ID = "project-id";
192194
static constexpr const char* YAML_PROJECTS = "projects";
193195
static constexpr const char* YAML_PROJECT_CONTEXT = "project-context";
194196
static constexpr const char* YAML_PROJECT_TYPE = "project-type";
@@ -243,6 +245,9 @@ static constexpr const char* YAML_VARS = "vars";
243245
static constexpr const char* YAML_VALUE = "value";
244246
static constexpr const char* YAML_VERSION = "version";
245247
static constexpr const char* YAML_WARNINGS = "warnings";
248+
static constexpr const char* YAML_WEST = "west";
249+
static constexpr const char* YAML_WEST_DEFS = "west-defs";
250+
static constexpr const char* YAML_WEST_OPT = "west-opt";
246251
static constexpr const char* YAML_WHILE = "while";
247252
static constexpr const char* YAML_WORKING_DIR = "working-dir";
248253

tools/projmgr/schemas/common.schema.json

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@
406406
},
407407
{
408408
"type": "number"
409+
},
410+
{
411+
"type": "boolean"
409412
}
410413
]
411414
}
@@ -601,7 +604,8 @@
601604
"target-set": { "$ref": "#/definitions/TargetSetsType" },
602605
"undefine": { "$ref": "#/definitions/UndefinesType" },
603606
"variables": { "$ref": "#/definitions/VariablesType" },
604-
"warnings": { "$ref": "#/definitions/WarningsType" }
607+
"warnings": { "$ref": "#/definitions/WarningsType" },
608+
"west-defs": { "$ref": "#/definitions/DefinesType" }
605609
},
606610
"additionalProperties": false,
607611
"required" : [ "type"]
@@ -638,7 +642,8 @@
638642
"processor": { "$ref": "#/definitions/ProcessorType" },
639643
"undefine": { "$ref": "#/definitions/UndefinesType" },
640644
"variables": { "$ref": "#/definitions/VariablesType" },
641-
"warnings": { "$ref": "#/definitions/WarningsType" }
645+
"warnings": { "$ref": "#/definitions/WarningsType" },
646+
"west-defs": { "$ref": "#/definitions/DefinesType" }
642647
},
643648
"additionalProperties": false,
644649
"required" : [ "type"]
@@ -660,13 +665,13 @@
660665
"pattern": "^.*[/]([^.+]*\\.cproject\\.(yml|yaml))$|^([^.+]+)\\.cproject\\.(yml|yaml)$",
661666
"description": "Path to the valid project file."
662667
},
668+
"west": { "$ref": "#/definitions/WestProjectType" },
663669
"for-context": { "$ref": "#/definitions/ForContext" },
664670
"not-for-context": { "$ref": "#/definitions/NotForContext" }
665671
},
666672
"additionalProperties": false,
667-
"allOf": [
668-
{ "$ref": "#/definitions/TypeListMutualExclusion"},
669-
{ "required": [ "project" ] }
673+
"oneOf": [
674+
{ "$ref": "#/definitions/TypeListMutualExclusion"}
670675
]
671676
},
672677
"ProcessorTrustzone": {
@@ -1274,6 +1279,7 @@
12741279
"type": "object",
12751280
"properties": {
12761281
"cbuild": { "type": "string", "description": "Path to <context>.cbuild.yml file." },
1282+
"west": { "type": "boolean" },
12771283
"project": { "type": "string", "description": "Project name." },
12781284
"configuration": { "$ref": "#/definitions/BuildContext" },
12791285
"depends-on": {
@@ -1427,7 +1433,8 @@
14271433
"licenses": {
14281434
"type": "array",
14291435
"items": { "$ref": "#/definitions/LicenseInfoType" }
1430-
}
1436+
},
1437+
"west": { "$ref": "#/definitions/WestProjectType" }
14311438
},
14321439
"additionalProperties": false
14331440
},
@@ -2398,6 +2405,21 @@
23982405
"title": "optimize:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#load",
23992406
"description": "Specifies the load mode for the project output or image file.",
24002407
"enum": [ "image+symbols", "symbols", "image", "none" ]
2408+
},
2409+
"WestProjectType": {
2410+
"title": "west:",
2411+
"description": "Enable West build orchestration wrapper for Zephyr projects.",
2412+
"type": "object",
2413+
"properties": {
2414+
"app-path": { "type": "string", "description": "Path to the application source directory." },
2415+
"project-id": { "type": "string", "description": "Project identifier (default: last sub-dir name of app-path)." },
2416+
"board": { "type": "string", "description": "Board name used for west build invocation (default: variable $west-board$)."},
2417+
"device": { "$ref": "#/definitions/ProcessorNameType" },
2418+
"west-defs": { "$ref": "#/definitions/DefinesType" },
2419+
"west-opts": { "type": "string", "description": "Options for the west tool (default: empty)." }
2420+
},
2421+
"additionalProperties": false,
2422+
"required": ["app-path"]
24012423
}
24022424
}
24032425
}

tools/projmgr/src/ProjMgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ bool ProjMgr::PopulateContexts(void) {
487487
}
488488
// Check cproject separate folders and unique names
489489
const StrVec& cprojects = m_parser.GetCsolution().cprojects;
490-
if (!IsSolutionImageOnly() && cprojects.empty()) {
490+
if (!IsSolutionImageOnly() && cprojects.empty() && m_parser.GetCsolution().westApps.empty()) {
491491
ProjMgrLogger::Get().Error("projects not found", "", m_csolutionFile);
492492
return false;
493493
}

tools/projmgr/src/ProjMgrCbuild.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ProjMgrCbuild : public ProjMgrCbuildBase {
4040
void SetBooksNode(YAML::Node node, const std::vector<BookItem>& books, const std::string& dir);
4141
void SetDebugConfigNode(YAML::Node node, const ContextItem* context);
4242
void SetPLMStatus(YAML::Node node, const ContextItem* context, const string& file);
43+
void SetWestNode(YAML::Node node, const ContextItem* context);
4344
bool m_ignoreRteFileMissing;
4445
};
4546

@@ -85,11 +86,11 @@ void ProjMgrCbuild::SetContextNode(YAML::Node contextNode, const ContextItem* co
8586
}
8687
SetBooksNode(contextNode[YAML_DEVICE_BOOKS], context->deviceBooks, context->directories.cbuild);
8788
SetDebugConfigNode(contextNode[YAML_DBGCONF], context);
88-
if (!context->imageOnly) {
89+
if (!context->imageOnly && !context->westOn) {
8990
SetProcessorNode(contextNode[YAML_PROCESSOR], context->targetAttributes);
9091
}
9192
SetPacksNode(contextNode[YAML_PACKS], context);
92-
if (!context->imageOnly) {
93+
if (!context->imageOnly && !context->westOn) {
9394
SetControlsNode(contextNode, context, context->controls.processed);
9495
vector<string> defines;
9596
if (context->rteActiveTarget != nullptr) {
@@ -108,7 +109,14 @@ void ProjMgrCbuild::SetContextNode(YAML::Node contextNode, const ContextItem* co
108109
}
109110
}
110111
SetOutputDirsNode(contextNode[YAML_OUTPUTDIRS], context);
111-
SetOutputNode(contextNode[YAML_OUTPUT], context);
112+
}
113+
if (context->westOn) {
114+
string outDir = context->directories.outdir;
115+
RteFsUtils::NormalizePath(outDir, context->directories.cprj);
116+
SetNodeValue(contextNode[YAML_OUTPUTDIRS][YAML_OUTPUT_OUTDIR], FormatPath(outDir, context->directories.cbuild));
117+
}
118+
SetOutputNode(contextNode[YAML_OUTPUT], context);
119+
if (!context->imageOnly && !context->westOn) {
112120
SetComponentsNode(contextNode[YAML_COMPONENTS], context);
113121
SetApisNode(contextNode[YAML_APIS], context);
114122
SetGeneratorsNode(contextNode[YAML_GENERATORS], context);
@@ -117,6 +125,9 @@ void ProjMgrCbuild::SetContextNode(YAML::Node contextNode, const ContextItem* co
117125
SetConstructedFilesNode(contextNode[YAML_CONSTRUCTEDFILES], context);
118126
}
119127
SetLicenseInfoNode(contextNode[YAML_LICENSES], context);
128+
if (context->westOn) {
129+
SetWestNode(contextNode[YAML_WEST], context);
130+
}
120131
}
121132

122133
void ProjMgrCbuild::SetComponentsNode(YAML::Node node, const ContextItem* context) {
@@ -590,3 +601,12 @@ bool ProjMgrYamlEmitter::GenerateCbuild(ContextItem* context,
590601
context->needRebuild = NeedRebuild(filename, rootNode);
591602
return WriteFile(rootNode, filename, context->name);
592603
}
604+
605+
void ProjMgrCbuild::SetWestNode(YAML::Node node, const ContextItem* context) {
606+
SetNodeValue(node[YAML_PROJECT_ID], context->west.projectId);
607+
SetNodeValue(node[YAML_APP_PATH], FormatPath(context->west.app, context->directories.cbuild));
608+
SetNodeValue(node[YAML_BOARD], context->west.board);
609+
SetNodeValue(node[YAML_DEVICE], context->west.device);
610+
SetDefineNode(node[YAML_WEST_DEFS], context->west.westDefs);
611+
SetNodeValue(node[YAML_WEST_OPT], context->west.westOpt);
612+
}

tools/projmgr/src/ProjMgrCbuildIdx.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ProjMgrCbuildIdx::ProjMgrCbuildIdx(YAML::Node node,
3333
if (!processedContexts.empty()) {
3434
const auto& context = processedContexts.front();
3535
SetNodeValue(node[YAML_DESCRIPTION], context->csolution->description);
36-
if (!parser->GetCdefault().path.empty() && !context->imageOnly) {
36+
if (!parser->GetCdefault().path.empty() && !context->imageOnly && !context->westOn) {
3737
SetNodeValue(node[YAML_CDEFAULT], FormatPath(parser->GetCdefault().path, directory));
3838
}
3939
}
@@ -44,7 +44,14 @@ ProjMgrCbuildIdx::ProjMgrCbuildIdx(YAML::Node node,
4444
SetNodeValue(node[YAML_OUTPUT_TMPDIR], FormatPath(parser->GetCsolution().directories.tmpdir, directory));
4545

4646
// Image Only flag
47-
if (!processedContexts.empty() && processedContexts.front()->imageOnly) {
47+
bool imageOnlySolution = true;
48+
for (const auto& processedContext : processedContexts) {
49+
if (!processedContext->imageOnly) {
50+
imageOnlySolution = false;
51+
break;
52+
}
53+
}
54+
if (imageOnlySolution) {
4855
node[YAML_IMAGE_ONLY] = true;
4956
}
5057

@@ -134,6 +141,9 @@ ProjMgrCbuildIdx::ProjMgrCbuildIdx(YAML::Node node,
134141
const string& filename = context->directories.cprj + "/" + context->name + ".cbuild.yml";
135142
const string& relativeFilename = fs::relative(filename, directory, ec).generic_string();
136143
SetNodeValue(cbuildNode[YAML_CBUILD], relativeFilename);
144+
if (context->westOn) {
145+
cbuildNode[YAML_WEST] = true;
146+
}
137147
if (context->cproject) {
138148
if (!context->imageOnly) {
139149
SetNodeValue(cbuildNode[YAML_PROJECT], context->cproject->name);

tools/projmgr/src/ProjMgrUtils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,11 @@ const std::string ProjMgrUtils::NormalizeLineEndings(const std::string& in) {
498498
}
499499
return out;
500500
}
501+
502+
const std::string ProjMgrUtils::GetWestBoard(const std::string& board) {
503+
string westBoard = RteUtils::StripSuffix(RteUtils::StripPrefix(board, "::"));
504+
std::transform(westBoard.begin(), westBoard.end(), westBoard.begin(),
505+
[](unsigned char c) { return std::tolower(c); });
506+
std::replace(westBoard.begin(), westBoard.end(), '-', '_');
507+
return westBoard;
508+
}

0 commit comments

Comments
 (0)