[gnome-builder] rust: handle missing rustc a bit better



commit 643006dc6dd299bc741e42f8b377cefb5ac114b0
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 20 15:59:45 2017 -0800

    rust: handle missing rustc a bit better

 plugins/rust-langserv/rust_langserv_plugin.py |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/plugins/rust-langserv/rust_langserv_plugin.py b/plugins/rust-langserv/rust_langserv_plugin.py
index 6c1d088..4c6f8c4 100644
--- a/plugins/rust-langserv/rust_langserv_plugin.py
+++ b/plugins/rust-langserv/rust_langserv_plugin.py
@@ -77,8 +77,10 @@ class RustService(Ide.Object, Ide.Service):
             # Setup a launcher to spawn the rust language server
             launcher = self._create_launcher()
             launcher.set_clear_env(False)
-            launcher.setenv("SYS_ROOT", self._discover_sysroot(), True)
-            launcher.setenv("LD_LIBRARY_PATH", os.path.join(self._discover_sysroot(), "lib"), True)
+            sysroot = self._discover_sysroot()
+            if sysroot:
+                launcher.setenv("SYS_ROOT", sysroot, True)
+                launcher.setenv("LD_LIBRARY_PATH", os.path.join(sysroot, "lib"), True)
 
             # If rls was installed with Cargo, try to discover that
             # to save the user having to update PATH.
@@ -140,11 +142,15 @@ class RustService(Ide.Object, Ide.Service):
         get, by using `rust --print sysroot` as the rust-language-server
         documentation suggests.
         """
-        launcher = self._create_launcher()
-        launcher.push_args(['rustc', '--print', 'sysroot'])
-        subprocess = launcher.spawn()
-        _, stdout, _ = subprocess.communicate_utf8()
-        return stdout.strip()
+        for rustc in ['rustc', os.path.expanduser('~/.cargo/bin/rustc')]:
+            try:
+                launcher = self._create_launcher()
+                launcher.push_args([rustc, '--print', 'sysroot'])
+                subprocess = launcher.spawn()
+                _, stdout, _ = subprocess.communicate_utf8()
+                return stdout.strip()
+            except:
+                pass
 
     @classmethod
     def bind_client(klass, provider):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]