diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2019-12-19 18:13:03 -0500 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2019-12-19 18:13:23 -0500 |
commit | 3c8c729c4c6d19a44e7b39c49d79dc5aafd7b9b6 (patch) | |
tree | 12e7eb30b048cb6f6f501b1acb9cce1923582e63 | |
parent | bc85061a94c27edf8d919cd9a41e81db53f79068 (diff) |
clang-plugin: Add option to provide extra typelib paths
This adds a --typelib-path option to the plugin, which may be given more
than once. Each time the option is given, it adds a path to the list of
typelib search paths.
In order to deal with build directories given as typelib paths, we also
make sure to skip files in the typelib search path without the .typelib
extension.
See: #39
-rw-r--r-- | clang-plugin/plugin.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/clang-plugin/plugin.cpp b/clang-plugin/plugin.cpp index 1a94e0f..5e49c71 100644 --- a/clang-plugin/plugin.cpp +++ b/clang-plugin/plugin.cpp @@ -204,15 +204,16 @@ private: } while ((typelib_filename = g_dir_read_name (dir)) != NULL) { - /* Load the typelib. Ignore failure. */ - - std::string _typelib_filename (typelib_filename); - std::string::size_type last_dot = _typelib_filename.find_last_of ("."); - if (last_dot == std::string::npos) { + if (!g_str_has_suffix (typelib_filename, ".typelib")) { /* No ‘.typelib’ suffix — ignore. */ continue; } + /* Load the typelib. Ignore failure. */ + std::string _typelib_filename (typelib_filename); + std::string::size_type last_dot = _typelib_filename.find_last_of ("."); + g_assert (last_dot != std::string::npos); + std::string gi_namespace_and_version = _typelib_filename.substr (0, last_dot); this->_load_typelib (CI, gi_namespace_and_version); } @@ -230,9 +231,6 @@ protected: ParseArgs (const CompilerInstance &CI, const std::vector<std::string>& args) { - /* Load all typelibs. */ - this->_load_gi_repositories (CI); - /* Enable the default set of checkers. */ for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end (); ++it) { @@ -254,9 +252,14 @@ protected: } else if (arg == "--disable-checker") { const std::string checker = *(++it); this->_disabled_checkers.get ()->insert (std::string (checker)); + } else if (arg == "--typelib-path") { + g_irepository_prepend_search_path ((++it)->c_str ()); } } + /* Load all typelibs. */ + this->_load_gi_repositories (CI); + /* Listen to the V environment variable (as standard in automake) too. */ const char *v_value = getenv ("V"); if (v_value != NULL && strcmp (v_value, "0") == 0) { @@ -308,6 +311,8 @@ protected: " Disable the given Tartan checker, which may be " "‘all’. All checkers are\n" " enabled by default.\n" + " --typelib-path [path]\n" + " Add the given path to the search path for typelibs.\n" " --quiet\n" " Disable all plugin output except code " "diagnostics (remarks,\n" |