Skip to content

Commit

Permalink
Add cmake_binary setting, and make preps for version 3.11
Browse files Browse the repository at this point in the history
- Protocol version 1.1 is used in 3.11
- Allow cmake_binary setting to point to another cmake executable, if
  desired.
  • Loading branch information
rwols committed Jun 24, 2018
1 parent 402e4d5 commit 171dc98
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 80 deletions.
5 changes: 5 additions & 0 deletions CMakeBuilder.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

//==========================================================================

// The path to the CMake binary. If CMake is in your PATH, then you don't
// have to change this. Otherwise, specify the full path to the CMake
// executable.
"cmake_binary": "cmake",

// If there's a compile_commands.json file generated with
// CMAKE_EXPORT_COMPILE_COMMANDS, do we want to copy it over to the source
// directory? This is useful for, for instance, clangd.
Expand Down
4 changes: 3 additions & 1 deletion commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ def _run_configure_with_new_settings(cls):
return
pickle.dump(cmake_settings, open(path, "wb"))
version = capabilities("version")
if version["major"] >= 3 and version["minor"] >= 10:
if version["major"] >= 3 and version["minor"] >= 11:
protocol = (1, 2)
elif version["major"] >= 3 and version["minor"] >= 10:
protocol = (1, 1)
else:
protocol = (1, 0)
Expand Down
40 changes: 5 additions & 35 deletions commands/edit_cache.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import sublime
import sublime_plugin
import os
from .command import CmakeCommand
from ..support import capabilities


if capabilities("serverMode"):
class CmakeEditCacheCommand(CmakeCommand):

def description(self):
return "Edit Cache..."

class CmakeEditCacheCommand(CmakeCommand):

def description(self):
return "Edit Cache..."

def run(self):
self.server.cache()

else:


class CmakeEditCacheCommand(sublime_plugin.WindowCommand):

"""Edit an entry from the CMake cache."""
def is_enabled(self):
try:
build_folder = self.window.project_data()["settings"]["cmake"]["build_folder"]
build_folder = sublime.expand_variables(build_folder, self.window.extract_variables())
return os.path.exists(os.path.join(build_folder, "CMakeCache.txt"))
except Exception as e:
return False

def description(self):
return "Edit Cache..."

def run(self):
build_folder = self.window.project_data()["settings"]["cmake"]["build_folder"]
build_folder = sublime.expand_variables(build_folder, self.window.extract_variables())
self.window.open_file(os.path.join(build_folder, "CMakeCache.txt"))
self.window.run_command("show_overlay", args={"overlay": "goto", "text": "@"})
def run(self):
self.server.cache()
46 changes: 9 additions & 37 deletions commands/open_build_folder.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
import sublime
import sublime_plugin
import os
from .command import CmakeCommand
from ..support import capabilities


if capabilities("serverMode"):
class CmakeOpenBuildFolderCommand(CmakeCommand):
"""Opens the build folder."""

@classmethod
def description(cls):
return "Browse Build Folder..."

class CmakeOpenBuildFolderCommand(CmakeCommand):
"""Opens the build folder."""

@classmethod
def description(cls):
return "Browse Build Folder..."

def run(self):
build_folder = self.server.cmake.build_folder
self.window.run_command("open_dir", args={"dir": os.path.realpath(build_folder)})

else:


class CmakeOpenBuildFolderCommand(sublime_plugin.WindowCommand):
"""Opens the build folder."""

@classmethod
def description(cls):
return "Browse Build Folder..."

def is_enabled(self):
try:
build_folder = self.window.project_data()["settings"]["cmake"]["build_folder"]
build_folder = sublime.expand_variables(build_folder, self.window.extract_variables())
return os.path.exists(build_folder)
except Exception as e:
return False

def run(self):
build_folder = self.window.project_data()["settings"]["cmake"]["build_folder"]
build_folder = sublime.expand_variables(build_folder, self.window.extract_variables())
self.window.run_command('open_dir', args={'dir': os.path.realpath(build_folder)})
def run(self):
build_folder = self.server.cmake.build_folder
args = {"dir": os.path.realpath(build_folder)}
self.window.run_command("open_dir", args=args)
40 changes: 34 additions & 6 deletions support/capabilities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
from .check_output import check_output
import json
import sublime

_capabilities = None


def plugin_loaded():
settings = sublime.load_settings("CMakeBuilder.sublime-settings")
settings.add_on_change("CMakeBuilder", _reload_capabilities)
_reload_capabilities()


def _reload_capabilities():
global _capabilities
try:
print("loading settings")
settings = sublime.load_settings("CMakeBuilder.sublime-settings")
print("fetching cmake binary")
cmake = settings.get("cmake_binary", "cmake")
command = "{} -E capabilities".format(cmake)
print("running", command)
output = check_output(command)
_capabilities = json.loads(output)
except Exception as e:
sublime.error_message("There was an error loading cmake's "
"capabilities. Your \"cmake_binary\" setting is "
"set to \"{}\". Please make sure that this "
"points to a valid cmake executable."
.format(cmake))
print(str(e))
_capabilities = {"error": None}


def capabilities(key):
global _capabilities
if _capabilities is None:
try:
_capabilities = json.loads(check_output("cmake -E capabilities"))
except Exception as e:
print("CMakeBuilder: Error: Could not load cmake's capabilities")
_capabilities = {"error": None}
return _capabilities.get(key, None)
raise KeyError("Capabilities called too early!")
elif "error" in _capabilities:
raise ValueError("Error loading capabilities")
else:
return _capabilities.get(key, None)
5 changes: 4 additions & 1 deletion support/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def __init__(self,
# type: Optional[Callable]
self.on_codemodel_done_handler = on_codemodel_done_handler

cmd = ["cmake", "-E", "server"]
settings = sublime.load_settings("CMakeBuilder.sublime-settings")
cmake_binary = settings.get("cmake_binary", "cmake")
cmd = [cmake_binary, "-E", "server"]
if experimental:
cmd.append("--experimental")
if debug:
Expand Down Expand Up @@ -205,6 +207,7 @@ def receive_dict(self, thedict):
t = thedict.pop("type")
if t == "hello":
self.supported_protocols = thedict.pop("supportedProtocolVersions")
print(self.supported_protocols)
self.send_handshake()
elif t == "reply":
self.receive_reply(thedict)
Expand Down

0 comments on commit 171dc98

Please sign in to comment.