Skip to content

Commit

Permalink
Let Rust plugin fetch dependencies in pull (canonical#908)
Browse files Browse the repository at this point in the history
Pulling the dependencies in the pull stage allows
building Rust snaps on Launchpad builders,
which are offline during the build stage

LP: #1647847
  • Loading branch information
ChrisMacNaughton authored and kyrofa committed Dec 6, 2016
1 parent f9d64c3 commit 626962c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions integration_tests/snaps/simple-rust/Cargo.toml
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
authors = ["Marius Gripsgard <mariogrip@ubuntu.com>"]

[dependencies]
log = "*"
2 changes: 2 additions & 0 deletions integration_tests/snaps/simple-rust/src/main.rs
@@ -1,3 +1,5 @@
extern crate log;

fn main() {
println!("There is rust on snaps!");
}
12 changes: 12 additions & 0 deletions snapcraft/plugins/rust.py
Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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"])
12 changes: 4 additions & 8 deletions snapcraft/tests/test_plugin_rust.py
Expand Up @@ -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"])])

0 comments on commit 626962c

Please sign in to comment.