diff --git a/turbolift_internals/Cargo.toml b/turbolift_internals/Cargo.toml index 34d5748a..a3c4c75e 100644 --- a/turbolift_internals/Cargo.toml +++ b/turbolift_internals/Cargo.toml @@ -31,7 +31,6 @@ async-std = "1.6" async-trait = "0.1" get_if_addrs = "0.5.3" regex = "1" -pathdiff = "0.2.0" # kubernetes-specific requirements kube = "0.42.0" diff --git a/turbolift_internals/src/build_project.rs b/turbolift_internals/src/build_project.rs index cc105199..6cb4896b 100644 --- a/turbolift_internals/src/build_project.rs +++ b/turbolift_internals/src/build_project.rs @@ -4,14 +4,17 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; -use pathdiff::diff_paths; - use crate::utils::symlink_dir; -pub fn edit_cargo_file(cargo_path: &Path, function_name: &str) -> anyhow::Result<()> { +pub fn edit_cargo_file( + original_project_source_dir: &Path, + cargo_path: &Path, + function_name: &str, +) -> anyhow::Result<()> { + let local_deps_dir_name = ".local_deps"; let mut parsed_toml: cargo_toml2::CargoToml = cargo_toml2::from_path(cargo_path) .unwrap_or_else(|_| panic!("toml at {:?} could not be read", cargo_path)); - let relative_local_deps_cache = cargo_path.parent().unwrap().join(".local_deps"); + let relative_local_deps_cache = cargo_path.parent().unwrap().join(local_deps_dir_name); fs::create_dir_all(&relative_local_deps_cache)?; let local_deps_cache = relative_local_deps_cache.canonicalize()?; @@ -26,21 +29,17 @@ pub fn edit_cargo_file(cargo_path: &Path, function_name: &str) -> anyhow::Result let details = deps .iter_mut() // only full dependency descriptions (not simple version number) - .filter_map(|(_name, dep)| match dep { + .filter_map(|(name, dep)| match dep { cargo_toml2::Dependency::Simple(_) => None, - cargo_toml2::Dependency::Full(detail) => Some(detail), + cargo_toml2::Dependency::Full(detail) => Some((name, detail)), }); let mut completed_locations = HashSet::new(); - for detail in details { + for (name, detail) in details { // only descriptions with a path if let Some(ref mut buf) = detail.path { // determine what the symlink for this dependency should be - let canonical = buf.canonicalize()?; - let dep_location = local_deps_cache.join( - &canonical - .file_name() - .unwrap_or_else(|| canonical.as_os_str()), - ); + let canonical = original_project_source_dir.join(&buf).canonicalize()?; + let dep_location = local_deps_cache.join(name); // check that we don't have a naming error // todo: automatically handle naming conflicts by mangling the dep for one @@ -63,10 +62,7 @@ pub fn edit_cargo_file(cargo_path: &Path, function_name: &str) -> anyhow::Result symlink_dir(&canonical, &dep_location)?; } - let proj_folder = cargo_path.parent().unwrap().canonicalize().unwrap(); - let rel_dep_location = diff_paths(&dep_location, &proj_folder).unwrap(); - let relative_path = PathBuf::from_str(".")?.join(&rel_dep_location); - *buf = relative_path; + *buf = PathBuf::from_str(".")?.join(local_deps_dir_name).join(name); } } diff --git a/turbolift_macros/src/lib.rs b/turbolift_macros/src/lib.rs index 969e0bc7..cbb9828b 100644 --- a/turbolift_macros/src/lib.rs +++ b/turbolift_macros/src/lib.rs @@ -109,6 +109,11 @@ pub fn on(distribution_platform_: TokenStream, function_: TokenStream) -> TokenS // modify cargo.toml (edit package info & add actix + json_serde deps) build_project::edit_cargo_file( + PathBuf::from_str(".") + .expect("could not find project dir") + .canonicalize() + .expect("could not canonicalize path to project dir") + .as_path(), &function_cache_proj_path.join("Cargo.toml"), &original_target_function_name, )