Coverage for rust2rpm/vendor.py: 23%
22 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-27 15:21 +0100
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-27 15:21 +0100
1import os
2from pathlib import Path
3import shutil
4import subprocess
6from rust2rpm import log
9def generate_vendor_tarball(toml_path: str, project_name: str, project_version: str, dest_dir: Path) -> str:
10 tarball_name = f"{project_name}-{project_version}-vendor.tar.xz"
11 tarball_dest = dest_dir / tarball_name
13 if (tarball_dest).is_file():
14 log.info(f"Vendor tarball already exists: {tarball_name}")
15 log.info("To force re-generation of the vendor tarball, remove this file.")
16 return tarball_name
18 log.info("Generating vendor tarball ...")
20 ret = subprocess.run(
21 ["cargo", "vendor", "--versioned-dirs", "--manifest-path", toml_path, "vendor/"],
22 stdout=subprocess.PIPE,
23 stderr=subprocess.PIPE,
24 )
25 ret.check_returncode()
27 log.info("Compressing vendor tarball ...")
29 ret = subprocess.run(["tar", "-cJvf", tarball_name, "vendor/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
30 ret.check_returncode()
32 shutil.rmtree("vendor/")
34 if dest_dir != Path.cwd():
35 os.rename(tarball_name, tarball_dest)
37 return tarball_name