feat: patch before linking

This commit is contained in:
daimond113 2024-11-10 17:16:35 +01:00
parent a9b1fa655f
commit 15868acce0
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C

View file

@ -239,30 +239,47 @@ impl InstallCommand {
downloaded_graph.clone() downloaded_graph.clone()
}; };
println!("{} 🗺️ linking dependencies", job(4)); #[cfg(feature = "patches")]
{
project let rx = project
.link_dependencies(&filtered_graph) .apply_patches(&filtered_graph)
.await .await
.context("failed to link dependencies")?; .context("failed to apply patches")?;
progress_bar(
manifest.patches.values().map(|v| v.len() as u64).sum(),
rx,
&multi,
format!("{} 🩹 applying patches", job(4)),
format!("{} 🩹 applied patches", job(4)),
)
.await?;
}
println!("{} 🗺️ linking dependencies", job(JOBS - 1));
let bin_folder = bin_dir().await?; let bin_folder = bin_dir().await?;
for versions in filtered_graph.values() { try_join_all(
for node in versions.values() { filtered_graph
if node.target.bin_path().is_none() { .values()
continue; .flat_map(|versions| versions.values())
} .filter(|node| node.target.bin_path().is_some())
.filter_map(|node| node.node.direct.as_ref())
let Some((alias, _)) = &node.node.direct else { .map(|(alias, _)| alias)
continue; .filter(|alias| {
}; if *alias == env!("CARGO_BIN_NAME") {
log::warn!(
if alias == env!("CARGO_BIN_NAME") { "package {alias} has the same name as the CLI, skipping bin link"
log::warn!("package {alias} has the same name as the CLI, skipping bin link"); );
continue; return false;
} }
true
})
.map(|alias| {
let bin_folder = bin_folder.clone();
async move {
let bin_file = bin_folder.join(alias); let bin_file = bin_folder.join(alias);
fs::write(&bin_file, bin_link_file(alias)) fs::write(&bin_file, bin_link_file(alias))
.await .await
@ -276,31 +293,24 @@ impl InstallCommand {
{ {
let bin_file = bin_file.with_extension(std::env::consts::EXE_EXTENSION); let bin_file = bin_file.with_extension(std::env::consts::EXE_EXTENSION);
fs::copy( fs::copy(
std::env::current_exe().context("failed to get current executable path")?, std::env::current_exe()
.context("failed to get current executable path")?,
&bin_file, &bin_file,
) )
.await .await
.context("failed to copy bin link file")?; .context("failed to copy bin link file")?;
} }
}
}
#[cfg(feature = "patches")] Ok::<_, anyhow::Error>(())
{ }
let rx = project }),
.apply_patches(&filtered_graph)
.await
.context("failed to apply patches")?;
progress_bar(
manifest.patches.values().map(|v| v.len() as u64).sum(),
rx,
&multi,
format!("{} 🩹 applying patches", job(5)),
format!("{} 🩹 applied patches", job(5)),
) )
.await?; .await?;
}
project
.link_dependencies(&filtered_graph)
.await
.context("failed to link dependencies")?;
println!("{} 🧹 finishing up", job(JOBS)); println!("{} 🧹 finishing up", job(JOBS));