Skip to content

Commit cd0c8b5

Browse files
author
Chris Patterson
committed
rust plugin: genericize fetching cargo deps
To support workspaces, simply issue "cargo fetch" from the build directory. Should support both workspaces and non-worskpace use. `cargo fetch` will honor Cargo.lock by default. Update tests accordingly. Signed-off-by: Chris Patterson <[email protected]>
1 parent 2252dd7 commit cd0c8b5

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

snapcraft/plugins/rust.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,11 @@ def _fetch_rust(self) -> None:
158158
self.run(add_target_cmd, env=self._build_env())
159159

160160
def _fetch_cargo_deps(self):
161-
if self.options.source_subdir:
162-
sourcedir = os.path.join(self.sourcedir, self.options.source_subdir)
163-
else:
164-
sourcedir = self.sourcedir
165-
166-
fetch_cmd = [
167-
self._cargo_cmd,
168-
"fetch",
169-
"--manifest-path",
170-
os.path.join(sourcedir, "Cargo.toml"),
171-
]
161+
fetch_cmd = [self._cargo_cmd, "fetch"]
172162
toolchain = self._get_toolchain()
173163
if toolchain is not None:
174164
fetch_cmd.insert(1, "+{}".format(toolchain))
175-
self.run(fetch_cmd, env=self._build_env())
165+
self.run(fetch_cmd, env=self._build_env(), cwd=self.builddir)
176166

177167
def _get_target(self) -> str:
178168
# Cf. rustc --print target-list

tests/unit/plugins/test_rust.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ def test_cross_compile(self, mock_download):
193193
plugin._cargo_cmd,
194194
"+stable",
195195
"fetch",
196-
"--manifest-path",
197-
os.path.join(plugin.sourcedir, "Cargo.toml"),
198196
],
199197
cwd=plugin.builddir,
200198
env=plugin._build_env(),
@@ -259,8 +257,6 @@ def test_cross_compile_with_rust_toolchain_file(self, mock_download):
259257
[
260258
plugin._cargo_cmd,
261259
"fetch",
262-
"--manifest-path",
263-
os.path.join(plugin.sourcedir, "Cargo.toml"),
264260
],
265261
cwd=plugin.builddir,
266262
env=plugin._build_env(),
@@ -348,8 +344,6 @@ def test_pull(self, script_mock):
348344
plugin._cargo_cmd,
349345
"+stable",
350346
"fetch",
351-
"--manifest-path",
352-
os.path.join(plugin.sourcedir, "Cargo.toml"),
353347
],
354348
cwd=plugin.builddir,
355349
env=plugin._build_env(),
@@ -385,8 +379,6 @@ def test_pull_with_rust_toolchain_file(self, script_mock):
385379
[
386380
plugin._cargo_cmd,
387381
"fetch",
388-
"--manifest-path",
389-
os.path.join(plugin.sourcedir, "Cargo.toml"),
390382
],
391383
cwd=plugin.builddir,
392384
env=plugin._build_env(),
@@ -428,8 +420,6 @@ def test_pull_with_channel(self, script_mock):
428420
plugin._cargo_cmd,
429421
"+nightly",
430422
"fetch",
431-
"--manifest-path",
432-
os.path.join(plugin.sourcedir, "Cargo.toml"),
433423
],
434424
cwd=plugin.builddir,
435425
env=plugin._build_env(),
@@ -471,8 +461,6 @@ def test_pull_with_revision(self, script_mock):
471461
plugin._cargo_cmd,
472462
"+1.13.0",
473463
"fetch",
474-
"--manifest-path",
475-
os.path.join(plugin.sourcedir, "Cargo.toml"),
476464
],
477465
cwd=plugin.builddir,
478466
env=plugin._build_env(),
@@ -513,8 +501,6 @@ def test_pull_with_source_and_source_subdir(self, script_mock):
513501
plugin._cargo_cmd,
514502
"+stable",
515503
"fetch",
516-
"--manifest-path",
517-
os.path.join(plugin.sourcedir, "test-subdir", "Cargo.toml"),
518504
],
519505
cwd=plugin.builddir,
520506
env=plugin._build_env(),

0 commit comments

Comments
 (0)