From 626962c48bbb150b3681d9911921d49ae4ed884f Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Tue, 6 Dec 2016 16:12:13 -0500 Subject: [PATCH] Let Rust plugin fetch dependencies in pull (#908) Pulling the dependencies in the pull stage allows building Rust snaps on Launchpad builders, which are offline during the build stage LP: #1647847 --- integration_tests/snaps/simple-rust/Cargo.toml | 1 + integration_tests/snaps/simple-rust/src/main.rs | 2 ++ snapcraft/plugins/rust.py | 12 ++++++++++++ snapcraft/tests/test_plugin_rust.py | 12 ++++-------- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/integration_tests/snaps/simple-rust/Cargo.toml b/integration_tests/snaps/simple-rust/Cargo.toml index 47a0d58ea0..68d321a4e6 100644 --- a/integration_tests/snaps/simple-rust/Cargo.toml +++ b/integration_tests/snaps/simple-rust/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" authors = ["Marius Gripsgard "] [dependencies] +log = "*" \ No newline at end of file diff --git a/integration_tests/snaps/simple-rust/src/main.rs b/integration_tests/snaps/simple-rust/src/main.rs index 17779d6ccd..be0f1582f5 100644 --- a/integration_tests/snaps/simple-rust/src/main.rs +++ b/integration_tests/snaps/simple-rust/src/main.rs @@ -1,3 +1,5 @@ +extern crate log; + fn main() { println!("There is rust on snaps!"); } diff --git a/snapcraft/plugins/rust.py b/snapcraft/plugins/rust.py index aef2146b37..feb3b5e3ed 100644 --- a/snapcraft/plugins/rust.py +++ b/snapcraft/plugins/rust.py @@ -54,6 +54,14 @@ def schema(cls): def __init__(self, name, options, project): super().__init__(name, options, project) + self.build_packages.extend([ + 'gcc', + 'binutils', + 'libc6-dev', + 'git', + 'curl', + 'file', + ]) self._rustpath = os.path.join(self.partdir, "rust") self._rustc = os.path.join(self._rustpath, "bin", "rustc") self._rustdoc = os.path.join(self._rustpath, "bin", "rustdoc") @@ -78,6 +86,7 @@ def _build_env(self): def pull(self): super().pull() self._fetch_rust() + self._fetch_deps() def clean_pull(self): super().clean_pull() @@ -104,3 +113,6 @@ def _fetch_rust(self): self.run(["%s" % self._rustup, "--prefix=%s" % self._rustpath, "--disable-sudo", "--save"]) + + def _fetch_deps(self): + self.run([self._cargo, "fetch"]) diff --git a/snapcraft/tests/test_plugin_rust.py b/snapcraft/tests/test_plugin_rust.py index c0ae81876b..3efc995f20 100644 --- a/snapcraft/tests/test_plugin_rust.py +++ b/snapcraft/tests/test_plugin_rust.py @@ -86,14 +86,10 @@ def test_pull(self, run_mock, script_mock): plugin.pull() - self.assertEqual(1, run_mock.call_count) - run_mock.assert_has_calls([ - mock.call(["%s" % plugin._rustup, - "--prefix=%s" % plugin._rustpath, - "--disable-sudo", "--save"]) - ]) + self.assertEqual(2, run_mock.call_count) rustdir = os.path.join(plugin.partdir, 'rust') - run_mock.assert_called_once_with([ + run_mock.assert_has_calls([mock.call([ os.path.join(rustdir, 'rustup.sh'), '--prefix={}'.format(rustdir), - '--disable-sudo', '--save']) + '--disable-sudo', '--save']), + mock.call([plugin._cargo, "fetch"])])