Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/projmgr/include/ProjMgrYamlEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 20 additions & 7 deletions tools/projmgr/src/ProjMgrCbuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,15 @@ void ProjMgrCbuild::SetDefineNode(YAML::Node define, const vector<string>& 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)
Expand All @@ -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];
}
}
19 changes: 4 additions & 15 deletions tools/projmgr/src/ProjMgrYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,15 @@ 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)) {
return false;
}
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) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
groups:
- group: sources
files:
- file: ../../../../src/main.c
- group: zephyr
files:
- file: ../../../../zephyr/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading