Rust: move rust_sysroot_src to its own session fixture

This commit is contained in:
Paolo Tranquilli
2024-11-29 12:01:50 +01:00
parent 4bcc4254c6
commit 7e0e5a3f4e

View File

@@ -4,18 +4,24 @@ import commands
import pathlib
@pytest.fixture
def cargo(cwd):
assert (cwd / "Cargo.toml").exists()
(cwd / "rust-project.json").unlink(missing_ok=True)
@pytest.fixture(scope="session")
def rust_sysroot_src() -> str:
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library")
assert ret.exists()
return str(ret)
@pytest.fixture
def rust_project(cwd):
def rust_project(cwd, rust_sysroot_src):
project_file = cwd / "rust-project.json"
assert project_file.exists()
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
project = json.loads(project_file.read_text())
project["sysroot_src"] = str(rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library"))
project["sysroot_src"] = rust_sysroot_src
project_file.write_text(json.dumps(project, indent=4))
(cwd / "Cargo.toml").unlink(missing_ok=True)