Beispiel #1
0
    def test_cross_compile_with_rust_toolchain_file(self, mock_download):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, "rust-toolchain"), "w").close()

        plugin.pull()

        self.assertThat(self.run_mock.call_count, Equals(3))
        self.run_mock.assert_has_calls([
            mock.call(
                [
                    os.path.join(plugin._rust_dir, "rustup.sh"),
                    "-y",
                    "--no-modify-path",
                ],
                cwd=os.path.join(plugin.partdir, "build"),
                env=plugin._build_env(),
            ),
            mock.call(
                [plugin._rustup_cmd, "target", "add", self.target],
                cwd=plugin.builddir,
                env=plugin._build_env(),
            ),
            mock.call(
                [
                    plugin._cargo_cmd,
                    "fetch",
                    "--manifest-path",
                    os.path.join(plugin.sourcedir, "Cargo.toml"),
                ],
                cwd=plugin.builddir,
                env=plugin._build_env(),
            ),
        ])

        self.run_mock.reset_mock()

        plugin.build()

        self.assertThat(os.path.join(plugin.builddir, ".cargo", "config"),
                        FileExists())

        self.assertThat(self.run_mock.call_count, Equals(1))
        self.run_mock.assert_has_calls([
            mock.call(
                [
                    plugin._cargo_cmd,
                    "install",
                    "--path",
                    plugin.builddir,
                    "--root",
                    plugin.installdir,
                    "--force",
                    "--target",
                    self.target,
                ],
                cwd=os.path.join(plugin.partdir, "build"),
                env=plugin._build_env(),
            )
        ])
Beispiel #2
0
    def test_build_with_conditional_compilation(self, _, run_mock):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        plugin.options.rust_features = ["conditional-compilation"]
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.assertThat(run_mock.call_count, Equals(2))
        run_mock.assert_has_calls([
            mock.call(
                [
                    plugin._cargo,
                    "test",
                    "-j{}".format(plugin.project.parallel_build_count),
                    "--features",
                    "conditional-compilation",
                ],
                env=plugin._build_env(),
            ),
            mock.call(
                [
                    plugin._cargo,
                    "install",
                    "-j{}".format(plugin.project.parallel_build_count),
                    "--root",
                    plugin.installdir,
                    "--path",
                    plugin.builddir,
                    "--features",
                    "conditional-compilation",
                ],
                env=plugin._build_env(),
            ),
        ])
Beispiel #3
0
    def test_pull_with_rust_toolchain_file(self, script_mock):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, "rust-toolchain"), "w").close()

        plugin.options.rust_revision = []
        plugin.options.rust_channel = []

        plugin.pull()

        self.assertThat(self.run_mock.call_count, Equals(2))

        self.run_mock.assert_has_calls(
            [
                mock.call(
                    [
                        os.path.join(plugin._rust_dir, "rustup.sh"),
                        "-y",
                        "--no-modify-path",
                    ],
                    cwd=os.path.join(plugin.partdir, "build"),
                    env=plugin._build_env(),
                ),
                mock.call(
                    [
                        plugin._cargo_cmd,
                        "fetch",
                        "--manifest-path",
                        os.path.join(plugin.sourcedir, "Cargo.toml"),
                    ],
                    cwd=plugin.builddir,
                    env=plugin._build_env(),
                ),
            ]
        )
Beispiel #4
0
    def test_pull_with_revision(self, run_mock, script_mock):
        plugin = rust.RustPlugin("test-part", self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)
        plugin.options.rust_revision = "1.13.0"
        plugin.options.rust_channel = ""

        plugin.pull()

        self.assertThat(run_mock.call_count, Equals(2))

        rustdir = os.path.join(plugin.partdir, "rust")
        run_mock.assert_has_calls([
            mock.call([
                os.path.join(rustdir, "rustup.sh"),
                "--prefix={}".format(rustdir),
                "--disable-sudo",
                "--save",
                "--revision=1.13.0",
            ]),
            mock.call(
                [
                    plugin._cargo,
                    "fetch",
                    "--manifest-path",
                    os.path.join(plugin.sourcedir, "Cargo.toml"),
                ],
                env=plugin._build_env(),
            ),
        ])
Beispiel #5
0
    def test_build(self, _, run_mock):
        plugin = rust.RustPlugin("test-part", self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.assertThat(run_mock.call_count, Equals(2))
        run_mock.assert_has_calls([
            mock.call(
                [
                    plugin._cargo,
                    "test",
                    "-j{}".format(plugin.project.parallel_build_count),
                ],
                env=plugin._build_env(),
            ),
            mock.call(
                [
                    plugin._cargo,
                    "install",
                    "-j{}".format(plugin.project.parallel_build_count),
                    "--root",
                    plugin.installdir,
                    "--path",
                    plugin.builddir,
                ],
                env=plugin._build_env(),
            ),
        ])
Beispiel #6
0
    def test_get_manifest_with_unexisting_cargo_lock(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertThat(plugin.get_manifest(), Not(Contains("cargo-lock-contents")))
Beispiel #7
0
    def test_get_manifest_with_cargo_lock_dir(self, *_):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        os.makedirs(plugin.builddir)

        os.mkdir(os.path.join(plugin.builddir, "Cargo.lock"))

        plugin.build()

        self.assertThat(plugin.get_manifest(), Not(Contains("cargo-lock-contents")))
Beispiel #8
0
    def test_get_manifest_with_cargo_lock_file(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        os.makedirs(plugin.builddir)

        with open(os.path.join(plugin.builddir, "Cargo.lock"), "w") as cargo_lock_file:
            cargo_lock_file.write("test cargo lock contents")

        plugin.build()

        self.assertThat(
            plugin.get_manifest()["cargo-lock-contents"],
            Equals("test cargo lock contents"),
        )
Beispiel #9
0
    def test_get_manifest_with_cargo_lock_file(self, *_):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)
        os.makedirs(plugin.builddir)

        with open(os.path.join(plugin.builddir, 'Cargo.lock'),
                  'w') as cargo_lock_file:
            cargo_lock_file.write('test cargo lock contents')

        plugin.build()

        self.assertThat(plugin.get_manifest()['cargo-lock-contents'],
                        Equals('test cargo lock contents'))
Beispiel #10
0
    def test_pull_with_source_and_source_subdir(self, run_mock, script_mock):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)
        plugin.options.source_subdir = 'test-subdir'

        plugin.pull()

        run_mock.assert_has_calls([
            mock.ANY,
            mock.call([
                plugin._cargo, 'fetch', '--manifest-path',
                os.path.join(plugin.sourcedir, 'test-subdir', 'Cargo.toml')
            ])
        ])
Beispiel #11
0
    def test_cross_compile(self, mock_download):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)

        plugin.enable_cross_compilation()
        self.assertThat(plugin._target, Equals(self.target))

        plugin.pull()
        mock_download.assert_called_once_with()
        self.assertThat(self.run_mock.call_count, Equals(2))
        self.run_mock.assert_has_calls([
            mock.call(
                [plugin._rustup,
                 '--prefix={}'.format(os.path.join(plugin._rustpath)),
                 '--disable-sudo',
                 '--save',
                 '--with-target={}'.format(self.target)],
                cwd=os.path.join(plugin.partdir, 'build')),
            mock.call(
                [plugin._cargo, 'fetch',
                 '--manifest-path',
                 os.path.join(plugin.sourcedir, 'Cargo.toml')],
                cwd=os.path.join(plugin.partdir, 'build')),
        ])

        plugin.build()
        self.assertThat(os.path.join(plugin._cargo_dir, 'config'),
                        FileExists())

        self.assertThat(self.run_mock.call_count, Equals(3))
        self.run_mock.assert_has_calls([
            mock.call(
                [plugin._cargo, 'install',
                 '-j{}'.format(plugin.project.parallel_build_count),
                 '--root', plugin.installdir,
                 '--path', plugin.builddir],
                cwd=os.path.join(plugin.partdir, 'build'),
                env=plugin._build_env())
        ])

        plugin.clean_build()
        self.assertThat(plugin._cargo_dir, Not(DirExists()))
        plugin.clean_pull()
        self.assertThat(plugin._rustpath, Not(DirExists()))
        # Cleaning again shouldn't raise an exception
        plugin.clean_build()
        plugin.clean_pull()
Beispiel #12
0
    def test_pull(self, run_mock):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)
        plugin.options.rust_revision = []
        plugin.options.rust_channel = []

        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"
            ])
        ])
Beispiel #13
0
    def test_build(self, _, run_mock):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.assertThat(run_mock.call_count, Equals(1))
        run_mock.assert_has_calls([
            mock.call([
                plugin._cargo, 'install', '-j{}'.format(
                    plugin.project.parallel_build_count), '--root',
                plugin.installdir, '--path', plugin.builddir
            ],
                      env=plugin._build_env())
        ])
Beispiel #14
0
    def setUp(self):
        super().setUp()

        self.useFixture(fixture_setup.CleanEnvironment())

        class Options:
            makefile = None
            make_parameters = []
            rust_features = []
            rust_revision = ""
            rust_channel = ""
            source_subdir = ""

        self.options = Options()

        patcher = mock.patch("snapcraft.internal.common.run")
        self.run_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch("snapcraft.internal.common.run_output")
        patcher.start()
        self.addCleanup(patcher.stop)

        original_exists = os.path.exists

        def exists_mock(*args, **kwargs):
            if args[0].endswith("rustup"):
                return False
            else:
                return original_exists(args[0])

        patcher = mock.patch("os.path.exists", side_effect=exists_mock)
        patcher.start()
        self.addCleanup(patcher.stop)

        self.project = snapcraft.project.Project(
            snapcraft_yaml_file_path=self.make_snapcraft_yaml(
                textwrap.dedent("""\
                    name: test-snap
                    base: core16
                    """)))

        self.plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(self.plugin.sourcedir)
        os.makedirs(self.plugin.builddir)
        open(Path(self.plugin.builddir, "Cargo.toml"), "w").write("")
Beispiel #15
0
    def test_pull(self, run_mock, script_mock):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)
        plugin.options.rust_revision = []
        plugin.options.rust_channel = []

        plugin.pull()

        self.assertThat(run_mock.call_count, Equals(2))

        rustdir = os.path.join(plugin.partdir, 'rust')
        run_mock.assert_has_calls([mock.call([
            os.path.join(rustdir, 'rustup.sh'), '--prefix={}'.format(rustdir),
            '--disable-sudo', '--save']),
            mock.call([plugin._cargo, 'fetch',
                       '--manifest-path',
                       os.path.join(plugin.sourcedir, 'Cargo.toml')])])
Beispiel #16
0
    def test_build_with_conditional_compilation(self, run_mock):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        plugin.options.rust_features = ['conditional-compilation']
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.assertThat(run_mock.call_count, Equals(1))
        run_mock.assert_has_calls([
            mock.call([
                plugin._cargo, 'install', '-j{}'.format(
                    plugin.project.parallel_build_count), '--root',
                plugin.installdir, '--path', plugin.builddir, '--features',
                'conditional-compilation'
            ],
                      env=plugin._build_env())
        ])
Beispiel #17
0
    def test_build(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.run_mock.assert_called_once_with(
            [
                plugin._cargo_cmd,
                "+stable",
                "install",
                "--path",
                plugin.builddir,
                "--root",
                plugin.installdir,
            ],
            cwd=os.path.join(plugin.partdir, "build"),
            env=plugin._build_env(),
        )
Beispiel #18
0
    def test_build_with_rust_toolchain_file(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, "rust-toolchain"), "w").close()

        plugin.build()

        self.run_mock.assert_called_once_with(
            [
                plugin._cargo_cmd,
                "install",
                "--path",
                plugin.builddir,
                "--root",
                plugin.installdir,
            ],
            cwd=os.path.join(plugin.partdir, "build"),
            env=plugin._build_env(),
        )
Beispiel #19
0
    def test_pull_with_source_and_source_subdir(self, run_mock, script_mock):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        plugin.options.source_subdir = "test-subdir"

        plugin.pull()

        run_mock.assert_has_calls([
            mock.ANY,
            mock.call(
                [
                    plugin._cargo,
                    "fetch",
                    "--manifest-path",
                    os.path.join(plugin.sourcedir, "test-subdir",
                                 "Cargo.toml"),
                ],
                env=plugin._build_env(),
            ),
        ])
Beispiel #20
0
    def test_pull_with_revision(self, script_mock):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        plugin.options.rust_revision = "1.13.0"
        plugin.options.rust_channel = ""

        plugin.pull()

        self.assertThat(self.run_mock.call_count, Equals(3))

        self.run_mock.assert_has_calls(
            [
                mock.call(
                    [
                        os.path.join(plugin._rust_dir, "rustup.sh"),
                        "-y",
                        "--no-modify-path",
                        "--default-toolchain",
                        "none",
                    ],
                    cwd=os.path.join(plugin.partdir, "build"),
                    env=plugin._build_env(),
                ),
                mock.call(
                    [plugin._rustup_cmd, "install", "1.13.0"],
                    cwd=plugin.builddir,
                    env=plugin._build_env(),
                ),
                mock.call(
                    [
                        plugin._cargo_cmd,
                        "+1.13.0",
                        "fetch",
                        "--manifest-path",
                        os.path.join(plugin.sourcedir, "Cargo.toml"),
                    ],
                    cwd=plugin.builddir,
                    env=plugin._build_env(),
                ),
            ]
        )
Beispiel #21
0
    def test_write_cargo_config(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        config_toml_path = "config.toml"

        plugin._write_cargo_config(cargo_config_path=config_toml_path)

        self.assertThat(config_toml_path, FileExists())

        config = toml.load(config_toml_path)

        self.assertThat(
            config,
            Equals(
                dict(
                    rustdoc_cmd=plugin._rustdoc_cmd,
                    rustc_cmd=plugin._rustc_cmd,
                    arch_triplet=plugin.project.arch_triplet,
                    jobs=plugin.parallel_build_count,
                    target={plugin._get_target(): dict(linker=plugin._get_linker())},
                )
            ),
        )
Beispiel #22
0
    def test_get_manifest_with_versions(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)

        original_check_output = subprocess.check_output

        def side_effect(cmd, *args, **kwargs):
            if cmd[-1] == "--version":
                binary = os.path.basename(cmd[0])
                return "test {} version".format(binary)
            return original_check_output(cmd, *args, **kwargs)

        with mock.patch.object(rust.RustPlugin, "run_output") as run_output_mock:
            run_output_mock.side_effect = side_effect
            plugin.build()

        expected_manifest = collections.OrderedDict()
        expected_manifest["rustup-version"] = "test rustup version"
        expected_manifest["rustc-version"] = "test rustc version"
        expected_manifest["cargo-version"] = "test cargo version"

        self.assertThat(plugin.get_manifest(), Equals(expected_manifest))
Beispiel #23
0
    def test_build_with_conditional_compilation(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        plugin.options.rust_features = ["conditional-compilation"]
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.run_mock.assert_called_once_with(
            [
                plugin._cargo_cmd,
                "+stable",
                "install",
                "--path",
                plugin.builddir,
                "--root",
                plugin.installdir,
                "--features",
                "conditional-compilation",
            ],
            cwd=os.path.join(plugin.partdir, "build"),
            env=plugin._build_env(),
        )
Beispiel #24
0
    def test_pull(self, run_mock, script_mock):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)
        plugin.options.rust_revision = []
        plugin.options.rust_channel = []

        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"
            ])
        ])

        rustdir = os.path.join(plugin.partdir, 'rust')
        run_mock.assert_called_once_with([
            os.path.join(rustdir, 'rustup.sh'), '--prefix={}'.format(rustdir),
            '--disable-sudo', '--save'
        ])
Beispiel #25
0
    def test_pull_with_source_and_source_subdir(self, script_mock):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)
        plugin.options.source_subdir = "test-subdir"

        plugin.pull()

        self.assertThat(self.run_mock.call_count, Equals(3))

        self.run_mock.assert_has_calls([
            mock.call(
                [
                    os.path.join(plugin._rust_dir, "rustup.sh"),
                    "-y",
                    "--no-modify-path",
                ],
                cwd=os.path.join(plugin.partdir, "build"),
                env=plugin._build_env(),
            ),
            mock.call(
                [plugin._rustup_cmd, "install", "stable"],
                cwd=plugin.builddir,
                env=plugin._build_env(),
            ),
            mock.call(
                [
                    plugin._cargo_cmd,
                    "+stable",
                    "fetch",
                    "--manifest-path",
                    os.path.join(plugin.sourcedir, "test-subdir",
                                 "Cargo.toml"),
                ],
                cwd=plugin.builddir,
                env=plugin._build_env(),
            ),
        ])
Beispiel #26
0
    def test_get_manifest_with_versions(self, _):
        plugin = rust.RustPlugin('test-part', self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)

        original_check_output = subprocess.check_output

        def side_effect(cmd, *args, **kwargs):
            if cmd[-1] == '--version':
                binary = os.path.basename(cmd[-2])
                return 'test {} version'.format(binary)
            return original_check_output(cmd, *args, **kwargs)

        with mock.patch.object(rust.RustPlugin,
                               'run_output') as run_output_mock:
            run_output_mock.side_effect = side_effect
            plugin.build()

        expected_manifest = collections.OrderedDict()
        expected_manifest['rustup-version'] = 'test rustup.sh version'
        expected_manifest['rustc-version'] = 'test rustc version'
        expected_manifest['cargo-version'] = 'test cargo version'

        self.assertThat(plugin.get_manifest(), Equals(expected_manifest))
Beispiel #27
0
    def test_unsupported_target_arch_raises_exception(self):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)

        self.assertRaises(errors.SnapcraftEnvironmentError, plugin._get_target)
Beispiel #28
0
    def test_cross_compiling_unsupported_arch_raises_exception(self):
        plugin = rust.RustPlugin("test-part", self.options,
                                 self.project_options)
        os.makedirs(plugin.sourcedir)

        self.assertRaises(NotImplementedError, plugin.enable_cross_compilation)
Beispiel #29
0
    def test_cross_compile(self, mock_download):
        plugin = rust.RustPlugin("test-part", self.options, self.project)
        os.makedirs(plugin.sourcedir)

        plugin.enable_cross_compilation()
        self.assertThat(plugin._target, Equals(self.target))

        plugin.pull()
        mock_download.assert_called_once_with()
        self.assertThat(self.run_mock.call_count, Equals(2))
        self.run_mock.assert_has_calls([
            mock.call(
                [
                    plugin._rustup,
                    "--prefix={}".format(os.path.join(plugin._rustpath)),
                    "--disable-sudo",
                    "--save",
                    "--with-target={}".format(self.target),
                ],
                cwd=os.path.join(plugin.partdir, "build"),
            ),
            mock.call(
                [
                    plugin._cargo,
                    "fetch",
                    "--manifest-path",
                    os.path.join(plugin.sourcedir, "Cargo.toml"),
                ],
                cwd=os.path.join(plugin.partdir, "build"),
                env=plugin._build_env(),
            ),
        ])

        plugin.build()
        self.assertThat(os.path.join(plugin._cargo_dir, "config"),
                        FileExists())
        self.assertThat(self.run_mock.call_count, Equals(3))
        self.run_mock.assert_has_calls([
            mock.call(
                [
                    plugin._cargo,
                    "install",
                    "-j{}".format(plugin.project.parallel_build_count),
                    "--root",
                    plugin.installdir,
                    "--path",
                    plugin.builddir,
                    "--target",
                    plugin._target,
                ],
                cwd=os.path.join(plugin.partdir, "build"),
                env=plugin._build_env(),
            )
        ])

        plugin.clean_build()
        self.assertThat(plugin._cargo_dir, Not(DirExists()))
        plugin.clean_pull()
        self.assertThat(plugin._rustpath, Not(DirExists()))
        # Cleaning again shouldn't raise an exception
        plugin.clean_build()
        plugin.clean_pull()
Beispiel #30
0
    def test_cross_compile_with_rust_toolchain_file(self, mock_download):
        self.project = snapcraft.project.Project(
            target_deb_arch=self.deb_arch,
            snapcraft_yaml_file_path=self.make_snapcraft_yaml(
                textwrap.dedent("""\
                    name: test-snap
                    base: core16
                    """)),
        )

        self.plugin = rust.RustPlugin("test-part", self.options, self.project)
        open(os.path.join(self.plugin.sourcedir, "rust-toolchain"),
             "w").close()

        self.plugin.pull()

        self.assertThat(self.run_mock.call_count, Equals(3))
        self.run_mock.assert_has_calls([
            mock.call(
                [
                    os.path.join(self.plugin._rustup_dir, "rustup.sh"),
                    "-y",
                    "--no-modify-path",
                    "--profile=minimal",
                ],
                cwd=os.path.join(self.plugin.partdir, "build"),
                env=self.plugin._build_env(),
            ),
            mock.call(
                [self.plugin._rustup_cmd, "target", "add", self.target],
                cwd=self.plugin.builddir,
                env=self.plugin._build_env(),
            ),
            mock.call(
                [
                    self.plugin._cargo_cmd,
                    "fetch",
                    "--manifest-path",
                    os.path.join(self.plugin.sourcedir, "Cargo.toml"),
                ],
                cwd=self.plugin.builddir,
                env=self.plugin._build_env(),
            ),
        ])

        self.run_mock.reset_mock()

        self.plugin.build()

        self.assertThat(os.path.join(self.plugin.builddir, ".cargo", "config"),
                        FileExists())

        self.assertThat(self.run_mock.call_count, Equals(1))
        self.run_mock.assert_has_calls([
            mock.call(
                [
                    self.plugin._cargo_cmd,
                    "install",
                    "--path",
                    self.plugin.builddir,
                    "--root",
                    self.plugin.installdir,
                    "--force",
                    "--target",
                    self.target,
                ],
                cwd=os.path.join(self.plugin.partdir, "build"),
                env=self.plugin._build_env(),
            )
        ])