diff --git a/lib/library.cpp b/lib/library.cpp index e8b6c40ef9c..828fd65af87 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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()) + 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) { @@ -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()) { diff --git a/test/cli/lookup_test.py b/test/cli/lookup_test.py index f22270b4cc0..f2a382a7f44 100644 --- a/test/cli/lookup_test.py +++ b/test/cli/lookup_test.py @@ -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), @@ -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), @@ -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), @@ -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) @@ -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), @@ -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 @@ -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),