Skip to content
Open
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
4 changes: 2 additions & 2 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"command": "ecc_show_all_errors"
},
{
"caption": "ECC: Clean current CMake cache",
"command": "clean_cmake"
"caption": "ECC: Clean internal cache",
"command": "clean_internal_cache"
},
{
"caption": "ECC: Show popup info",
Expand Down
46 changes: 21 additions & 25 deletions EasyClangComplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ def plugin_loaded():
We need it to initialize all the different classes that encapsulate
functionality. We can only properly init them after sublime api is
available."""
log.debug("Reloading the plugin")
module_reloader.ModuleReloader.reload_all(ignore_string='singleton')
GenericCache.clear_all_caches()
# Clear the old cache directory.
cache_dir = File.get_temp_dir()
if path.exists(cache_dir):
log.debug("Removing the build cache folder %s", cache_dir)
shutil.rmtree(cache_dir, ignore_errors=True)
handle_plugin_loaded_function()


Expand Down Expand Up @@ -179,36 +185,26 @@ def passthrough(view, trigger):
settings.force_unix_includes)


class CleanCmakeCommand(sublime_plugin.TextCommand):
"""Command that cleans cmake build directory."""
class CleanInternalCacheCommand(sublime_plugin.TextCommand):
"""Command that cleans the internal build directory and all caches."""

def run(self, edit):
"""Run clean command.

Detects if there is a CMakeLists.txt associated to current view and
cleans all related information in case there is one.
"""
"""Run clean command."""
if not SublBridge.is_valid_view(self.view):
log.debug("Cannot clean build for view: '%s'",
self.view.file_name())
return
import gc
file_path = self.view.file_name()
cmake_cache = CMakeFileCache()
try:
cmake_file_path = cmake_cache[file_path]
log.debug("Cleaning file: '%s'", cmake_file_path)
del cmake_cache[file_path]
del cmake_cache[cmake_file_path]
EasyClangComplete.view_config_manager.clear_for_view(
log.debug("Clearing config for view: '%s'", self.view.file_name())
EasyClangComplete.view_config_manager.clear_for_view(
self.view.buffer_id())
# Better safe than sorry. Cleanup!
gc.collect()
temp_proj_dir = CMakeFile.unique_folder_name(cmake_file_path)
if path.exists(temp_proj_dir):
log.debug("Cleaning build directory: '%s'", temp_proj_dir)
shutil.rmtree(temp_proj_dir, ignore_errors=True)
except KeyError:
log.debug("Nothing to clean")

cache_dir = File.get_temp_dir()
if path.exists(cache_dir):
log.debug("Removing the build cache folder %s", cache_dir)
shutil.rmtree(cache_dir, ignore_errors=True)
else:
log.warning("Cloud not clean folder: %s", cache_dir)
GenericCache().clear_all_caches()
EasyClangComplete.view_config_manager.clear()

class GenerateBazelCompDbCommand(sublime_plugin.TextCommand):
"""Command that generates a compilation database with bazel."""
Expand Down
13 changes: 11 additions & 2 deletions plugin/flags_sources/cmake_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ def get_flags(self, file_path=None, search_scope=None):
flags = db.get_flags(file_path, db_search_scope)
return flags

@staticmethod
def get_cache_dir():
"""Get all builds folder name.

Returns:
str: Path to a temp folder where all cache is stored.
"""
return File.get_temp_dir('cmake_builds')

@staticmethod
def unique_folder_name(cmake_path):
"""Get unique build folder name.
Expand All @@ -152,8 +161,8 @@ def unique_folder_name(cmake_path):
Returns:
str: Path to a unique temp folder.
"""
return File.get_temp_dir('cmake_builds',
Tools.get_unique_str(cmake_path))
return File.get_temp_dir('cmake_builds',
Tools.get_unique_str(cmake_path))

@staticmethod
def __prepend_prefix_paths(prefix_paths):
Expand Down
4 changes: 2 additions & 2 deletions plugin/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def run_command(command, shell=False, cwd=path.curdir, env=environ,
output_text = e.output.decode("utf-8")
_log.debug("Command finished with code: %s", e.returncode)
_log.debug("Command output: \n%s", output_text)
except OSError:
except OSError as e:
_log.debug(
"Executable file not found executing: {}".format(command))
"Error while executing command: %s", e.strerror)
return output_text

@staticmethod
Expand Down
8 changes: 8 additions & 0 deletions plugin/view_config/view_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def load_for_view(self, view, settings):
log.error("Traceback: %s", tb)
return None

def clear(self):
"""Clear all cache."""
import gc
log.debug("Trying to clean all view cache")
with self.__rlock:
self.__cache.clear()
gc.collect() # Explicitly collect garbage.

def clear_for_view(self, v_id):
"""Clear config for a view id."""
assert isinstance(v_id, int), "View id should be an int."
Expand Down