feat: parallel sourcemap generation

This commit is contained in:
daimond113 2024-05-12 16:00:08 +02:00
parent 39102908cb
commit 06ed5d94ae
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
2 changed files with 66 additions and 37 deletions

View file

@ -109,14 +109,20 @@ pub fn root_command(cmd: Command) -> anyhow::Result<()> {
"Downloading packages".to_string(), "Downloading packages".to_string(),
)?; )?;
#[allow(unused_variables)]
project.convert_manifests(&lockfile, |path| {
cfg_if! { cfg_if! {
if #[cfg(feature = "wally")] { if #[cfg(feature = "wally")] {
if let Some(sourcemap_generator) = &manifest.sourcemap_generator { let sourcemap_generator = manifest.sourcemap_generator.clone();
}
}
#[allow(unused_variables)]
let convert_job = project.convert_manifests(&lockfile, move |path| {
cfg_if! {
if #[cfg(feature = "wally")] {
if let Some(sourcemap_generator) = &sourcemap_generator {
cfg_if! { cfg_if! {
if #[cfg(target_os = "windows")] { if #[cfg(target_os = "windows")] {
std::process::Command::new("pwsh") std::process::Command::new("powershell")
.args(["-C", &sourcemap_generator]) .args(["-C", &sourcemap_generator])
.current_dir(path) .current_dir(path)
.output() .output()
@ -132,7 +138,19 @@ pub fn root_command(cmd: Command) -> anyhow::Result<()> {
} }
} }
} }
})?; });
cfg_if! {
if #[cfg(feature = "wally")] {
multithreaded_bar(
convert_job,
lockfile.children.values().flat_map(|v| v.values()).filter(|v| matches!(v.pkg_ref, PackageRef::Git(_) | PackageRef::Wally(_))).count() as u64,
"Converting manifests".to_string(),
)?;
} else {
convert_job?;
}
}
let project = Lazy::force_mut(&mut project); let project = Lazy::force_mut(&mut project);

View file

@ -321,11 +321,11 @@ impl Project {
/// Converts the manifests of the project's dependencies /// Converts the manifests of the project's dependencies
#[cfg(feature = "wally")] #[cfg(feature = "wally")]
pub fn convert_manifests<F: Fn(PathBuf)>( pub fn convert_manifests<F: Fn(PathBuf) + Send + Sync + 'static>(
&self, &self,
lockfile: &RootLockfileNode, lockfile: &RootLockfileNode,
generate_sourcemap: F, generate_sourcemap: F,
) -> Result<(), ConvertManifestsError> { ) -> MultithreadedJob<ConvertManifestsError> {
#[derive(Deserialize)] #[derive(Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct SourcemapNode { struct SourcemapNode {
@ -333,13 +333,21 @@ impl Project {
file_paths: Vec<relative_path::RelativePathBuf>, file_paths: Vec<relative_path::RelativePathBuf>,
} }
let (job, tx) = MultithreadedJob::new();
let generate_sourcemap = Arc::new(generate_sourcemap);
for versions in lockfile.children.values() { for versions in lockfile.children.values() {
for resolved_package in versions.values() { for resolved_package in versions.values().cloned() {
let generate_sourcemap = generate_sourcemap.clone();
let self_path = self.path().to_path_buf();
job.execute(&tx, move || {
let source = match &resolved_package.pkg_ref { let source = match &resolved_package.pkg_ref {
PackageRef::Wally(_) | PackageRef::Git(_) => { PackageRef::Wally(_) | PackageRef::Git(_) => {
resolved_package.directory(self.path()).1 resolved_package.directory(self_path).1
} }
_ => continue, _ => return Ok(()),
}; };
let mut manifest = match &resolved_package.pkg_ref { let mut manifest = match &resolved_package.pkg_ref {
@ -356,7 +364,7 @@ impl Project {
serde_json::from_str(&std::fs::read_to_string(&sourcemap)?)? serde_json::from_str(&std::fs::read_to_string(&sourcemap)?)?
} else { } else {
log::warn!("sourcemap for {resolved_package} not found, skipping..."); log::warn!("sourcemap for {resolved_package} not found, skipping...");
continue; return Ok(());
}; };
manifest.exports.lib = sourcemap manifest.exports.lib = sourcemap
@ -369,10 +377,13 @@ impl Project {
.or_else(|| Some(relative_path::RelativePathBuf::from("true"))); .or_else(|| Some(relative_path::RelativePathBuf::from("true")));
manifest.write(&source)?; manifest.write(&source)?;
Ok(())
});
} }
} }
Ok(()) job
} }
/// Errors if dependencies don't have manifests, enable the `wally` feature to convert them /// Errors if dependencies don't have manifests, enable the `wally` feature to convert them