37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
|
|
from rust2rpm import log
|
|
|
|
|
|
def generate_vendor_tarball(toml_path: str, project_name: str, project_version: str, dest_dir: Path) -> str:
|
|
tarball_name = f"{project_name}-{project_version}-vendor.tar.xz"
|
|
tarball_dest = dest_dir / tarball_name
|
|
|
|
if (tarball_dest).is_file():
|
|
log.info(f"Vendor tarball already exists: {tarball_name}")
|
|
log.info("To force re-generation of the vendor tarball, remove this file.")
|
|
return tarball_name
|
|
|
|
log.info("Generating vendor tarball ...")
|
|
|
|
ret = subprocess.run(
|
|
["cargo", "vendor", "--versioned-dirs", "--manifest-path", toml_path, "vendor/"],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE,
|
|
)
|
|
ret.check_returncode()
|
|
|
|
log.info("Compressing vendor tarball ...")
|
|
|
|
ret = subprocess.run(["tar", "-cJvf", tarball_name, "vendor/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
ret.check_returncode()
|
|
|
|
shutil.rmtree("vendor/")
|
|
|
|
if dest_dir != Path.cwd():
|
|
os.rename(tarball_name, tarball_dest)
|
|
|
|
return tarball_name
|