[gnome-builder] cargo: add dependency updater for cargo projects



commit 4b8d3338ba55ac24cba5a54786a82b8a8238918b
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 16 18:18:10 2017 -0800

    cargo: add dependency updater for cargo projects

 src/plugins/cargo/cargo_plugin.py |   51 +++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/cargo/cargo_plugin.py b/src/plugins/cargo/cargo_plugin.py
index adf462b..d422d4c 100644
--- a/src/plugins/cargo/cargo_plugin.py
+++ b/src/plugins/cargo/cargo_plugin.py
@@ -200,3 +200,54 @@ class CargoBuildTargetProvider(Ide.Object, Ide.BuildTargetProvider):
     def do_get_targets_finish(self, result):
         if result.propagate_boolean():
             return result.targets
+
+class CargoDependencyUpdater(Ide.Object, Ide.DependencyUpdater):
+
+    def do_update_async(self, cancellable, callback, data):
+        task = Gio.Task.new(self, cancellable, callback)
+        task.set_priority(GLib.PRIORITY_LOW)
+
+        context = self.get_context()
+        build_system = context.get_build_system()
+
+        # Short circuit if not using cargo
+        if type(build_system) != CargoBuildSystem:
+            task.return_boolean(True)
+            return
+
+        build_manager = context.get_build_manager()
+        pipeline = build_manager.get_pipeline()
+        if not pipeline:
+            task.return_error(GLib.Error('Cannot update dependencies without build pipeline',
+                                         domain=GLib.quark_to_string(Gio.io_error_quark()),
+                                         code=Gio.IOErrorEnum.FAILED))
+            return
+
+        config_manager = context.get_configuration_manager()
+        config = config_manager.get_current()
+        cargo = locate_cargo_from_config(config)
+
+        cargo_toml = build_system.props.project_file.get_path()
+
+        launcher = pipeline.create_launcher()
+        launcher.setenv('CARGO_TARGET_DIR', pipeline.get_builddir(), True)
+        launcher.push_argv(cargo)
+        launcher.push_argv('update')
+        launcher.push_argv('--manifest-path')
+        launcher.push_argv(cargo_toml)
+
+        try:
+            subprocess = launcher.spawn()
+            subprocess.wait_check_async(None, self.wait_check_cb, task)
+        except Exception as ex:
+            task.return_error(ex)
+
+    def do_update_finish(self, result):
+        return result.propagate_boolean()
+
+    def wait_check_cb(self, subprocess, result, task):
+        try:
+            subprocess.wait_check_finish(result)
+            task.return_boolean(True)
+        except Exception as ex:
+            task.return_error(ex)


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