Skip to content

Commit e9e5778

Browse files
committed
fixed #14658 - do not append extension in lookup if a relative path has been provided
1 parent 8343cd0 commit e9e5778

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

lib/library.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ Library::Error Library::load(const char exename[], const char path[], bool debug
194194
}
195195

196196
const bool is_abs_path = Path::isAbsolute(path);
197+
const bool is_rel_path = Path::isRelative(path);
197198

198199
std::string fullfilename(path);
199200

200201
// TODO: what if the extension is not .cfg?
201-
// only append extension when we provide the library name and not a path - TODO: handle relative paths?
202-
if (!is_abs_path && Path::getFilenameExtension(fullfilename).empty())
202+
// only append extension when we provide the library name and not a path
203+
if (!is_abs_path && !is_rel_path && Path::getFilenameExtension(fullfilename).empty())
203204
fullfilename += ".cfg";
204205

205206
std::string absolute_path;

lib/platform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ bool Platform::loadFromFile(const std::vector<std::string>& paths, const std::st
176176
std::cout << "looking for platform '" + filename + "'" << std::endl;
177177

178178
const bool is_abs_path = Path::isAbsolute(filename);
179+
const bool is_rel_path = Path::isRelative(filename);
179180

180181
std::string fullfilename(filename);
181182
// TODO: what if extension is not .xml?
182183
// only append extension when we provide the library name is not a path - TODO: handle relative paths?
183-
if (!is_abs_path && Path::getFilenameExtension(fullfilename).empty())
184+
if (!is_abs_path && !is_rel_path && Path::getFilenameExtension(fullfilename).empty())
184185
fullfilename += ".xml";
185186

186187
// TODO: use native separators

test/cli/lookup_test.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ def test_lib_lookup_relative_noext_notfound(tmpdir):
205205
assert exitcode == 1, stdout if stdout else stderr
206206
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
207207
assert lines == [
208-
"looking for library 'config/gnu.cfg'",
209-
"looking for library '{}/config/gnu.cfg'".format(exepath),
210-
"looking for library '{}/cfg/config/gnu.cfg'".format(exepath),
208+
"looking for library 'config/gnu'",
209+
"looking for library '{}/config/gnu'".format(exepath),
210+
"looking for library '{}/cfg/config/gnu'".format(exepath),
211211
"library not found: 'config/gnu'",
212212
"cppcheck: Failed to load library configuration file 'config/gnu'. File not found"
213213
]
@@ -226,10 +226,9 @@ def test_lib_lookup_relative_noext_trailing_notfound(tmpdir):
226226
assert exitcode == 1, stdout if stdout else stderr
227227
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
228228
assert lines == [
229-
# TODO: do not append extension
230-
"looking for library 'config/gnu/.cfg'",
231-
"looking for library '{}/config/gnu/.cfg'".format(exepath),
232-
"looking for library '{}/cfg/config/gnu/.cfg'".format(exepath),
229+
"looking for library 'config/gnu/'",
230+
"looking for library '{}/config/gnu/'".format(exepath),
231+
"looking for library '{}/cfg/config/gnu/'".format(exepath),
233232
"library not found: 'config/gnu/'",
234233
"cppcheck: Failed to load library configuration file 'config/gnu/'. File not found"
235234
]
@@ -608,10 +607,10 @@ def test_platform_lookup_relative_noext_notfound(tmpdir):
608607
lines = stdout.splitlines()
609608
assert lines == [
610609
"looking for platform 'platform/none'",
611-
"try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(cwd, cwd),
612-
"try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(cwd, cwd),
613-
"try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(exepath, exepath),
614-
"try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(exepath, exepath),
610+
"try to load platform file '{}/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none".format(cwd, cwd),
611+
"try to load platform file '{}/platforms/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none".format(cwd, cwd),
612+
"try to load platform file '{}/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none".format(exepath, exepath),
613+
"try to load platform file '{}/platforms/platform/none' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none".format(exepath, exepath),
615614
"cppcheck: error: unrecognized platform: 'platform/none'."
616615
]
617616

@@ -632,11 +631,10 @@ def test_platform_lookup_relative_noext_trailing_notfound(tmpdir):
632631
lines = stdout.splitlines()
633632
assert lines == [
634633
"looking for platform 'platform/none/'",
635-
# TODO: should not append extension
636-
"try to load platform file '{}/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none/.xml".format(cwd, cwd),
637-
"try to load platform file '{}/platforms/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none/.xml".format(cwd, cwd),
638-
"try to load platform file '{}/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none/.xml".format(exepath, exepath),
639-
"try to load platform file '{}/platforms/platform/none/.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none/.xml".format(exepath, exepath),
634+
"try to load platform file '{}/platform/none/' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none/".format(cwd, cwd),
635+
"try to load platform file '{}/platforms/platform/none/' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none/".format(cwd, cwd),
636+
"try to load platform file '{}/platform/none/' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none/".format(exepath, exepath),
637+
"try to load platform file '{}/platforms/platform/none/' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none/".format(exepath, exepath),
640638
"cppcheck: error: unrecognized platform: 'platform/none/'."
641639
]
642640

@@ -884,6 +882,7 @@ def test_addon_lookup_relative_notfound(tmpdir):
884882
]
885883

886884

885+
# FIXME: an addon requires a file extension as we need to differentiate between .py and .json addons
887886
def test_addon_lookup_relative_noext_notfound(tmpdir):
888887
test_file = os.path.join(tmpdir, 'test.c')
889888
with open(test_file, 'wt'):
@@ -956,6 +955,7 @@ def test_addon_lookup_absolute_notfound(tmpdir):
956955
]
957956

958957

958+
# FIXME: an addon requires a file extension as we need to differentiate between .py and .json addons
959959
def test_addon_lookup_absolute_noext_notfound(tmpdir):
960960
test_file = os.path.join(tmpdir, 'test.c')
961961
with open(test_file, 'wt'):

0 commit comments

Comments
 (0)