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

Add option to packchk to fail if warning/info violations are detected #886 (#583) #948

Merged
merged 1 commit into from
May 31, 2023
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
5 changes: 5 additions & 0 deletions tools/packchk/include/PackOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ class CPackOptions {
CPackOptions();
~CPackOptions();

enum class PedanticLevel { NONE = 0, WARNING, INFO };


bool SetWarnLevel(const uint32_t warnLevel);
bool SetPedantic(const PedanticLevel pedanticLevel);
PedanticLevel GetPedantic();
bool SetLogFile(const std::string& m_logFile);
bool SetXsdFile();
bool SetXsdFile(const std::string& m_xsdFile);
Expand Down Expand Up @@ -54,6 +58,7 @@ class CPackOptions {
private:
bool m_bIgnoreOtherPdscFiles;
bool m_bDisableValidation;
PedanticLevel m_pedanticLevel;

std::string m_urlRef; // package URL reference, check the URL of the PDSC against this value. if not std::set it is compared against the Keil Pack Server URL
std::string m_packNamePath;
Expand Down
1 change: 1 addition & 0 deletions tools/packchk/include/ParseOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ParseOptions {

protected:
bool SetWarnLevel(const std::string& warnLevel);
bool SetPedantic(const std::string& pedanticLevel);
bool SetTestPdscFile(const std::string& filename);
bool SetLogFile(const std::string& m_logFile);
bool SetXsdFile();
Expand Down
7 changes: 7 additions & 0 deletions tools/packchk/src/PackChk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,12 @@ int PackChk::Check(int argc, const char* argv[], const char* envp[])
return 1;
}

CPackOptions::PedanticLevel pedantic = m_packOptions.GetPedantic();
if(pedantic != CPackOptions::PedanticLevel::NONE) {
if(ErrLog::Get()->GetWarnCnt()) {
return 1;
}
}

return 0;
}
26 changes: 25 additions & 1 deletion tools/packchk/src/PackOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ using namespace std;
*/
CPackOptions::CPackOptions() :
m_bIgnoreOtherPdscFiles(false),
m_bDisableValidation(false)
m_bDisableValidation(false),
m_pedanticLevel(PedanticLevel::NONE)
{
}

Expand Down Expand Up @@ -452,6 +453,29 @@ bool CPackOptions::SetWarnLevel(const uint32_t warnLevel)
return true;
}


/**
* @brief set the pedantic level to return with error flag
* @param warnLevel PEDANTIC_LEVEL pedantic level
* @return passed / failed
*/
bool CPackOptions::SetPedantic(const PedanticLevel pedanticLevel)
{
m_pedanticLevel = pedanticLevel;

return true;
}

/**
* @brief get the pedantic level to return with error flag
* @param none
* @return level
*/
CPackOptions::PedanticLevel CPackOptions::GetPedantic()
{
return m_pedanticLevel;
}

/**
* @brief enabled verbose output (processing messages)
* @param bVerbose true/false
Expand Down
20 changes: 20 additions & 0 deletions tools/packchk/src/ParseOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ bool ParseOptions::SetWarnLevel(const string& warnLevel)
return m_packOptions.SetWarnLevel(level);
}

bool ParseOptions::SetPedantic(const string& pedanticLevel)
{
if(pedanticLevel.empty() || pedanticLevel == "info") {
return m_packOptions.SetPedantic(CPackOptions::PedanticLevel::INFO);
}
else if(pedanticLevel == "warning") {
return m_packOptions.SetPedantic(CPackOptions::PedanticLevel::WARNING);
}
else {
return false;
}
}

/**
* @brief option "v,verbose"
* @param bVerbose set verbose mode
Expand Down Expand Up @@ -208,6 +221,7 @@ ParseOptions::Result ParseOptions::Parse(int argc, const char* argv[])
{"allow-suppress-error", "Allow to suppress error messages", cxxopts::value<bool>()->default_value("false")},
{"break", "Debug halt after start", cxxopts::value<bool>()->default_value("false")},
{"ignore-other-pdsc", "Ignores other PDSC files in working folder", cxxopts::value<bool>()->default_value("false")},
{"pedantic", "Return with error value on warning", cxxopts::value<bool>()->default_value("false")},
});

options.parse_positional({"input"});
Expand Down Expand Up @@ -284,6 +298,12 @@ ParseOptions::Result ParseOptions::Parse(int argc, const char* argv[])
}
}

if(parseResult.count("pedantic")) {
if(!SetPedantic("warning")) {
bOk = false;
}
}

if(parseResult.count("n")) {
if(!SetPackNamePath(parseResult["n"].as<string>())) {
bOk = false;
Expand Down