Skip to content

Commit 3502036

Browse files
committed
Usability: Fixed loading of platform file placed in same path as project file
1 parent fe4964f commit 3502036

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
624624
mSettings->platform(Settings::Native);
625625
else if (platform == "unspecified" || platform == "Unspecified" || platform == "")
626626
;
627-
else if (!mSettings->loadPlatformFile(argv[0], platform)) {
627+
else if (!mSettings->loadPlatformFile(projectFile.c_str(), platform) && !mSettings->loadPlatformFile(argv[0], platform)) {
628628
std::string message("cppcheck: error: unrecognized platform: \"");
629629
message += platform;
630630
message += "\".";

lib/platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ bool cppcheck::Platform::loadPlatformFile(const char exename[], const std::strin
162162
std::vector<std::string> filenames;
163163
filenames.push_back(filename + ".xml");
164164
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
165+
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
166+
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
165167
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
166168
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename + ".xml");
167169
}

test/cli/test-more-projects.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,32 @@ def test_project_force_U():
3232
ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-UMACRO1', '-rp=' + temp_folder, '--template=cppcheck1'])
3333
assert stderr == '[bug1.cpp:2]: (error) Division by zero.\n'
3434

35+
36+
def test_project_custom_platform():
37+
"""
38+
import cppcheck project that contains a custom platform file
39+
"""
40+
with tempfile.TemporaryDirectory('10018') as temp_folder:
41+
project_file = os.path.join(temp_folder, 'Project.cppcheck')
42+
43+
with open(project_file, 'wt') as f:
44+
f.write("""
45+
<?xml version="1.0" encoding="UTF-8"?>
46+
<project version="1">
47+
<platform>p1.xml</platform>
48+
<paths>
49+
<dir name="."/>
50+
</paths>
51+
</project>
52+
""")
53+
54+
with open(os.path.join(temp_folder, 'p1.xml'), 'wt') as f:
55+
f.write('<?xml version="1.0"?>\n<platform/>')
56+
57+
with open(os.path.join(temp_folder, '1.c'), 'wt') as f:
58+
f.write("int x;")
59+
60+
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1'])
61+
assert stderr == ''
62+
63+

0 commit comments

Comments
 (0)