Skip to content

Commit

Permalink
fix: it should be using custom_root and not setup_workdir
Browse files Browse the repository at this point in the history
Signed-off-by: Soc Virnyl Estela <contact@uncomfyhalomacro.pl>
  • Loading branch information
uncomfyhalomacro committed Dec 18, 2024
1 parent add2b41 commit d742d0c
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion cargo/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,28 @@ pub fn run_cargo_vendor_home_registry(
custom_root: &Path,
registry: &Opts,
) -> io::Result<()> {

debug!(?registry);
info!("🛖🏃📦 Starting Cargo Vendor Home Registry");

let tempdir_for_home_registry_binding = tempfile::Builder::new()
.prefix(".cargo")
.rand_bytes(12)
.tempdir()?;

let home_registry = &tempdir_for_home_registry_binding.path();
let home_registry_dot_cargo = &home_registry.join(".cargo");
let mut global_has_deps = false;
std::env::set_var("CARGO_HOME", home_registry_dot_cargo);

let res = {
debug!(?home_registry_dot_cargo);
if !registry.no_root_manifest {
let possible_root_manifest = custom_root.join("Cargo.toml");
if possible_root_manifest.is_file() {
let is_workspace = is_workspace(&possible_root_manifest)?;
let has_deps = has_dependencies(&possible_root_manifest)?;

if is_workspace {
info!("ℹ️ This manifest is in WORKSPACE configuration.");
let workspace_has_deps =
Expand All @@ -53,29 +58,36 @@ pub fn run_cargo_vendor_home_registry(
info!("🎉 No other manifests. No dependencies. Nothing to vendor.");
}
}

global_has_deps = has_deps || global_has_deps;
let possible_root_manifest_parent = possible_root_manifest
.parent()
.unwrap_or(custom_root)
.canonicalize()?;

cargo_update(
registry.update,
&registry.update_crate,
&possible_root_manifest_parent,
&possible_root_manifest.to_string_lossy(),
registry.respect_lockfile,
)?;

info!(?setup_workdir, "🌳 Finished setting up workdir.");
info!("🚝 Attempting to fetch dependencies.");

cargo_fetch(
&possible_root_manifest_parent,
&possible_root_manifest.to_string_lossy(),
registry.respect_lockfile,
)?;

info!("💼 Fetched dependencies.");
}
}

let mut lockfiles: Vec<PathBuf> = Vec::new();

for manifest in &registry.manifest_path {
if !manifest.ends_with("Cargo.toml") {
let msg = format!(
Expand All @@ -85,8 +97,10 @@ pub fn run_cargo_vendor_home_registry(
error!(?manifest, msg);
return Err(io::Error::new(io::ErrorKind::InvalidInput, msg));
}

let full_manifest_path = &custom_root.join(manifest);
let full_manifest_path_parent = full_manifest_path.parent().unwrap_or(setup_workdir);
let full_manifest_path_parent = full_manifest_path.parent().unwrap_or(custom_root);

if full_manifest_path.is_file() {
let is_workspace = is_workspace(full_manifest_path)?;
let has_deps = has_dependencies(full_manifest_path)?;
Expand All @@ -103,38 +117,46 @@ pub fn run_cargo_vendor_home_registry(
info!("😄 This extra manifest does not seem to have any dependencies.");
info!("🙂 If you think this is a BUG 🐞, please open an issue at <https://github.com/openSUSE-Rust/obs-service-cargo/issues>.");
}

global_has_deps = has_deps || global_has_deps;

if registry.update {
info!(
?full_manifest_path,
"⏫ Updating dependencies for extra manifest path..."
);
}

cargo_update(
registry.update,
&registry.update_crate,
full_manifest_path_parent,
&full_manifest_path.to_string_lossy(),
registry.respect_lockfile,
)?;

if registry.update {
info!(
?full_manifest_path,
"✅ Updated dependencies for extra manifest path."
);
}

if !registry.update {
warn!("😥 Disabled update of dependencies. You should enable this for security updates.");
}

info!(
?full_manifest_path,
"🚝 Attempting to fetch dependencies at extra manifest path..."
);

cargo_fetch(
full_manifest_path_parent,
&full_manifest_path.to_string_lossy(),
registry.respect_lockfile,
)?;

info!(
?full_manifest_path,
"💼 Fetched dependencies for extra manifest path."
Expand All @@ -144,10 +166,12 @@ pub fn run_cargo_vendor_home_registry(
error!(?err);
return Err(err);
}

let possible_lockfile = full_manifest_path_parent.join("Cargo.lock");
let possible_lockfile = &possible_lockfile
.canonicalize()
.unwrap_or(possible_lockfile.to_path_buf());

if possible_lockfile.exists() {
info!(
?possible_lockfile,
Expand All @@ -166,6 +190,7 @@ pub fn run_cargo_vendor_home_registry(
);
lockfiles.push(possible_lockfile.to_path_buf());
}

}

if !registry.no_root_manifest {
Expand All @@ -192,7 +217,9 @@ pub fn run_cargo_vendor_home_registry(
}
lockfiles.push(possible_root_lockfile.to_path_buf());
}

info!("🛡️🫥 Auditing lockfiles...");

if let Ok(audit_result) =
audit::perform_cargo_audit(&lockfiles, &registry.i_accept_the_risk)
{
Expand All @@ -201,27 +228,33 @@ pub fn run_cargo_vendor_home_registry(
io::Error::new(io::ErrorKind::Interrupted, err.to_string())
})?;
}

info!("🛡️🙂 All lockfiles are audited");
info!("👉🏻🗑️ Removing unneeded directories");

if !global_has_deps {
info!("😄 This manifest does not seem to have any dependencies.");
info!("🙂 If you think this is a BUG 🐞, please open an issue at <https://github.com/openSUSE-Rust/obs-service-cargo/issues>.");
info!("🎉 Nothing to vendor.");
return Ok(());
}

let registry_src_dir = &home_registry_dot_cargo.join("registry").join("src");
let registry_bin_dir = &home_registry_dot_cargo.join("bin");
let registry_caches = [".global-cache", ".package-cache", ".package-cache-mutate"];

if registry_src_dir.exists() {
info!("🚮 Removing {}", registry_src_dir.display());
fs::remove_dir_all(registry_src_dir)?;
info!("🤯 Removed {}", registry_src_dir.display());
}

if registry_bin_dir.exists() {
info!("🚮 Removing {}", registry_bin_dir.display());
fs::remove_dir_all(registry_bin_dir)?;
info!("🤯 Removed {}", registry_bin_dir.display());
}

for ca in registry_caches {
let cache = &home_registry_dot_cargo.join(ca);
if cache.exists() {
Expand All @@ -230,11 +263,14 @@ pub fn run_cargo_vendor_home_registry(
info!("🤯 Removed {}", cache.display());
}
}

let outfile = match &registry.tag {
Some(v) => format!("registry-{}", v),
None => "registry".to_string(),
};

let mut outfile = PathBuf::from(outfile);

let extension = match &registry.compression {
Compression::Gz => "tar.gz",
Compression::Xz => "tar.xz",
Expand All @@ -249,6 +285,7 @@ pub fn run_cargo_vendor_home_registry(
"Unable to set extension",
));
}

let roast_args = RoastArgs {
target: home_registry.to_path_buf(),
include: None,
Expand All @@ -261,8 +298,10 @@ pub fn run_cargo_vendor_home_registry(
ignore_git: false,
ignore_hidden: false,
};

roast_opts(&roast_args, false)
};

res.map(|val| {
trace!(?val);
info!("📦 Cargo Vendor Home Registry finished.");
Expand Down

0 comments on commit d742d0c

Please # to comment.