Skip to content

Commit 64cd09a

Browse files
authored
fixed #11917 (Default to native platform in Windows builds) (cppcheck-opensource#5428)
1 parent fe46bd3 commit 64cd09a

11 files changed

Lines changed: 17 additions & 103 deletions

cli/cmdlineparser.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,10 @@ void CmdLineParser::printError(const std::string &message)
125125
printMessage("error: " + message);
126126
}
127127

128-
#if defined(_WIN64) || defined(_WIN32)
129-
bool CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
130-
#endif
131-
132128
// TODO: normalize/simplify/native all path parameters
133129
// TODO: error out on all missing given files/paths
134130
bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
135131
{
136-
#if defined(_WIN64) || defined(_WIN32)
137-
bool default_platform = true;
138-
#endif
139-
140132
bool def = false;
141133
bool maxconfigs = false;
142134

@@ -632,10 +624,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
632624
return false;
633625
}
634626

635-
#if defined(_WIN64) || defined(_WIN32)
636-
default_platform = false;
637-
#endif
638-
639627
// TODO: remove
640628
// these are loaded via external files and thus have Settings::PlatformFile set instead.
641629
// override the type so they behave like the regular platforms.
@@ -1057,14 +1045,6 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
10571045
return true;
10581046
}
10591047

1060-
#if defined(_WIN64)
1061-
if (SHOW_DEF_PLATFORM_MSG && default_platform && !mSettings.quiet)
1062-
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.");
1063-
#elif defined(_WIN32)
1064-
if (SHOW_DEF_PLATFORM_MSG && default_platform && !mSettings.quiet)
1065-
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.");
1066-
#endif
1067-
10681048
// Print error only if we have "real" command and expect files
10691049
if (!mExitAfterPrint && mPathNames.empty() && mSettings.project.fileSettings.empty()) {
10701050
printError("no C or C++ source files found.");

cli/cmdlineparser.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ class CmdLineParser {
9999
return mIgnoredPaths;
100100
}
101101

102-
#if defined(_WIN64) || defined(_WIN32)
103-
// temporary variable to "un-break" tests
104-
static bool SHOW_DEF_PLATFORM_MSG;
105-
#endif
106-
107102
protected:
108103

109104
/**

lib/platform.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@
2929

3030
cppcheck::Platform::Platform()
3131
{
32-
// This assumes the code you are checking is for the same architecture this is compiled on.
33-
#if defined(_WIN64)
34-
set(Type::Win64);
35-
#elif defined(_WIN32)
36-
set(Type::Win32A);
37-
#else
3832
set(Type::Native);
39-
#endif
4033
}
4134

4235

releasenotes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Changed interface:
1313
-
1414

1515
Other:
16-
-
16+
- Windows builds now default to the `native` platform instead of `win32A` or `win64`. Please specify it explicitly if you depedent on it.

test/cli/test-helloworld.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_addon_absolute_path():
7878

7979
def test_addon_relative_path():
8080
prjpath = getRelativeProjectPath()
81-
ret, stdout, stderr = cppcheck(['--platform=native', '--addon=misra', '--enable=style', '--template=cppcheck1', prjpath])
81+
ret, stdout, stderr = cppcheck(['--addon=misra', '--enable=style', '--template=cppcheck1', prjpath])
8282
filename = os.path.join(prjpath, 'main.c')
8383
assert ret == 0, stdout
8484
assert stdout == ('Checking %s ...\n'
@@ -89,7 +89,7 @@ def test_addon_relative_path():
8989
def test_addon_with_gui_project():
9090
project_file = 'helloworld/test.cppcheck'
9191
create_gui_project_file(project_file, paths=['.'], addon='misra')
92-
ret, stdout, stderr = cppcheck(['--platform=native', '--template=cppcheck1', '--enable=style', '--project=' + project_file])
92+
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--enable=style', '--project=' + project_file])
9393
filename = os.path.join('helloworld', 'main.c')
9494
assert ret == 0, stdout
9595
assert stdout == 'Checking %s ...\n' % filename

test/cli/test-more-projects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_project_custom_platform(tmpdir):
7474
with open(os.path.join(tmpdir, '1.c'), 'wt') as f:
7575
f.write("int x;")
7676

77-
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1', '-q'])
77+
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1', '-q'])
7878
assert ret == 0, stdout
7979
assert stdout == ''
8080
assert stderr == ''
@@ -89,7 +89,7 @@ def test_project_empty_platform(tmpdir):
8989
with open(os.path.join(tmpdir, '1.c'), 'wt') as f:
9090
f.write("int x;")
9191

92-
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1', '-q'])
92+
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1', '-q'])
9393
assert ret == 0, stdout
9494
assert stdout == ''
9595
assert stderr == ''
@@ -104,7 +104,7 @@ def test_project_unspecified_platform(tmpdir):
104104
with open(os.path.join(tmpdir, '1.c'), 'wt') as f:
105105
f.write("int x;")
106106

107-
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1', '-q'])
107+
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1', '-q'])
108108
assert ret == 0, stdout
109109
assert stdout == "cppcheck: 'Unspecified' is a deprecated platform type and will be removed in Cppcheck 2.14. Please use 'unspecified' instead.\n"
110110
assert stderr == ''
@@ -209,7 +209,7 @@ def test_project_empty_fields(tmpdir):
209209
</coding-standards>
210210
</project>""")
211211

212-
ret, stdout, stderr = cppcheck(['--platform=native', '--project=' + project_file, '--template=cppcheck1'])
212+
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1'])
213213
assert ret == 1, stdout # do not crash
214214
assert stdout == 'cppcheck: error: no C or C++ source files found.\n'
215215
assert stderr == ''

test/cli/test-other.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_missing_include_inline_suppr(tmpdir):
7171

7272

7373
def test_invalid_library(tmpdir):
74-
args = ['--library=none', '--library=posix', '--library=none2', '--platform=native', 'file.c']
74+
args = ['--library=none', '--library=posix', '--library=none2', 'file.c']
7575

7676
exitcode, stdout, stderr = cppcheck(args)
7777
assert exitcode == 1
@@ -85,7 +85,7 @@ def test_message_j(tmpdir):
8585
with open(test_file, 'wt') as f:
8686
f.write("")
8787

88-
args = ['-j2', '--platform=native', test_file]
88+
args = ['-j2', test_file]
8989

9090
_, stdout, _ = cppcheck(args)
9191
assert stdout == "Checking {} ...\n".format(test_file) # we were adding stray \0 characters at the end
@@ -102,7 +102,7 @@ def test_progress(tmpdir):
102102
}
103103
""")
104104

105-
args = ['--report-progress=0', '--enable=all', '--inconclusive', '--platform=native', test_file]
105+
args = ['--report-progress=0', '--enable=all', '--inconclusive', test_file]
106106

107107
exitcode, stdout, stderr = cppcheck(args)
108108
assert exitcode == 0
@@ -135,7 +135,7 @@ def test_progress_j(tmpdir):
135135
}
136136
""")
137137

138-
args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j2', '--disable=unusedFunction', '--platform=native', test_file]
138+
args = ['--report-progress=0', '--enable=all', '--inconclusive', '-j2', '--disable=unusedFunction', test_file]
139139

140140
exitcode, stdout, stderr = cppcheck(args)
141141
assert exitcode == 0

test/fixture.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,8 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::platform(cppcheck::P
421421
{
422422
const std::string platformStr = cppcheck::Platform::toString(type);
423423

424-
// TODO: the default platform differs between Windows and Linux
425-
//if (REDUNDANT_CHECK && settings.platform.type == type)
426-
// throw std::runtime_error("redundant setting: platform (" + platformStr + ")");
424+
if (REDUNDANT_CHECK && settings.platform.type == type)
425+
throw std::runtime_error("redundant setting: platform (" + platformStr + ")");
427426

428427
std::string errstr;
429428
// TODO: exename is not yet set

test/testcmdlineparser.cpp

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@
4040
class TestCmdlineParser : public TestFixture {
4141
public:
4242
TestCmdlineParser() : TestFixture("TestCmdlineParser")
43-
{
44-
#if defined(_WIN64) || defined(_WIN32)
45-
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
46-
#endif
47-
}
48-
49-
~TestCmdlineParser() override {
50-
#if defined(_WIN64) || defined(_WIN32)
51-
CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
52-
#endif
53-
}
43+
{}
5444

5545
private:
5646
std::unique_ptr<Settings> settings;
@@ -169,10 +159,6 @@ class TestCmdlineParser : public TestFixture {
169159
TEST_CASE(platformUnspecified);
170160
TEST_CASE(platformPlatformFile);
171161
TEST_CASE(platformUnknown);
172-
#if defined(_WIN64) || defined(_WIN32)
173-
TEST_CASE(platformDefault);
174-
TEST_CASE(platformDefault2);
175-
#endif
176162
TEST_CASE(plistEmpty);
177163
TEST_CASE(plistDoesNotExist);
178164
TEST_CASE(suppressionsOld);
@@ -1237,39 +1223,6 @@ class TestCmdlineParser : public TestFixture {
12371223
ASSERT_EQUALS("cppcheck: error: unrecognized platform: 'win128'.\n", GET_REDIRECT_OUTPUT);
12381224
}
12391225

1240-
#if defined(_WIN64) || defined(_WIN32)
1241-
void platformDefault() {
1242-
REDIRECT;
1243-
1244-
CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
1245-
1246-
const char * const argv[] = {"cppcheck", "file.cpp"};
1247-
ASSERT(parser->parseFromArgs(2, argv));
1248-
#if defined(_WIN64)
1249-
ASSERT_EQUALS(cppcheck::Platform::Type::Win64, settings->platform.type);
1250-
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);
1251-
#elif defined(_WIN32)
1252-
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings->platform.type);
1253-
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);
1254-
#endif
1255-
1256-
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
1257-
}
1258-
1259-
void platformDefault2() {
1260-
REDIRECT;
1261-
1262-
CmdLineParser::SHOW_DEF_PLATFORM_MSG = true;
1263-
1264-
const char * const argv[] = {"cppcheck", "--platform=unix64", "file.cpp"};
1265-
ASSERT(parser->parseFromArgs(3, argv));
1266-
ASSERT_EQUALS(cppcheck::Platform::Type::Unix64, settings->platform.type);
1267-
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1268-
1269-
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
1270-
}
1271-
#endif
1272-
12731226
void plistEmpty() {
12741227
REDIRECT;
12751228
const char * const argv[] = {"cppcheck", "--plist-output=", "file.cpp"};

test/testcondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class TestCondition : public TestFixture {
3838
TestCondition() : TestFixture("TestCondition") {}
3939

4040
private:
41-
const Settings settings0 = settingsBuilder().library("qt.cfg").library("std.cfg").severity(Severity::style).severity(Severity::warning).platform(cppcheck::Platform::Type::Native).build();
42-
Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).platform(cppcheck::Platform::Type::Native).build();
41+
const Settings settings0 = settingsBuilder().library("qt.cfg").library("std.cfg").severity(Severity::style).severity(Severity::warning).build();
42+
Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
4343

4444
void run() override {
4545
const char cfg[] = "<?xml version=\"1.0\"?>\n"

0 commit comments

Comments
 (0)