Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projmgr] Add --frozen-packs argument to csolution #1225

Merged
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
6 changes: 5 additions & 1 deletion libs/rtemodel/src/RteProject.cpp
Torbjorn-Svensson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,18 @@ void RteProject::AddCprjComponents(const Collection<RteItem*>& selItems, RteTarg
// update file versions
for (auto [instanceName, fi] : m_files) {
string version;
auto rteFile = fi->GetFile(target->GetName());
auto itver = configFileVersions.find(instanceName); // file in cprj can be specified by its instance name
if (itver == configFileVersions.end())
itver = configFileVersions.find(fi->GetName()); // or by original name
if (itver != configFileVersions.end()) {
version = itver->second;
} else {
// Fall back to the version noted in the pack
version = rteFile->GetVersionString();
brondani marked this conversation as resolved.
Show resolved Hide resolved
}
UpdateFileInstanceVersion(fi, version);
UpdateConfigFileBackups(fi, fi->GetFile(target->GetName()));
UpdateConfigFileBackups(fi, rteFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Intentionally left empty to trigger upgrade scenario in test case */
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class ProjMgr {
bool m_ymlOrder;
bool m_contextSet;
bool m_relativePaths;
bool m_frozenPacks;
GroupNode m_files;
std::vector<ContextItem*> m_processedContexts;

Expand Down
3 changes: 2 additions & 1 deletion tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,9 @@ class ProjMgrParser {
* @brief parse csolution
* @param checkSchema false to skip schema validation
* @param input csolution.yml file
* @param frozenPacks false to allow missing cbuild-packs.yml file
*/
bool ParseCsolution(const std::string& input, bool checkSchema);
bool ParseCsolution(const std::string& input, bool checkSchema, bool frozenPacks);

/**
* @brief parse clayer
Expand Down
3 changes: 2 additions & 1 deletion tools/projmgr/include/ProjMgrYamlEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ class ProjMgrYamlEmitter {
* @brief generate cbuild pack file
* @param contexts vector with pointers to contexts
* @param keepExistingPackContent if true, all entries from existing cbuild-pack should be preserved
* @param cbuildPackFrozen if true, reject updates to cbuild pack file
* @return true if executed successfully
*/
static bool GenerateCbuildPack(ProjMgrParser& parser, const std::vector<ContextItem*> contexts, bool keepExistingPackContent);
static bool GenerateCbuildPack(ProjMgrParser& parser, const std::vector<ContextItem*> contexts, bool keepExistingPackContent, bool cbuildPackFrozen);
};

#endif // PROJMGRYAMLEMITTER_H
3 changes: 2 additions & 1 deletion tools/projmgr/include/ProjMgrYamlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ class ProjMgrYamlParser {
* @param input csolution.yml file
* @param reference to store parsed csolution item
* @param checkSchema false to skip schema validation
* @param frozenPacks false to allow missing cbuild-packs.yml file
*/
bool ParseCsolution(const std::string& input, CsolutionItem& csolution,
bool checkSchema);
bool checkSchema, bool frozenPacks);

/**
* @brief parse cproject
Expand Down
28 changes: 20 additions & 8 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ ProjMgr::ProjMgr() :
m_dryRun(false),
m_ymlOrder(false),
m_contextSet(false),
m_relativePaths(false)
m_relativePaths(false),
m_frozenPacks(false)
{
}

Expand Down Expand Up @@ -151,12 +152,13 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
cxxopts::Option ymlOrder("yml-order", "Preserve order as specified in input yml", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option contextSet("S,context-set", "Use context set", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option relativePaths("R,relative-paths", "Output paths relative to project or to CMSIS_PACK_ROOT", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option frozenPacks("frozen-packs", "The list of packs from cbuild-pack.yml is frozen and raises error if not up-to-date", cxxopts::value<bool>()->default_value("false"));

// command options dictionary
map<string, std::pair<bool, vector<cxxopts::Option>>> optionsDict = {
// command, optional args, options
{"update-rte", { false, {context, contextSet, debug, load, schemaCheck, toolchain, verbose}}},
{"convert", { false, {context, contextSet, debug, exportSuffix, load, schemaCheck, noUpdateRte, output, toolchain, verbose}}},
{"update-rte", { false, {context, contextSet, debug, load, schemaCheck, toolchain, verbose, frozenPacks}}},
{"convert", { false, {context, contextSet, debug, exportSuffix, load, schemaCheck, noUpdateRte, output, toolchain, verbose, frozenPacks}}},
{"run", { false, {context, debug, generator, load, schemaCheck, verbose, dryRun}}},
{"list packs", { true, {context, debug, filter, load, missing, schemaCheck, toolchain, verbose, relativePaths}}},
{"list boards", { true, {context, debug, filter, load, schemaCheck, toolchain, verbose}}},
Expand All @@ -176,7 +178,7 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
{"positional", "", cxxopts::value<vector<string>>()},
solution, context, contextSet, filter, generator,
load, clayerSearchPath, missing, schemaCheck, noUpdateRte, output,
help, version, verbose, debug, dryRun, exportSuffix, toolchain, ymlOrder, relativePaths
help, version, verbose, debug, dryRun, exportSuffix, toolchain, ymlOrder, relativePaths, frozenPacks
});
options.parse_positional({ "positional" });

Expand All @@ -196,6 +198,7 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
m_contextSet = parseResult.count("context-set");
m_relativePaths = parseResult.count("relative-paths");
m_worker.SetPrintRelativePaths(m_relativePaths);
m_frozenPacks = parseResult.count("frozen-packs");

vector<string> positionalArguments;
if (parseResult.count("positional")) {
Expand Down Expand Up @@ -398,7 +401,7 @@ bool ProjMgr::SetLoadPacksPolicy(void) {
bool ProjMgr::PopulateContexts(void) {
if (!m_csolutionFile.empty()) {
// Parse csolution
if (!m_parser.ParseCsolution(m_csolutionFile, m_checkSchema)) {
if (!m_parser.ParseCsolution(m_csolutionFile, m_checkSchema, m_frozenPacks)) {
return false;
}
// Parse cdefault
Expand Down Expand Up @@ -502,7 +505,7 @@ bool ProjMgr::RunConfigure(bool printConfig) {
if (!m_worker.IsContextSelected(contextName)) {
continue;
}
if (!m_worker.ProcessContext(contextItem, true, true, m_updateRteFiles)) {
if (!m_worker.ProcessContext(contextItem, true, true, false)) {
ProjMgrLogger::Error("processing context '" + contextName + "' failed");
error = true;
} else {
Expand Down Expand Up @@ -552,12 +555,21 @@ bool ProjMgr::RunConfigure(bool printConfig) {
if (!m_emitter.GenerateCbuild(contextItem)) {
return false;
}

}

// Generate cbuild-pack file
const bool isUsingContexts = m_contextSet || m_context.size() != 0;
m_emitter.GenerateCbuildPack(m_parser, m_processedContexts, isUsingContexts);
if (!m_emitter.GenerateCbuildPack(m_parser, m_processedContexts, isUsingContexts, m_frozenPacks)) {
return false;
}

// Update the RTE files
if (m_updateRteFiles) {
for (auto& contextItem : m_processedContexts) {
contextItem->rteActiveProject->SetAttribute("update-rte-files", "1");
contextItem->rteActiveProject->UpdateRte();
}
}

return !error;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/projmgr/src/ProjMgrParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ bool ProjMgrParser::ParseCdefault(const string& input, bool checkSchema) {
return ProjMgrYamlParser().ParseCdefault(input, m_cdefault, checkSchema);
}

bool ProjMgrParser::ParseCsolution(const string& input, bool checkSchema) {
bool ProjMgrParser::ParseCsolution(const string& input, bool checkSchema, bool frozenPacks) {
// Parse solution file
return ProjMgrYamlParser().ParseCsolution(input, m_csolution, checkSchema);
return ProjMgrYamlParser().ParseCsolution(input, m_csolution, checkSchema, frozenPacks);
}

bool ProjMgrParser::ParseCproject(const string& input, bool checkSchema, bool single) {
Expand Down
12 changes: 8 additions & 4 deletions tools/projmgr/src/ProjMgrYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ProjMgrYamlBase {
const string FormatPath(const string& original, const string& directory);
bool CompareFile(const string& filename, const YAML::Node& rootNode);
bool CompareNodes(const YAML::Node& lhs, const YAML::Node& rhs);
bool WriteFile(YAML::Node& rootNode, const std::string& filename);
bool WriteFile(YAML::Node& rootNode, const std::string& filename, bool allowUpdate = true);
const bool m_useAbsolutePaths;
};

Expand Down Expand Up @@ -705,7 +705,7 @@ bool ProjMgrYamlBase::CompareNodes(const YAML::Node& lhs, const YAML::Node& rhs)
return (lhsData == rhsData) ? true : false;
}

bool ProjMgrYamlBase::WriteFile(YAML::Node& rootNode, const std::string& filename) {
bool ProjMgrYamlBase::WriteFile(YAML::Node& rootNode, const std::string& filename, bool allowUpdate) {
// Compare yaml contents
if (RteFsUtils::IsDirectory(filename)) {
ProjMgrLogger::Error(filename, "file cannot be written");
Expand All @@ -721,6 +721,10 @@ bool ProjMgrYamlBase::WriteFile(YAML::Node& rootNode, const std::string& filenam
}
}
else if (!CompareFile(filename, rootNode)) {
if (!allowUpdate) {
ProjMgrLogger::Error(filename, "file not allowed to be updated");
Torbjorn-Svensson marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
if (!RteFsUtils::MakeSureFilePath(filename)) {
ProjMgrLogger::Error(filename, "destination directory can not be created");
return false;
Expand Down Expand Up @@ -829,12 +833,12 @@ bool ProjMgrYamlEmitter::GenerateCbuildGenIndex(ProjMgrParser& parser, const vec
return cbuild.WriteFile(rootNode, filename);
}

bool ProjMgrYamlEmitter::GenerateCbuildPack(ProjMgrParser& parser, const vector<ContextItem*> contexts, bool keepExistingPackContent) {
bool ProjMgrYamlEmitter::GenerateCbuildPack(ProjMgrParser& parser, const vector<ContextItem*> contexts, bool keepExistingPackContent, bool cbuildPackFrozen) {
// generate cbuild-pack.yml
const string& filename = parser.GetCsolution().directory + "/" + parser.GetCsolution().name + ".cbuild-pack.yml";

YAML::Node rootNode;
ProjMgrYamlCbuildPack cbuildPack(rootNode[YAML_CBUILD_PACK], contexts, parser, keepExistingPackContent);

return cbuildPack.WriteFile(rootNode, filename);
return cbuildPack.WriteFile(rootNode, filename, !cbuildPackFrozen);
}
5 changes: 4 additions & 1 deletion tools/projmgr/src/ProjMgrYamlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ bool ProjMgrYamlParser::ParseCdefault(const string& input,
}

bool ProjMgrYamlParser::ParseCsolution(const string& input,
CsolutionItem& csolution, bool checkSchema) {
CsolutionItem& csolution, bool checkSchema, bool frozenPacks) {

string cbuildPackFile = RteUtils::RemoveSuffixByString(input, ".csolution.yml") + ".cbuild-pack.yml";
if (fs::exists(cbuildPackFile)) {
if (!ParseCbuildPack(cbuildPackFile, csolution.cbuildPack, checkSchema)) {
return false;
}
} else if (frozenPacks) {
ProjMgrLogger::Error(cbuildPackFile, "file is missing and required due to use of --frozen-packs option");
return false;
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cbuild-pack:
resolved-packs:
- resolved-pack: ARM::[email protected]
selected-by:
- ARM::RteTest_DFP
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
target-types:
- type: CM3
device: RteTest_ARMCM3
packs:
- pack: ARM::[email protected]
projects:
- project: ./project_with_dfp_components.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
target-types:
- type: CM0
device: RteTest_ARMCM0
packs:
- pack: ARM::[email protected]
projects:
- project: ./project_with_dfp_components.cproject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cbuild-pack:
resolved-packs:
- resolved-pack: ARM::[email protected]
selected-by:
- ARM::[email protected]
Loading
Loading