Usability: Fixed loading of platform file placed in same path as project file
This commit is contained in:
parent
fe4964f22c
commit
3502036b14
|
@ -624,7 +624,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
mSettings->platform(Settings::Native);
|
mSettings->platform(Settings::Native);
|
||||||
else if (platform == "unspecified" || platform == "Unspecified" || platform == "")
|
else if (platform == "unspecified" || platform == "Unspecified" || platform == "")
|
||||||
;
|
;
|
||||||
else if (!mSettings->loadPlatformFile(argv[0], platform)) {
|
else if (!mSettings->loadPlatformFile(projectFile.c_str(), platform) && !mSettings->loadPlatformFile(argv[0], platform)) {
|
||||||
std::string message("cppcheck: error: unrecognized platform: \"");
|
std::string message("cppcheck: error: unrecognized platform: \"");
|
||||||
message += platform;
|
message += platform;
|
||||||
message += "\".";
|
message += "\".";
|
||||||
|
|
|
@ -162,6 +162,8 @@ bool cppcheck::Platform::loadPlatformFile(const char exename[], const std::strin
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
filenames.push_back(filename + ".xml");
|
filenames.push_back(filename + ".xml");
|
||||||
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
|
if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) {
|
||||||
|
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
|
||||||
|
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + filename);
|
||||||
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
|
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
|
||||||
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename + ".xml");
|
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename + ".xml");
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,3 +32,32 @@ def test_project_force_U():
|
||||||
ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-UMACRO1', '-rp=' + temp_folder, '--template=cppcheck1'])
|
ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-UMACRO1', '-rp=' + temp_folder, '--template=cppcheck1'])
|
||||||
assert stderr == '[bug1.cpp:2]: (error) Division by zero.\n'
|
assert stderr == '[bug1.cpp:2]: (error) Division by zero.\n'
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_custom_platform():
|
||||||
|
"""
|
||||||
|
import cppcheck project that contains a custom platform file
|
||||||
|
"""
|
||||||
|
with tempfile.TemporaryDirectory('10018') as temp_folder:
|
||||||
|
project_file = os.path.join(temp_folder, 'Project.cppcheck')
|
||||||
|
|
||||||
|
with open(project_file, 'wt') as f:
|
||||||
|
f.write("""
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="1">
|
||||||
|
<platform>p1.xml</platform>
|
||||||
|
<paths>
|
||||||
|
<dir name="."/>
|
||||||
|
</paths>
|
||||||
|
</project>
|
||||||
|
""")
|
||||||
|
|
||||||
|
with open(os.path.join(temp_folder, 'p1.xml'), 'wt') as f:
|
||||||
|
f.write('<?xml version="1.0"?>\n<platform/>')
|
||||||
|
|
||||||
|
with open(os.path.join(temp_folder, '1.c'), 'wt') as f:
|
||||||
|
f.write("int x;")
|
||||||
|
|
||||||
|
ret, stdout, stderr = cppcheck(['--project=' + project_file, '--template=cppcheck1'])
|
||||||
|
assert stderr == ''
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue