Skip to content

Commit 8833e3e

Browse files
authored
Fix #13556 (Import project: exclude missing files) (danmar#7644)
1 parent 1dd1575 commit 8833e3e

File tree

5 files changed

+11
-22
lines changed

5 files changed

+11
-22
lines changed

gui/test/projectfile/testprojectfile.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "settings.h"
2626
#include "suppressions.h"
2727

28-
#include <string>
29-
3028
#include <QFile>
3129
#include <QIODevice>
3230
#include <QList>
@@ -45,9 +43,6 @@ Platform::Platform() = default;
4543
Library::Library() = default;
4644
Library::~Library() = default;
4745
struct Library::LibraryData {};
48-
bool ImportProject::sourceFileExists(const std::string & /*file*/) {
49-
return true;
50-
}
5146

5247
void TestProjectFile::loadInexisting() const
5348
{

lib/importproject.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,6 @@ bool ImportProject::importCompileCommands(std::istream &istr)
430430
#endif
431431
else
432432
path = Path::simplifyPath(directory + file);
433-
if (!sourceFileExists(path)) {
434-
printError("'" + path + "' from compilation database does not exist");
435-
return false;
436-
}
437433
FileSettings fs{path, Standards::Language::None, 0}; // file will be identified later on
438434
fsParseCommand(fs, command); // read settings; -D, -I, -U, -std, -m*, -f*
439435
std::map<std::string, std::string, cppcheck::stricmp> variables;
@@ -1547,8 +1543,3 @@ void ImportProject::printError(const std::string &message)
15471543
{
15481544
std::cout << "cppcheck: error: " << message << std::endl;
15491545
}
1550-
1551-
bool ImportProject::sourceFileExists(const std::string &file)
1552-
{
1553-
return Path::isFile(file);
1554-
}

lib/importproject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
102102
protected:
103103
bool importCompileCommands(std::istream &istr);
104104
bool importCppcheckGuiProject(std::istream &istr, Settings &settings, Suppressions &supprs);
105-
virtual bool sourceFileExists(const std::string &file);
106105

107106
private:
108107
struct SharedItemsProject {

test/cli/project_test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ def test_json_entry_file_not_found(tmpdir):
4949
"output": "bug1.o"}
5050
]
5151

52-
expected = "'{}' from compilation database does not exist".format(os.path.join(tmpdir, "bug1.cpp"))
52+
project_file = os.path.join(tmpdir, "file.json")
53+
missing_file = os.path.join(tmpdir, "bug1.cpp")
54+
missing_file_posix = missing_file
55+
5356
if sys.platform == "win32":
54-
expected = expected.replace('\\', '/')
57+
missing_file_posix = missing_file_posix.replace('\\', '/')
5558

56-
__test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)
59+
with open(project_file, 'w') as f:
60+
f.write(json.dumps(compilation_db))
61+
62+
ret, _, stderr = cppcheck(["--project=" + str(project_file)])
63+
assert 0 == ret
64+
assert f"{missing_file}:1:0: error: File is missing: {missing_file_posix} [syntaxError]\n\n^\n" == stderr
5765

5866

5967
def test_json_no_arguments(tmpdir):

test/testimportproject.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ class TestImporter : public ImportProject {
3838
using ImportProject::importCppcheckGuiProject;
3939
using ImportProject::importVcxproj;
4040
using ImportProject::SharedItemsProject;
41-
42-
bool sourceFileExists(const std::string & /*file*/) override {
43-
return true;
44-
}
4541
};
4642

4743

0 commit comments

Comments
 (0)