feat: improve container_folder api

This commit is contained in:
daimond113 2025-01-01 16:35:59 +01:00
parent d0169976cd
commit 78e58d63fa
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
6 changed files with 47 additions and 67 deletions

View file

@ -125,13 +125,11 @@ impl PublishCommand {
.target
.kind()
.packages_folder(id.version_id().target());
let container_folder = node.container_folder(
&project
.package_dir()
.join(base_folder)
.join(PACKAGES_CONTAINER_NAME),
id,
);
let container_folder = project
.package_dir()
.join(base_folder)
.join(PACKAGES_CONTAINER_NAME)
.join(node.container_folder(id));
let node = node.clone();
let refreshed_sources = refreshed_sources.clone();

View file

@ -92,13 +92,11 @@ impl RunCommand {
.target
.kind()
.packages_folder(id.version_id().target());
let container_folder = node.container_folder(
&project
.package_dir()
.join(base_folder)
.join(PACKAGES_CONTAINER_NAME),
&id,
);
let container_folder = project
.package_dir()
.join(base_folder)
.join(PACKAGES_CONTAINER_NAME)
.join(node.container_folder(&id));
let source = node.pkg_ref.source();
source

View file

@ -170,15 +170,12 @@ impl Project {
)
.await?;
let container_folder = node.container_folder(
&package_dir
.join(
manifest_target_kind
.packages_folder(package_id.version_id().target()),
)
.join(PACKAGES_CONTAINER_NAME),
&package_id,
);
let container_folder = package_dir
.join(
manifest_target_kind.packages_folder(package_id.version_id().target()),
)
.join(PACKAGES_CONTAINER_NAME)
.join(node.container_folder(&package_id));
fs::create_dir_all(&container_folder).await?;

View file

@ -11,10 +11,7 @@ use crate::{
},
};
use serde::{Deserialize, Serialize};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};
use std::{collections::BTreeMap, path::PathBuf};
/// A graph of dependencies
pub type Graph<Node> = BTreeMap<PackageId, Node>;
@ -47,23 +44,20 @@ impl DependencyGraphNode {
}
/// Returns the folder to store the contents of the package in
pub fn container_folder<P: AsRef<Path>>(&self, path: &P, package_id: &PackageId) -> PathBuf {
pub fn container_folder(&self, package_id: &PackageId) -> PathBuf {
let (name, version) = package_id.parts();
if self.pkg_ref.like_wally() {
return path
.as_ref()
.join(format!(
"{}_{}@{}",
package_id.name().as_str().0,
name.as_str().1,
version
))
.join(name.as_str().1);
return PathBuf::from(format!(
"{}_{}@{}",
package_id.name().as_str().0,
name.as_str().1,
version
))
.join(name.as_str().1);
}
path.as_ref()
.join(name.escaped())
PathBuf::from(name.escaped())
.join(version.to_string())
.join(name.as_str().1)
}

View file

@ -91,16 +91,13 @@ impl Project {
return Ok((package_id, vec![]));
};
let container_folder = node.node.container_folder(
&project
.package_dir()
.join(
manifest_target_kind
.packages_folder(package_id.version_id().target()),
)
.join(PACKAGES_CONTAINER_NAME),
&package_id,
);
let container_folder = project
.package_dir()
.join(
manifest_target_kind.packages_folder(package_id.version_id().target()),
)
.join(PACKAGES_CONTAINER_NAME)
.join(node.node.container_folder(&package_id));
let types = if lib_file.as_str() != LINK_LIB_NO_FILE_FOUND {
let lib_file = lib_file.to_path(&container_folder);
@ -274,9 +271,8 @@ impl Project {
.await?;
let packages_container_folder = base_folder.join(PACKAGES_CONTAINER_NAME);
let container_folder = node
.node
.container_folder(&packages_container_folder, &package_id);
let container_folder =
packages_container_folder.join(node.node.container_folder(&package_id));
if let Some((alias, _, _)) = &node.node.direct {
project
@ -320,9 +316,8 @@ impl Project {
.await?;
let packages_container_folder = base_folder.join(PACKAGES_CONTAINER_NAME);
let container_folder = dependency_node
.node
.container_folder(&packages_container_folder, dependency_id);
let container_folder = packages_container_folder
.join(dependency_node.node.container_folder(dependency_id));
let linker_folder = create_and_canonicalize(node_container_folder.join(
node.node.base_folder(

View file

@ -102,18 +102,16 @@ impl Project {
continue;
};
let container_folder = node.container_folder(
&self
.package_dir()
.join(
manifest
.target
.kind()
.packages_folder(package_id.version_id().target()),
)
.join(PACKAGES_CONTAINER_NAME),
&package_id,
);
let container_folder = self
.package_dir()
.join(
manifest
.target
.kind()
.packages_folder(package_id.version_id().target()),
)
.join(PACKAGES_CONTAINER_NAME)
.join(node.container_folder(&package_id));
let reporter = reporter.clone();
let span = tracing::info_span!("apply patch", package_id = package_id.to_string());