From 0f74e2efa38a5f1334c3c41a9aa9a0bab2fa7ab9 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Wed, 18 Dec 2024 23:34:49 +0100 Subject: [PATCH] fix: do not error on missing deps until full linking --- CHANGELOG.md | 1 + src/download_and_link.rs | 6 +++++- src/linking/mod.rs | 20 +++++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c19ddc3..fc27fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Change dependency types for removed peer dependencies by @daimond113 - Resolve version to correct tag for `pesde_version` field by @daimond113 +- Do not error on missing dependencies until full linking by @daimond113 ### Changed - Switch from `log` to `tracing` for logging by @daimond113 diff --git a/src/download_and_link.rs b/src/download_and_link.rs index 9ee1b85..a8d7b19 100644 --- a/src/download_and_link.rs +++ b/src/download_and_link.rs @@ -11,7 +11,7 @@ use std::{ sync::{Arc, Mutex as StdMutex}, }; use tokio::sync::Mutex; -use tracing::instrument; +use tracing::{instrument, Instrument}; /// Filters a graph to only include production dependencies, if `prod` is `true` pub fn filter_graph(graph: &DownloadedGraph, prod: bool) -> DownloadedGraph { @@ -85,6 +85,7 @@ impl Project { // step 1. download pesde dependencies let (mut pesde_rx, pesde_graph) = this .download_graph(&graph, &mut refreshed_sources, &reqwest, prod, write, false) + .instrument(tracing::debug_span!("download (pesde)")) .await?; while let Some(result) = pesde_rx.recv().await { @@ -96,6 +97,7 @@ impl Project { // step 2. link pesde dependencies. do so without types if write { this.link_dependencies(&filter_graph(&pesde_graph, prod), false) + .instrument(tracing::debug_span!("link (pesde)")) .await?; } @@ -110,6 +112,7 @@ impl Project { // step 3. download wally dependencies let (mut wally_rx, wally_graph) = this .download_graph(&graph, &mut refreshed_sources, &reqwest, prod, write, true) + .instrument(tracing::debug_span!("download (wally)")) .await?; while let Some(result) = wally_rx.recv().await { @@ -139,6 +142,7 @@ impl Project { // step 4. link ALL dependencies. do so with types if write { this.link_dependencies(&filter_graph(&graph, prod), true) + .instrument(tracing::debug_span!("link (all)")) .await?; } diff --git a/src/linking/mod.rs b/src/linking/mod.rs index 9df91f8..56bb203 100644 --- a/src/linking/mod.rs +++ b/src/linking/mod.rs @@ -57,7 +57,7 @@ impl Project { // step 1. link all non-wally packages (and their dependencies) temporarily without types // we do this separately to allow the required tools for the scripts to be installed - self.link(graph, &manifest, &Arc::new(Default::default())) + self.link(graph, &manifest, &Arc::new(Default::default()), false) .await?; if !with_types { @@ -156,7 +156,8 @@ impl Project { .collect::>(); // step 3. link all packages (and their dependencies), this time with types - self.link(graph, &manifest, &Arc::new(package_types)).await + self.link(graph, &manifest, &Arc::new(package_types), true) + .await } #[allow(clippy::too_many_arguments)] @@ -245,6 +246,7 @@ impl Project { graph: &DownloadedGraph, manifest: &Arc, package_types: &Arc>>>, + is_complete: bool, ) -> Result<(), errors::LinkingError> { try_join_all(graph.iter().flat_map(|(name, versions)| { versions.iter().map(|(version_id, node)| { @@ -299,10 +301,14 @@ impl Project { .get(dependency_name) .and_then(|v| v.get(dependency_version_id)) else { - return Err(errors::LinkingError::DependencyNotFound( - dependency_name.to_string(), - dependency_version_id.to_string(), - )); + if is_complete { + return Err(errors::LinkingError::DependencyNotFound( + format!("{dependency_name}@{dependency_version_id}"), + format!("{name}@{version_id}"), + )); + } + + continue; }; let base_folder = create_and_canonicalize( @@ -371,7 +377,7 @@ pub mod errors { Io(#[from] std::io::Error), /// A dependency was not found - #[error("dependency not found: {0}@{1}")] + #[error("dependency `{0}` of `{1}` not found")] DependencyNotFound(String, String), /// The library file was not found