fixed #11917 (Default to `native` platform in Windows builds) (#5428)

This commit is contained in:
Oliver Stöneberg 2023-09-11 11:08:23 +02:00 committed by GitHub
parent fe46bd3f96
commit 64cd09ab62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 103 deletions

View File

@ -125,18 +125,10 @@ void CmdLineParser::printError(const std::string &message)
printMessage("error: " + message);
}
#if defined(_WIN64) || defined(_WIN32)
bool CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
#endif
// TODO: normalize/simplify/native all path parameters
// TODO: error out on all missing given files/paths
bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
{
#if defined(_WIN64) || defined(_WIN32)
bool default_platform = true;
#endif
bool def = false;
bool maxconfigs = false;
@ -632,10 +624,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
return false;
}
#if defined(_WIN64) || defined(_WIN32)
default_platform = false;
#endif
// TODO: remove
// these are loaded via external files and thus have Settings::PlatformFile set instead.
// override the type so they behave like the regular platforms.
@ -1057,14 +1045,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
return true;
}
#if defined(_WIN64)
if (SHOW_DEF_PLATFORM_MSG && default_platform && !mSettings.quiet)
printMessage("Windows 64-bit binaries currently default to the 'win64' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win64' explicitly if you rely on this.");
#elif defined(_WIN32)
if (SHOW_DEF_PLATFORM_MSG && default_platform && !mSettings.quiet)
printMessage("Windows 32-bit binaries currently default to the 'win32A' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32A' explicitly if you rely on this.");
#endif
// Print error only if we have "real" command and expect files
if (!mExitAfterPrint && mPathNames.empty() && mSettings.project.fileSettings.empty()) {
printError("no C or C++ source files found.");

View File

@ -99,11 +99,6 @@ public:
return mIgnoredPaths;
}
#if defined(_WIN64) || defined(_WIN32)
// temporary variable to "un-break" tests
static bool SHOW_DEF_PLATFORM_MSG;
#endif
protected:
/**

View File

@ -29,14 +29,7 @@
cppcheck::Platform::Platform()
{
// This assumes the code you are checking is for the same architecture this is compiled on.
#if defined(_WIN64)
set(Type::Win64);
#elif defined(_WIN32)
set(Type::Win32A);
#else
set(Type::Native);
#endif
}

View File

@ -13,4 +13,4 @@ Changed interface:
-
Other:
-
- Windows builds now default to the `native` platform instead of `win32A` or `win64`. Please specify it explicitly if you depedent on it.

View File

@ -78,7 +78,7 @@ def test_addon_absolute_path():
def test_addon_relative_path():
prjpath = getRelativeProjectPath()
ret, stdout, stderr = cppcheck(['--platform=native', '--addon=misra', '--enable=style', '--template=cppcheck1', prjpath])
ret, stdout, stderr = cppcheck(['--addon=misra', '--enable=style', '--template=cppcheck1', prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0, stdout
assert stdout == ('Checking %s ...\n'
@ -89,7 +89,7 @@ def test_addon_relative_path():
def test_addon_with_gui_project():
project_file = 'helloworld/test.cppcheck'
create_gui_project_file(project_file, paths=['.'], addon='misra')
ret, stdout, stderr = cppcheck(['--platform=native', '--template=cppcheck1', '--enable=style', '--project=' + project_file])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--enable=style', '--project=' + project_file])
filename = os.path.join('helloworld', 'main.c')
assert ret == 0, stdout
assert stdout == 'Checking %s ...\n' % filename

View File

@ -74,7 +74,7 @@ def test_project_custom_platform(tmpdir):
with open(os.path.join(tmpdir, '1.c'), 'wt') as f:
f.write("int x;")
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1', '-q'])
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1', '-q'])
assert ret == 0, stdout
assert stdout == ''
assert stderr == ''
@ -89,7 +89,7 @@ def test_project_empty_platform(tmpdir):
with open(os.path.join(tmpdir, '1.c'), 'wt') as f:
f.write("int x;")
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1', '-q'])
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1', '-q'])
assert ret == 0, stdout
assert stdout == ''
assert stderr == ''
@ -104,7 +104,7 @@ def test_project_unspecified_platform(tmpdir):
with open(os.path.join(tmpdir, '1.c'), 'wt') as f:
f.write("int x;")
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1', '-q'])
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1', '-q'])
assert ret == 0, stdout
assert stdout == "cppcheck: 'Unspecified' is a deprecated platform type and will be removed in Cppcheck 2.14. Please use 'unspecified' instead.\n"
assert stderr == ''
@ -209,7 +209,7 @@ def test_project_empty_fields(tmpdir):
</coding-standards>
</project>""")
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1'])
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1'])
assert ret == 1, stdout # do not crash
assert stdout == 'cppcheck: error: no C or C++ source files found.\n'
assert stderr == ''

View File

@ -71,7 +71,7 @@ def test_missing_include_inline_suppr(tmpdir):
def test_invalid_library(tmpdir):
args = ['--library=none', '--library=posix', '--library=none2', '--platform=native', 'file.c']
args = ['--library=none', '--library=posix', '--library=none2', 'file.c']
exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 1
@ -85,7 +85,7 @@ def test_message_j(tmpdir):
with open(test_file, 'wt') as f:
f.write("")
args = ['-j2', '--platform=native', test_file]
args = ['-j2', test_file]
_, stdout, _ = cppcheck(args)
assert stdout == "Checking {} ...\n".format(test_file) # we were adding stray \0 characters at the end
@ -102,7 +102,7 @@ def test_progress(tmpdir):
}
""")
args = ['--report-progress=0', '--enable=all', '--inconclusive', '--platform=native', test_file]
args = ['--report-progress=0', '--enable=all', '--inconclusive', test_file]
exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
@ -135,7 +135,7 @@ def test_progress_j(tmpdir):
}
""")
args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j2', '--disable=unusedFunction', '--platform=native', test_file]
args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j2', '--disable=unusedFunction', test_file]
exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0

View File

@ -421,9 +421,8 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::platform(cppcheck::P
{
const std::string platformStr = cppcheck::Platform::toString(type);
// TODO: the default platform differs between Windows and Linux
//if (REDUNDANT_CHECK && settings.platform.type == type)
// throw std::runtime_error("redundant setting: platform (" + platformStr + ")");
if (REDUNDANT_CHECK && settings.platform.type == type)
throw std::runtime_error("redundant setting: platform (" + platformStr + ")");
std::string errstr;
// TODO: exename is not yet set

View File

@ -40,17 +40,7 @@
class TestCmdlineParser : public TestFixture {
public:
TestCmdlineParser() : TestFixture("TestCmdlineParser")
{
#if defined(_WIN64) || defined(_WIN32)
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
#endif
}
~TestCmdlineParser() override {
#if defined(_WIN64) || defined(_WIN32)
CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
#endif
}
{}
private:
std::unique_ptr<Settings> settings;
@ -169,10 +159,6 @@ private:
TEST_CASE(platformUnspecified);
TEST_CASE(platformPlatformFile);
TEST_CASE(platformUnknown);
#if defined(_WIN64) || defined(_WIN32)
TEST_CASE(platformDefault);
TEST_CASE(platformDefault2);
#endif
TEST_CASE(plistEmpty);
TEST_CASE(plistDoesNotExist);
TEST_CASE(suppressionsOld);
@ -1237,39 +1223,6 @@ private:
ASSERT_EQUALS("cppcheck: error: unrecognized platform: 'win128'.\n", GET_REDIRECT_OUTPUT);
}
#if defined(_WIN64) || defined(_WIN32)
void platformDefault() {
REDIRECT;
CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
const char * const argv[] = {"cppcheck", "file.cpp"};
ASSERT(parser->parseFromArgs(2, argv));
#if defined(_WIN64)
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, settings->platform.type);
ASSERT_EQUALS("cppcheck: Windows 64-bit binaries currently default to the 'win64' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win64' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
#elif defined(_WIN32)
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings->platform.type);
ASSERT_EQUALS("cppcheck: Windows 32-bit binaries currently default to the 'win32A' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32A' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
#endif
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
}
void platformDefault2() {
REDIRECT;
CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
const char * const argv[] = {"cppcheck", "--platform=unix64", "file.cpp"};
ASSERT(parser->parseFromArgs(3, argv));
ASSERT_EQUALS(cppcheck::Platform::Type::Unix64, settings->platform.type);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
}
#endif
void plistEmpty() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--plist-output=", "file.cpp"};

View File

@ -38,8 +38,8 @@ public:
TestCondition() : TestFixture("TestCondition") {}
private:
const Settings settings0 = settingsBuilder().library("qt.cfg").library("std.cfg").severity(Severity::style).severity(Severity::warning).platform(cppcheck::Platform::Type::Native).build();
Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).platform(cppcheck::Platform::Type::Native).build();
const Settings settings0 = settingsBuilder().library("qt.cfg").library("std.cfg").severity(Severity::style).severity(Severity::warning).build();
Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
void run() override {
const char cfg[] = "<?xml version=\"1.0\"?>\n"

View File

@ -388,15 +388,9 @@ private:
ASSERT(!readPlatform(platform, xmldata));
}
void default_platform() {
void default_platform() const {
cppcheck::Platform platform;
#if defined(_WIN64)
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, platform.type);
#elif defined(_WIN32)
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, platform.type);
#else
ASSERT_EQUALS(cppcheck::Platform::Type::Native, platform.type);
#endif
}
};