|
16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | 17 |
|
18 | 18 | import collections
|
| 19 | +from pathlib import Path |
19 | 20 | import os
|
20 | 21 | import subprocess
|
21 | 22 | import textwrap
|
@@ -189,11 +190,7 @@ def test_cross_compile(self, mock_download):
|
189 | 190 | env=plugin._build_env(),
|
190 | 191 | ),
|
191 | 192 | mock.call(
|
192 |
| - [ |
193 |
| - plugin._cargo_cmd, |
194 |
| - "+stable", |
195 |
| - "fetch", |
196 |
| - ], |
| 193 | + [plugin._cargo_cmd, "+stable", "fetch"], |
197 | 194 | cwd=plugin.builddir,
|
198 | 195 | env=plugin._build_env(),
|
199 | 196 | ),
|
@@ -254,10 +251,7 @@ def test_cross_compile_with_rust_toolchain_file(self, mock_download):
|
254 | 251 | env=plugin._build_env(),
|
255 | 252 | ),
|
256 | 253 | mock.call(
|
257 |
| - [ |
258 |
| - plugin._cargo_cmd, |
259 |
| - "fetch", |
260 |
| - ], |
| 254 | + [plugin._cargo_cmd, "fetch"], |
261 | 255 | cwd=plugin.builddir,
|
262 | 256 | env=plugin._build_env(),
|
263 | 257 | ),
|
@@ -340,11 +334,7 @@ def test_pull(self, script_mock):
|
340 | 334 | env=plugin._build_env(),
|
341 | 335 | ),
|
342 | 336 | mock.call(
|
343 |
| - [ |
344 |
| - plugin._cargo_cmd, |
345 |
| - "+stable", |
346 |
| - "fetch", |
347 |
| - ], |
| 337 | + [plugin._cargo_cmd, "+stable", "fetch"], |
348 | 338 | cwd=plugin.builddir,
|
349 | 339 | env=plugin._build_env(),
|
350 | 340 | ),
|
@@ -376,10 +366,7 @@ def test_pull_with_rust_toolchain_file(self, script_mock):
|
376 | 366 | env=plugin._build_env(),
|
377 | 367 | ),
|
378 | 368 | mock.call(
|
379 |
| - [ |
380 |
| - plugin._cargo_cmd, |
381 |
| - "fetch", |
382 |
| - ], |
| 369 | + [plugin._cargo_cmd, "fetch"], |
383 | 370 | cwd=plugin.builddir,
|
384 | 371 | env=plugin._build_env(),
|
385 | 372 | ),
|
@@ -416,11 +403,7 @@ def test_pull_with_channel(self, script_mock):
|
416 | 403 | env=plugin._build_env(),
|
417 | 404 | ),
|
418 | 405 | mock.call(
|
419 |
| - [ |
420 |
| - plugin._cargo_cmd, |
421 |
| - "+nightly", |
422 |
| - "fetch", |
423 |
| - ], |
| 406 | + [plugin._cargo_cmd, "+nightly", "fetch"], |
424 | 407 | cwd=plugin.builddir,
|
425 | 408 | env=plugin._build_env(),
|
426 | 409 | ),
|
@@ -457,11 +440,7 @@ def test_pull_with_revision(self, script_mock):
|
457 | 440 | env=plugin._build_env(),
|
458 | 441 | ),
|
459 | 442 | mock.call(
|
460 |
| - [ |
461 |
| - plugin._cargo_cmd, |
462 |
| - "+1.13.0", |
463 |
| - "fetch", |
464 |
| - ], |
| 443 | + [plugin._cargo_cmd, "+1.13.0", "fetch"], |
465 | 444 | cwd=plugin.builddir,
|
466 | 445 | env=plugin._build_env(),
|
467 | 446 | ),
|
@@ -497,11 +476,7 @@ def test_pull_with_source_and_source_subdir(self, script_mock):
|
497 | 476 | env=plugin._build_env(),
|
498 | 477 | ),
|
499 | 478 | mock.call(
|
500 |
| - [ |
501 |
| - plugin._cargo_cmd, |
502 |
| - "+stable", |
503 |
| - "fetch", |
504 |
| - ], |
| 479 | + [plugin._cargo_cmd, "+stable", "fetch"], |
505 | 480 | cwd=plugin.builddir,
|
506 | 481 | env=plugin._build_env(),
|
507 | 482 | ),
|
@@ -536,6 +511,53 @@ def test_build(self):
|
536 | 511 | env=plugin._build_env(),
|
537 | 512 | )
|
538 | 513 |
|
| 514 | + def test_install_workspace_artifacts(self): |
| 515 | + plugin = rust.RustPlugin("test-part", self.options, self.project) |
| 516 | + release_path = Path(plugin.builddir, "target", "release") |
| 517 | + os.makedirs(release_path, exist_ok=True) |
| 518 | + |
| 519 | + p_nonexec = Path(release_path / "nonexec") |
| 520 | + open(p_nonexec, "w").write("") |
| 521 | + p_nonexec.chmod(0o664) |
| 522 | + |
| 523 | + p_exec = Path(release_path / "exec") |
| 524 | + open(p_exec, "w").write("") |
| 525 | + p_exec.chmod(0o755) |
| 526 | + |
| 527 | + p_exec_so = Path(release_path / "exec.so") |
| 528 | + open(p_exec_so, "w").write("") |
| 529 | + p_exec_so.chmod(0o755) |
| 530 | + |
| 531 | + plugin._install_workspace_artifacts() |
| 532 | + |
| 533 | + bindir = Path(plugin.installdir, "bin") |
| 534 | + bins = list(bindir.iterdir()) |
| 535 | + |
| 536 | + libdir = Path(plugin.installdir, "usr", "lib", self.project.arch_triplet) |
| 537 | + libs = list(libdir.iterdir()) |
| 538 | + |
| 539 | + self.assertThat(bins, Equals([bindir / "exec"])) |
| 540 | + self.assertThat(libs, Equals([libdir / "exec.so"])) |
| 541 | + |
| 542 | + def test_build_workspace(self): |
| 543 | + plugin = rust.RustPlugin("test-part", self.options, self.project) |
| 544 | + os.makedirs(plugin.sourcedir) |
| 545 | + |
| 546 | + os.makedirs(plugin.builddir, exist_ok=True) |
| 547 | + cargo_path = Path(plugin.builddir, "Cargo.toml") |
| 548 | + with open(cargo_path, "w") as cargo_file: |
| 549 | + cargo_file.write("[workspace]" + os.linesep) |
| 550 | + release_path = Path(plugin.builddir, "target", "release") |
| 551 | + os.makedirs(release_path, exist_ok=True) |
| 552 | + |
| 553 | + plugin.build() |
| 554 | + |
| 555 | + self.run_mock.assert_called_once_with( |
| 556 | + [plugin._cargo_cmd, "+stable", "build", "--release"], |
| 557 | + cwd=os.path.join(plugin.partdir, "build"), |
| 558 | + env=plugin._build_env(), |
| 559 | + ) |
| 560 | + |
539 | 561 | def test_build_with_rust_toolchain_file(self):
|
540 | 562 | plugin = rust.RustPlugin("test-part", self.options, self.project)
|
541 | 563 | os.makedirs(plugin.sourcedir)
|
|
0 commit comments