Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,20 @@ Library::Error Library::load(const char exename[], const char path[], bool debug

const bool is_abs_path = Path::isAbsolute(path);

std::string fullfilename(path);

// TODO: what if the extension is not .cfg?
// only append extension when we provide the library name and not a path - TODO: handle relative paths?
if (!is_abs_path && Path::getFilenameExtension(fullfilename).empty())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe only allow extensionless as a shorthand if it's a single word? If you're supplying a path you might as well supply the whole filename.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same thing. That's what the TODO is about. Will file a ticket about it and address it as a whole when the behavior is mostly aligned (i.e. no more TODO/skip/xfail in the Python test).

fullfilename += ".cfg";

std::string absolute_path;
// open file..
tinyxml2::XMLDocument doc;
if (debug)
std::cout << "looking for library '" + std::string(path) + "'" << std::endl;
tinyxml2::XMLError error = xml_LoadFile(doc, path);
std::cout << "looking for library '" + fullfilename + "'" << std::endl;
tinyxml2::XMLError error = xml_LoadFile(doc, fullfilename.c_str());
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
// failed to open file.. is there no extension?
std::string fullfilename(path);
if (Path::getFilenameExtension(fullfilename).empty()) {
fullfilename += ".cfg";
if (debug)
std::cout << "looking for library '" + fullfilename + "'" << std::endl;
error = xml_LoadFile(doc, fullfilename.c_str());
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
absolute_path = Path::getAbsoluteFilePath(fullfilename);
}

// only perform further lookups when the given path was not absolute
if (!is_abs_path && error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
{
Expand All @@ -240,7 +236,7 @@ Library::Error Library::load(const char exename[], const char path[], bool debug
}
}
} else
absolute_path = Path::getAbsoluteFilePath(path);
absolute_path = Path::getAbsoluteFilePath(fullfilename);

if (error == tinyxml2::XML_SUCCESS) {
if (mData->mFiles.find(absolute_path) == mData->mFiles.end()) {
Expand Down
9 changes: 0 additions & 9 deletions test/cli/lookup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_lib_lookup(tmpdir):
assert exitcode == 0, stdout if stdout else stderr
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
assert lines == [
"looking for library 'gnu'",
"looking for library 'gnu.cfg'",
"looking for library '{}/gnu.cfg'".format(exepath),
"looking for library '{}/cfg/gnu.cfg'".format(exepath),
Expand Down Expand Up @@ -63,7 +62,6 @@ def test_lib_lookup_notfound(tmpdir):
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
assert lines == [
# TODO: specify which folder is actually used for lookup here
"looking for library 'none'", # TODO: this could conflict with the platform lookup
"looking for library 'none.cfg'",
# TODO: lookup of '{exepath}/none' missing - could conflict with the platform lookup though
"looking for library '{}/none.cfg'".format(exepath),
Expand Down Expand Up @@ -126,7 +124,6 @@ def test_lib_lookup_relative_noext_notfound(tmpdir):
assert exitcode == 1, stdout if stdout else stderr
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
assert lines == [
"looking for library 'config/gnu'",
"looking for library 'config/gnu.cfg'",
"looking for library '{}/config/gnu.cfg'".format(exepath),
"looking for library '{}/cfg/config/gnu.cfg'".format(exepath),
Expand Down Expand Up @@ -186,8 +183,6 @@ def test_lib_lookup_nofile(tmpdir):
pass

# make sure we do not produce an error when the attempted lookup path is a directory and not a file
gtk_dir = os.path.join(tmpdir, 'gtk')
os.mkdir(gtk_dir)
gtk_cfg_dir = os.path.join(tmpdir, 'gtk.cfg')
os.mkdir(gtk_cfg_dir)

Expand All @@ -198,7 +193,6 @@ def test_lib_lookup_nofile(tmpdir):
assert exitcode == 0, stdout if stdout else stderr
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
assert lines == [
"looking for library 'gtk'",
"looking for library 'gtk.cfg'",
"looking for library '{}/gtk.cfg'".format(exepath),
"looking for library '{}/cfg/gtk.cfg'".format(exepath),
Expand All @@ -223,7 +217,6 @@ def test_lib_lookup_invalid(tmpdir):
assert exitcode == 1, stdout if stdout else stderr
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
assert lines == [
"looking for library 'gnu'",
"looking for library 'gnu.cfg'",
"library not found: 'gnu'",
"Error=XML_ERROR_PARSING_TEXT ErrorID=8 (0x8) Line number=1", # TODO: log the failure before saying the library was not found
Expand All @@ -243,11 +236,9 @@ def test_lib_lookup_multi(tmpdir):
assert exitcode == 0, stdout if stdout else stderr
lines = __remove_std_lookup_log(stdout.splitlines(), exepath)
assert lines == [
"looking for library 'posix'",
"looking for library 'posix.cfg'",
"looking for library '{}/posix.cfg'".format(exepath),
"looking for library '{}/cfg/posix.cfg'".format(exepath),
"looking for library 'gnu'",
"looking for library 'gnu.cfg'",
"looking for library '{}/gnu.cfg'".format(exepath),
"looking for library '{}/cfg/gnu.cfg'".format(exepath),
Expand Down
Loading