diff --git a/tools/projmgr/include/ProjMgrYamlEmitter.h b/tools/projmgr/include/ProjMgrYamlEmitter.h index d07b3e238..f8d99f406 100644 --- a/tools/projmgr/include/ProjMgrYamlEmitter.h +++ b/tools/projmgr/include/ProjMgrYamlEmitter.h @@ -114,7 +114,7 @@ class ProjMgrYamlEmitter { bool CompareFile(const std::string& filename, const YAML::Node& rootNode); bool CompareNodes(const YAML::Node& lhs, const YAML::Node& rhs); bool NeedRebuild(const std::string& filename, const YAML::Node& rootNode); - std::string EraseGeneratedByNode(const std::string& inStr); + void CopyWestGroups(const std::string& filename, YAML::Node rootNode); }; #endif // PROJMGRYAMLEMITTER_H diff --git a/tools/projmgr/src/ProjMgrCbuild.cpp b/tools/projmgr/src/ProjMgrCbuild.cpp index 6b0c96594..77ea93f60 100644 --- a/tools/projmgr/src/ProjMgrCbuild.cpp +++ b/tools/projmgr/src/ProjMgrCbuild.cpp @@ -570,6 +570,15 @@ void ProjMgrCbuild::SetDefineNode(YAML::Node define, const vector& vec) } } +void ProjMgrCbuild::SetWestNode(YAML::Node node, const ContextItem* context) { + SetNodeValue(node[YAML_PROJECT_ID], context->west.projectId); + SetNodeValue(node[YAML_APP_PATH], FormatPath(context->west.app, context->directories.cbuild)); + SetNodeValue(node[YAML_BOARD], context->west.board); + SetNodeValue(node[YAML_DEVICE], context->west.device); + SetDefineNode(node[YAML_WEST_DEFS], context->west.westDefs); + SetNodeValue(node[YAML_WEST_OPT], context->west.westOpt); +} + //-- ProjMgrYamlEmitter::GenerateCbuild ----------------------------------------------------------- bool ProjMgrYamlEmitter::GenerateCbuild(ContextItem* context, const string& generatorId, const string& generatorPack, bool ignoreRteFileMissing) @@ -596,17 +605,21 @@ bool ProjMgrYamlEmitter::GenerateCbuild(ContextItem* context, } YAML::Node rootNode; ProjMgrCbuild cbuild(rootNode[rootKey], context, generatorId, generatorPack, ignoreRteFileMissing); + if (context->westOn) { + CopyWestGroups(filename, rootNode); + } RteFsUtils::CreateDirectories(RteFsUtils::ParentPath(filename)); // get context rebuild flag context->needRebuild = NeedRebuild(filename, rootNode); return WriteFile(rootNode, filename, context->name); } -void ProjMgrCbuild::SetWestNode(YAML::Node node, const ContextItem* context) { - SetNodeValue(node[YAML_PROJECT_ID], context->west.projectId); - SetNodeValue(node[YAML_APP_PATH], FormatPath(context->west.app, context->directories.cbuild)); - SetNodeValue(node[YAML_BOARD], context->west.board); - SetNodeValue(node[YAML_DEVICE], context->west.device); - SetDefineNode(node[YAML_WEST_DEFS], context->west.westDefs); - SetNodeValue(node[YAML_WEST_OPT], context->west.westOpt); +void ProjMgrYamlEmitter::CopyWestGroups(const string& filename, YAML::Node rootNode) { + if (!RteFsUtils::Exists(filename) || !RteFsUtils::IsRegularFile(filename)) { + return; + } + const YAML::Node& cbuildFile = YAML::LoadFile(filename); + if (cbuildFile[YAML_BUILD][YAML_GROUPS].IsDefined()) { + rootNode[YAML_BUILD][YAML_GROUPS] = cbuildFile[YAML_BUILD][YAML_GROUPS]; + } } diff --git a/tools/projmgr/src/ProjMgrYamlEmitter.cpp b/tools/projmgr/src/ProjMgrYamlEmitter.cpp index 52baaac57..3c20ff202 100644 --- a/tools/projmgr/src/ProjMgrYamlEmitter.cpp +++ b/tools/projmgr/src/ProjMgrYamlEmitter.cpp @@ -87,17 +87,6 @@ bool ProjMgrYamlEmitter::WriteFile(YAML::Node& rootNode, const std::string& file return true; } -string ProjMgrYamlEmitter::EraseGeneratedByNode(const string& inStr) { - size_t startIndex, endIndex; - string outStr = inStr; - startIndex = outStr.find(YAML_GENERATED_BY, 0); - endIndex = outStr.find('\n', startIndex); - if (startIndex != std::string::npos && endIndex != std::string::npos) { - outStr = outStr.erase(startIndex, endIndex - startIndex); - } - return outStr; -}; - bool ProjMgrYamlEmitter::CompareFile(const string& filename, const YAML::Node& rootNode) { string inBuffer; if (!RteFsUtils::Exists(filename) || !RteFsUtils::ReadFile(filename, inBuffer)) { @@ -105,8 +94,8 @@ bool ProjMgrYamlEmitter::CompareFile(const string& filename, const YAML::Node& r } YAML::Emitter emitter; const auto& outBuffer = string((emitter << rootNode).c_str()) + '\n'; - return ProjMgrUtils::NormalizeLineEndings(EraseGeneratedByNode(inBuffer)) == - ProjMgrUtils::NormalizeLineEndings(EraseGeneratedByNode(outBuffer)); + return ProjMgrUtils::NormalizeLineEndings(inBuffer) == + ProjMgrUtils::NormalizeLineEndings(outBuffer); } 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 rhsEmitter << rhs; // remove generated-by node from the string - lhsData = EraseGeneratedByNode(lhsEmitter.c_str()); - rhsData = EraseGeneratedByNode(rhsEmitter.c_str()); + lhsData = lhsEmitter.c_str(); + rhsData = rhsEmitter.c_str(); return (lhsData == rhsData) ? true : false; } diff --git a/tools/projmgr/test/data/WestSupport/out/core0/CM0/Debug/core0.Debug+CM0.cbuild.yml b/tools/projmgr/test/data/WestSupport/out/core0/CM0/Debug/core0.Debug+CM0.cbuild.yml new file mode 100644 index 000000000..7e3f491dc --- /dev/null +++ b/tools/projmgr/test/data/WestSupport/out/core0/CM0/Debug/core0.Debug+CM0.cbuild.yml @@ -0,0 +1,8 @@ +build: + groups: + - group: sources + files: + - file: ../../../../src/main.c + - group: zephyr + files: + - file: ../../../../zephyr/utils.c diff --git a/tools/projmgr/test/data/WestSupport/ref/core0.Debug+CM0.cbuild.yml b/tools/projmgr/test/data/WestSupport/ref/core0.Debug+CM0.cbuild.yml index 27b032d6d..df1563be8 100644 --- a/tools/projmgr/test/data/WestSupport/ref/core0.Debug+CM0.cbuild.yml +++ b/tools/projmgr/test/data/WestSupport/ref/core0.Debug+CM0.cbuild.yml @@ -38,3 +38,10 @@ build: - CONFIG_BUILD_OUTPUT_HEX: y - TARGET-DEF: on - CONFIG-DEBUG: y + groups: + - group: sources + files: + - file: ../../../../src/main.c + - group: zephyr + files: + - file: ../../../../zephyr/utils.c