From f16ffd88e96efc4ab5a538fa61197741be6fee3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 27 Jan 2023 10:46:48 +0100 Subject: [PATCH] deprecate non-`native` platform being used by default in Windows builds (#4734) * deprecate non-`native` platform being used by default in Windows builds * test-helloworld.py: avoid deprecation warnings --- cli/cmdlineparser.cpp | 20 +++++++++++++++ cli/cmdlineparser.h | 5 ++++ releasenotes.txt | 1 + test/cli/test-helloworld.py | 4 +-- test/testcmdlineparser.cpp | 51 ++++++++++++++++++++++++++++++++++++- test/testplatform.cpp | 12 +++++++++ 6 files changed, 90 insertions(+), 3 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 9db58c500..2f53869b8 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -128,10 +128,18 @@ 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; @@ -617,6 +625,10 @@ 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. @@ -1039,6 +1051,14 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) return true; } +#if defined(_WIN64) + if (SHOW_DEF_PLATFORM_MSG && default_platform) + 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) + 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."); diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 8b09e6ae9..e50dabf40 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -93,6 +93,11 @@ public: return mIgnoredPaths; } +#if defined(_WIN64) || defined(_WIN32) + // temporary variable to "un-break" tests + static bool SHOW_DEF_PLATFORM_MSG; +#endif + protected: /** diff --git a/releasenotes.txt b/releasenotes.txt index 64bfc8f1b..2327e97d0 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -4,3 +4,4 @@ release notes for cppcheck-2.10 - if the file provided via "--file-list" cannot be opened it will now error out - add command-line option "--disable=" to individually disable checks - added CMake option BUILD_CORE_DLL to build lib as cppcheck-core.dll with Visual Studio +- Windows binaries currently default to the "win32A" and "win64" platform respectively. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32A' or '--platform=win64' explicitly if you rely on this. diff --git a/test/cli/test-helloworld.py b/test/cli/test-helloworld.py index 83584e511..bb9af0f3c 100644 --- a/test/cli/test-helloworld.py +++ b/test/cli/test-helloworld.py @@ -72,7 +72,7 @@ def test_addon_absolute_path(): def test_addon_relative_path(): prjpath = getRelativeProjectPath() - ret, stdout, stderr = cppcheck(['--addon=misra', '--template=cppcheck1', prjpath]) + ret, stdout, stderr = cppcheck(['--platform=native', '--addon=misra', '--template=cppcheck1', prjpath]) filename = os.path.join(prjpath, 'main.c') assert ret == 0, stdout assert stdout == ('Checking %s ...\n' @@ -83,7 +83,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(['--template=cppcheck1', '--project=' + project_file]) + ret, stdout, stderr = cppcheck(['--platform=native', '--template=cppcheck1', '--project=' + project_file]) filename = os.path.join('helloworld', 'main.c') assert ret == 0, stdout assert stdout == 'Checking %s ...\n' % filename diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index d64ad5b64..92cfae954 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -37,7 +37,17 @@ class TestCmdlineParser : public TestFixture { public: TestCmdlineParser() : TestFixture("TestCmdlineParser") - , defParser(&settings) {} + , defParser(&settings) { +#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: Settings settings; // TODO: reset after each test @@ -131,6 +141,10 @@ 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); @@ -1065,6 +1079,41 @@ 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"}; + settings = Settings(); + ASSERT(defParser.parseFromArgs(2, argv)); +#if defined(_WIN64) + ASSERT_EQUALS(Settings::Win64, settings.platformType); + 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(Settings::Win32A, settings.platformType); + 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"}; + settings = Settings(); + ASSERT(defParser.parseFromArgs(3, argv)); + ASSERT_EQUALS(Settings::Unix64, settings.platformType); + ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); + + CmdLineParser::SHOW_DEF_PLATFORM_MSG = false; + } +#endif + void plistEmpty() { REDIRECT; const char * const argv[] = {"cppcheck", "--plist-output=", "file.cpp"}; diff --git a/test/testplatform.cpp b/test/testplatform.cpp index f7cfa5251..e7b2d02a8 100644 --- a/test/testplatform.cpp +++ b/test/testplatform.cpp @@ -37,6 +37,7 @@ private: TEST_CASE(valid_config_file_4); TEST_CASE(invalid_config_file_1); TEST_CASE(empty_elements); + TEST_CASE(default_platform); } static bool readPlatform(cppcheck::Platform& platform, const char* xmldata) { @@ -313,6 +314,17 @@ private: ASSERT_EQUALS(platform.PlatformFile, platform.platformType); ASSERT(!platform.isWindowsPlatform()); } + + void default_platform() { + cppcheck::Platform platform; +#if defined(_WIN64) + ASSERT_EQUALS(cppcheck::Platform::Win64, platform.platformType); +#elif defined(_WIN32) + ASSERT_EQUALS(cppcheck::Platform::Win32A, platform.platformType); +#else + ASSERT_EQUALS(cppcheck::Platform::Native, platform.platformType); +#endif + } }; REGISTER_TEST(TestPlatform)