Skip to content

Commit

Permalink
Auto merge of #13993 - epage:path-source, r=ehuss
Browse files Browse the repository at this point in the history
refactor(source): Split `RecursivePathSource` out of `PathSource`

### What does this PR try to resolve?

`PathSource` serves a couple of roles
- When a dependency / patch uses `path` (non-recursive)
- As the implementation details of a `git` source (recursive)
- Dependency overrides (recursive)

Instead of using a `PathSource::new` vs `PathSouce::new_recursive`, this does `RecursivePathSource::new`.  This makes the intent a lot clearer and makes it easier to customize the behavior to each role that is played.

Specifically, there are two ways I expect to leverage this refactor
- Improve the interplay between `RecursivePathSource` and `read_packages` to reduce the duplicate package warnings for git sources (#13992)
- cargo script will change the semantics of path sources slightly and I'm assuming having a distinct source will make this easier

### How should we test and review this PR?

### Additional information
  • Loading branch information
bors committed Jun 3, 2024
2 parents d503f74 + 406bf68 commit 1f020f0
Show file tree
Hide file tree
Showing 5 changed files with 771 additions and 600 deletions.
3 changes: 1 addition & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,8 +1142,7 @@ impl<'gctx> Workspace<'gctx> {
MaybePackage::Package(ref p) => p.clone(),
MaybePackage::Virtual(_) => continue,
};
let mut src = PathSource::new(pkg.root(), pkg.package_id().source_id(), self.gctx);
src.preload_with(pkg);
let src = PathSource::preload_with(pkg, self.gctx);
registry.add_preloaded(Box::new(src));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use crate::core::PackageSet;
use crate::core::SourceId;
use crate::core::Workspace;
use crate::ops;
use crate::sources::PathSource;
use crate::sources::RecursivePathSource;
use crate::util::cache_lock::CacheLockMode;
use crate::util::errors::CargoResult;
use crate::util::CanonicalUrl;
Expand Down Expand Up @@ -453,7 +453,7 @@ pub fn add_overrides<'a>(

for (path, definition) in paths {
let id = SourceId::for_path(&path)?;
let mut source = PathSource::new_recursive(&path, id, ws.gctx());
let mut source = RecursivePathSource::new(&path, id, ws.gctx());
source.update().with_context(|| {
format!(
"failed to update path override `{}` \
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::sources::source::MaybePackage;
use crate::sources::source::QueryKind;
use crate::sources::source::Source;
use crate::sources::IndexSummary;
use crate::sources::PathSource;
use crate::sources::RecursivePathSource;
use crate::util::cache_lock::CacheLockMode;
use crate::util::errors::CargoResult;
use crate::util::hex::short_hash;
Expand All @@ -24,7 +24,7 @@ use tracing::trace;
use url::Url;

/// `GitSource` contains one or more packages gathering from a Git repository.
/// Under the hood it uses [`PathSource`] to discover packages inside the
/// Under the hood it uses [`RecursivePathSource`] to discover packages inside the
/// repository.
///
/// ## Filesystem layout
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct GitSource<'gctx> {
///
/// This gets set to `Some` after the git repo has been checked out
/// (automatically handled via [`GitSource::block_until_ready`]).
path_source: Option<PathSource<'gctx>>,
path_source: Option<RecursivePathSource<'gctx>>,
/// A short string that uniquely identifies the version of the checkout.
///
/// This is typically a 7-character string of the OID hash, automatically
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<'gctx> Source for GitSource<'gctx> {
let source_id = self
.source_id
.with_git_precise(Some(actual_rev.to_string()));
let path_source = PathSource::new_recursive(&checkout_path, source_id, self.gctx);
let path_source = RecursivePathSource::new(&checkout_path, source_id, self.gctx);

self.path_source = Some(path_source);
self.short_id = Some(short_id.as_str().into());
Expand Down
1 change: 1 addition & 0 deletions src/cargo/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use self::config::SourceConfigMap;
pub use self::directory::DirectorySource;
pub use self::git::GitSource;
pub use self::path::PathSource;
pub use self::path::RecursivePathSource;
pub use self::registry::{
IndexSummary, RegistrySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY,
};
Expand Down
Loading

0 comments on commit 1f020f0

Please sign in to comment.