Skip to content

Commit 8e15927

Browse files
grasci-armbrondani
andauthored
[projmgr] Preserve west groups in cbuild.yml (#1362) (#2290)
Co-authored-by: Daniel Brondani <[email protected]>
1 parent 257cb36 commit 8e15927

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

tools/projmgr/include/ProjMgrYamlEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ProjMgrYamlEmitter {
114114
bool CompareFile(const std::string& filename, const YAML::Node& rootNode);
115115
bool CompareNodes(const YAML::Node& lhs, const YAML::Node& rhs);
116116
bool NeedRebuild(const std::string& filename, const YAML::Node& rootNode);
117-
std::string EraseGeneratedByNode(const std::string& inStr);
117+
void CopyWestGroups(const std::string& filename, YAML::Node rootNode);
118118
};
119119

120120
#endif // PROJMGRYAMLEMITTER_H

tools/projmgr/src/ProjMgrCbuild.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ void ProjMgrCbuild::SetDefineNode(YAML::Node define, const vector<string>& vec)
570570
}
571571
}
572572

573+
void ProjMgrCbuild::SetWestNode(YAML::Node node, const ContextItem* context) {
574+
SetNodeValue(node[YAML_PROJECT_ID], context->west.projectId);
575+
SetNodeValue(node[YAML_APP_PATH], FormatPath(context->west.app, context->directories.cbuild));
576+
SetNodeValue(node[YAML_BOARD], context->west.board);
577+
SetNodeValue(node[YAML_DEVICE], context->west.device);
578+
SetDefineNode(node[YAML_WEST_DEFS], context->west.westDefs);
579+
SetNodeValue(node[YAML_WEST_OPT], context->west.westOpt);
580+
}
581+
573582
//-- ProjMgrYamlEmitter::GenerateCbuild -----------------------------------------------------------
574583
bool ProjMgrYamlEmitter::GenerateCbuild(ContextItem* context,
575584
const string& generatorId, const string& generatorPack, bool ignoreRteFileMissing)
@@ -596,17 +605,21 @@ bool ProjMgrYamlEmitter::GenerateCbuild(ContextItem* context,
596605
}
597606
YAML::Node rootNode;
598607
ProjMgrCbuild cbuild(rootNode[rootKey], context, generatorId, generatorPack, ignoreRteFileMissing);
608+
if (context->westOn) {
609+
CopyWestGroups(filename, rootNode);
610+
}
599611
RteFsUtils::CreateDirectories(RteFsUtils::ParentPath(filename));
600612
// get context rebuild flag
601613
context->needRebuild = NeedRebuild(filename, rootNode);
602614
return WriteFile(rootNode, filename, context->name);
603615
}
604616

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);
617+
void ProjMgrYamlEmitter::CopyWestGroups(const string& filename, YAML::Node rootNode) {
618+
if (!RteFsUtils::Exists(filename) || !RteFsUtils::IsRegularFile(filename)) {
619+
return;
620+
}
621+
const YAML::Node& cbuildFile = YAML::LoadFile(filename);
622+
if (cbuildFile[YAML_BUILD][YAML_GROUPS].IsDefined()) {
623+
rootNode[YAML_BUILD][YAML_GROUPS] = cbuildFile[YAML_BUILD][YAML_GROUPS];
624+
}
612625
}

tools/projmgr/src/ProjMgrYamlEmitter.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,15 @@ bool ProjMgrYamlEmitter::WriteFile(YAML::Node& rootNode, const std::string& file
8787
return true;
8888
}
8989

90-
string ProjMgrYamlEmitter::EraseGeneratedByNode(const string& inStr) {
91-
size_t startIndex, endIndex;
92-
string outStr = inStr;
93-
startIndex = outStr.find(YAML_GENERATED_BY, 0);
94-
endIndex = outStr.find('\n', startIndex);
95-
if (startIndex != std::string::npos && endIndex != std::string::npos) {
96-
outStr = outStr.erase(startIndex, endIndex - startIndex);
97-
}
98-
return outStr;
99-
};
100-
10190
bool ProjMgrYamlEmitter::CompareFile(const string& filename, const YAML::Node& rootNode) {
10291
string inBuffer;
10392
if (!RteFsUtils::Exists(filename) || !RteFsUtils::ReadFile(filename, inBuffer)) {
10493
return false;
10594
}
10695
YAML::Emitter emitter;
10796
const auto& outBuffer = string((emitter << rootNode).c_str()) + '\n';
108-
return ProjMgrUtils::NormalizeLineEndings(EraseGeneratedByNode(inBuffer)) ==
109-
ProjMgrUtils::NormalizeLineEndings(EraseGeneratedByNode(outBuffer));
97+
return ProjMgrUtils::NormalizeLineEndings(inBuffer) ==
98+
ProjMgrUtils::NormalizeLineEndings(outBuffer);
11099
}
111100

112101
bool ProjMgrYamlEmitter::CompareNodes(const YAML::Node& lhs, const YAML::Node& rhs) {
@@ -118,8 +107,8 @@ bool ProjMgrYamlEmitter::CompareNodes(const YAML::Node& lhs, const YAML::Node& r
118107
rhsEmitter << rhs;
119108

120109
// remove generated-by node from the string
121-
lhsData = EraseGeneratedByNode(lhsEmitter.c_str());
122-
rhsData = EraseGeneratedByNode(rhsEmitter.c_str());
110+
lhsData = lhsEmitter.c_str();
111+
rhsData = rhsEmitter.c_str();
123112

124113
return (lhsData == rhsData) ? true : false;
125114
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build:
2+
groups:
3+
- group: sources
4+
files:
5+
- file: ../../../../src/main.c
6+
- group: zephyr
7+
files:
8+
- file: ../../../../zephyr/utils.c

tools/projmgr/test/data/WestSupport/ref/core0.Debug+CM0.cbuild.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ build:
3838
- CONFIG_BUILD_OUTPUT_HEX: y
3939
- TARGET-DEF: on
4040
- CONFIG-DEBUG: y
41+
groups:
42+
- group: sources
43+
files:
44+
- file: ../../../../src/main.c
45+
- group: zephyr
46+
files:
47+
- file: ../../../../zephyr/utils.c

0 commit comments

Comments
 (0)