diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-08-13 13:49:45 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-14 09:35:56 -0700 |
| commit | c97970a3c476df05984f171fae74b21fb07a7428 (patch) | |
| tree | 527a9e6b5a6ef36e5e57e1f0ccf4479b1f80f07b /unittests | |
| parent | dece20658f96c2682240506c7d3acf7c2ddabd83 (diff) | |
| download | meson-c97970a3c476df05984f171fae74b21fb07a7428.tar.gz | |
cargo: load a single Cargo.lock for a whole chain of subprojects
When processing cargo subprojects, each Resolver was independently
loading Cargo.lock files, leading to duplicate wraps and errors like
'Multiple wrap files provide dependency'.
Instead, build the cargo.Interpreter as soon as a Cargo.lock file is
found, and merge that Cargo.lock into the wrap resolver. There is no
need anymore to build a separate resolver for the dependent packages,
because their indirect dependencies are all listed in the parent lockfile.
Diffstat (limited to 'unittests')
| -rw-r--r-- | unittests/cargotests.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/unittests/cargotests.py b/unittests/cargotests.py index 96a7b81ee..01d326130 100644 --- a/unittests/cargotests.py +++ b/unittests/cargotests.py @@ -8,8 +8,9 @@ import tempfile import textwrap import typing as T -from mesonbuild.cargo import cfg, load_wraps +from mesonbuild.cargo import cfg from mesonbuild.cargo.cfg import TokenType +from mesonbuild.cargo.interpreter import load_cargo_lock from mesonbuild.cargo.manifest import Dependency, Manifest, Package, Workspace from mesonbuild.cargo.toml import load_toml from mesonbuild.cargo.version import convert @@ -179,9 +180,10 @@ class CargoCfgTest(unittest.TestCase): self.assertEqual(value, expected) class CargoLockTest(unittest.TestCase): - def test_cargo_lock(self) -> None: + def test_wraps(self) -> None: with tempfile.TemporaryDirectory() as tmpdir: - with open(os.path.join(tmpdir, 'Cargo.lock'), 'w', encoding='utf-8') as f: + filename = os.path.join(tmpdir, 'Cargo.lock') + with open(filename, 'w', encoding='utf-8') as f: f.write(textwrap.dedent('''\ version = 3 [[package]] @@ -198,21 +200,22 @@ class CargoLockTest(unittest.TestCase): version = "0.1" source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=0.19#23c5599424cc75ec66618891c915d9f490f6e4c2" ''')) - wraps = load_wraps(tmpdir, 'subprojects') + cargolock = load_cargo_lock(filename, 'subprojects') + wraps = cargolock.wraps self.assertEqual(len(wraps), 2) - self.assertEqual(wraps[0].name, 'foo-0.1-rs') - self.assertEqual(wraps[0].directory, 'foo-0.1') - self.assertEqual(wraps[0].type, 'file') - self.assertEqual(wraps[0].get('method'), 'cargo') - self.assertEqual(wraps[0].get('source_url'), 'https://crates.io/api/v1/crates/foo/0.1/download') - self.assertEqual(wraps[0].get('source_hash'), '8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb') - self.assertEqual(wraps[1].name, 'gtk-rs-core-0.19') - self.assertEqual(wraps[1].directory, 'gtk-rs-core-0.19') - self.assertEqual(wraps[1].type, 'git') - self.assertEqual(wraps[1].get('method'), 'cargo') - self.assertEqual(wraps[1].get('url'), 'https://github.com/gtk-rs/gtk-rs-core') - self.assertEqual(wraps[1].get('revision'), '23c5599424cc75ec66618891c915d9f490f6e4c2') - self.assertEqual(list(wraps[1].provided_deps), ['gtk-rs-core-0.19', 'bar-0.1-rs', 'member-0.1-rs']) + self.assertEqual(wraps['foo-0.1-rs'].name, 'foo-0.1-rs') + self.assertEqual(wraps['foo-0.1-rs'].directory, 'foo-0.1') + self.assertEqual(wraps['foo-0.1-rs'].type, 'file') + self.assertEqual(wraps['foo-0.1-rs'].get('method'), 'cargo') + self.assertEqual(wraps['foo-0.1-rs'].get('source_url'), 'https://crates.io/api/v1/crates/foo/0.1/download') + self.assertEqual(wraps['foo-0.1-rs'].get('source_hash'), '8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb') + self.assertEqual(wraps['gtk-rs-core-0.19'].name, 'gtk-rs-core-0.19') + self.assertEqual(wraps['gtk-rs-core-0.19'].directory, 'gtk-rs-core-0.19') + self.assertEqual(wraps['gtk-rs-core-0.19'].type, 'git') + self.assertEqual(wraps['gtk-rs-core-0.19'].get('method'), 'cargo') + self.assertEqual(wraps['gtk-rs-core-0.19'].get('url'), 'https://github.com/gtk-rs/gtk-rs-core') + self.assertEqual(wraps['gtk-rs-core-0.19'].get('revision'), '23c5599424cc75ec66618891c915d9f490f6e4c2') + self.assertEqual(list(wraps['gtk-rs-core-0.19'].provided_deps), ['gtk-rs-core-0.19', 'bar-0.1-rs', 'member-0.1-rs']) class CargoTomlTest(unittest.TestCase): CARGO_TOML_1 = textwrap.dedent('''\ |
