Skip to content

Commit 2aaac23

Browse files
committed
Fix #13645 (fail to load platform when executing Cppcheck in PATH)
1 parent 5374cd3 commit 2aaac23

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
421421

422422
std::vector<std::string> lookupPaths{
423423
Path::getCurrentPath(), // TODO: do we want to look in CWD?
424-
Path::getPathFromFilename(argv[0])
424+
Path::getPathFromFilename(mSettings.exename),
425425
};
426426

427427
bool executorAuto = true;

test/cli/lookup_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,27 @@ def test_platform_lookup_ext(tmpdir):
381381
]
382382

383383

384+
def test_platform_lookup_path(tmpdir):
385+
test_file = os.path.join(tmpdir, 'test.c')
386+
with open(test_file, 'wt'):
387+
pass
388+
389+
c = 'cppcheck.exe' if sys.platform == 'win32' else 'cppcheck'
390+
path = os.path.dirname(__lookup_cppcheck_exe())
391+
env = os.environ.copy()
392+
env['PATH'] = path
393+
exitcode, stdout, stderr, exe = cppcheck_ex(args=['--debug-lookup=platform', '--platform=avr8.xml', test_file], cppcheck_exe=c, cwd=str(tmpdir), env=env)
394+
assert exitcode == 0, stdout if stdout else stderr
395+
lines = stdout.splitlines()
396+
assert lines == [
397+
"looking for platform 'avr8.xml'",
398+
"try to load platform file '{}/avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/avr8.xml".format(tmpdir, tmpdir),
399+
"try to load platform file '{}/platforms/avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/avr8.xml".format(tmpdir, tmpdir),
400+
"try to load platform file '{}/avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/avr8.xml".format(path, path),
401+
"try to load platform file '{}/platforms/avr8.xml' ... Success".format(path),
402+
'Checking {} ...'.format(test_file)
403+
]
404+
384405
def test_platform_lookup_notfound(tmpdir):
385406
test_file = os.path.join(tmpdir, 'test.c')
386407
with open(test_file, 'wt'):

0 commit comments

Comments
 (0)