Skip to content

Commit fd07cfd

Browse files
committed
[workspace] Add some docs
Plus some little codemod.
1 parent f320997 commit fd07cfd

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/cargo/core/workspace.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ pub enum WorkspaceConfig {
8282
Member { root: Option<String> },
8383
}
8484

85-
/// Configuration of a workspace root in a manifest.
85+
/// Intermediate configuration of a workspace root in a manifest.
86+
///
87+
/// Knows the Workspace Root path, as well as `members` and `exclude` lists of path patterns, which
88+
/// together tell if some path is recognized as a member by this root or not.
8689
#[derive(Debug, Clone)]
8790
pub struct WorkspaceRootConfig {
8891
root_dir: PathBuf,
@@ -207,7 +210,7 @@ impl<'cfg> Workspace<'cfg> {
207210
let root = self.root_manifest.as_ref().unwrap_or(&self.current_manifest);
208211
match *self.packages.get(root) {
209212
MaybePackage::Package(ref p) => p.manifest().profiles(),
210-
MaybePackage::Virtual(ref m) => m.profiles(),
213+
MaybePackage::Virtual(ref vm) => vm.profiles(),
211214
}
212215
}
213216

@@ -238,7 +241,7 @@ impl<'cfg> Workspace<'cfg> {
238241
};
239242
match *self.packages.get(path) {
240243
MaybePackage::Package(ref p) => p.manifest().replace(),
241-
MaybePackage::Virtual(ref v) => v.replace(),
244+
MaybePackage::Virtual(ref vm) => vm.replace(),
242245
}
243246
}
244247

@@ -252,7 +255,7 @@ impl<'cfg> Workspace<'cfg> {
252255
};
253256
match *self.packages.get(path) {
254257
MaybePackage::Package(ref p) => p.manifest().patch(),
255-
MaybePackage::Virtual(ref v) => v.patch(),
258+
MaybePackage::Virtual(ref vm) => vm.patch(),
256259
}
257260
}
258261

@@ -306,20 +309,20 @@ impl<'cfg> Workspace<'cfg> {
306309
}
307310

308311
for path in paths::ancestors(manifest_path).skip(2) {
309-
let manifest = path.join("Cargo.toml");
310-
debug!("find_root - trying {}", manifest.display());
311-
if manifest.exists() {
312-
match *self.packages.load(&manifest)?.workspace_config() {
313-
WorkspaceConfig::Root(ref root_config) => {
312+
let ances_manifest_path = path.join("Cargo.toml");
313+
debug!("find_root - trying {}", ances_manifest_path.display());
314+
if ances_manifest_path.exists() {
315+
match *self.packages.load(&ances_manifest_path)?.workspace_config() {
316+
WorkspaceConfig::Root(ref ances_root_config) => {
314317
debug!("find_root - found a root checking exclusion");
315-
if !root_config.is_excluded(manifest_path) {
318+
if !ances_root_config.is_excluded(&manifest_path) {
316319
debug!("find_root - found!");
317-
return Ok(Some(manifest))
320+
return Ok(Some(ances_manifest_path))
318321
}
319322
}
320323
WorkspaceConfig::Member { root: Some(ref path_to_root) } => {
321324
debug!("find_root - found pointer");
322-
return Ok(Some(read_root_pointer(&manifest, path_to_root)?))
325+
return Ok(Some(read_root_pointer(&ances_manifest_path, path_to_root)?))
323326
}
324327
WorkspaceConfig::Member { .. } => {}
325328
}
@@ -491,6 +494,8 @@ impl<'cfg> Workspace<'cfg> {
491494
let current_dir = self.current_manifest.parent().unwrap();
492495
let root_pkg = self.packages.get(root);
493496

497+
// FIXME: Make this more generic by using a relative path resolver between member and
498+
// root.
494499
let members_msg = match current_dir.strip_prefix(root_dir) {
495500
Ok(rel) => {
496501
format!("this may be fixable by adding `{}` to the \
@@ -578,11 +583,10 @@ impl<'cfg> Packages<'cfg> {
578583
read_manifest(manifest_path, &source_id, self.config)?;
579584
Ok(v.insert(match manifest {
580585
EitherManifest::Real(manifest) => {
581-
MaybePackage::Package(Package::new(manifest,
582-
manifest_path))
586+
MaybePackage::Package(Package::new(manifest, manifest_path))
583587
}
584-
EitherManifest::Virtual(v) => {
585-
MaybePackage::Virtual(v)
588+
EitherManifest::Virtual(vm) => {
589+
MaybePackage::Virtual(vm)
586590
}
587591
}))
588592
}
@@ -616,13 +620,14 @@ impl<'a, 'cfg> Iterator for Members<'a, 'cfg> {
616620
impl MaybePackage {
617621
fn workspace_config(&self) -> &WorkspaceConfig {
618622
match *self {
619-
MaybePackage::Virtual(ref v) => v.workspace_config(),
620-
MaybePackage::Package(ref v) => v.manifest().workspace_config(),
623+
MaybePackage::Package(ref p) => p.manifest().workspace_config(),
624+
MaybePackage::Virtual(ref vm) => vm.workspace_config(),
621625
}
622626
}
623627
}
624628

625629
impl WorkspaceRootConfig {
630+
/// Create a new Intermediate Workspace Root configuration.
626631
pub fn new(
627632
root_dir: &Path,
628633
members: &Option<Vec<String>>,
@@ -635,6 +640,9 @@ impl WorkspaceRootConfig {
635640
}
636641
}
637642

643+
/// Checks the path against the `excluded` list.
644+
///
645+
/// This method does NOT consider the `members` list.
638646
fn is_excluded(&self, manifest_path: &Path) -> bool {
639647
let excluded = self.exclude.iter().any(|ex| {
640648
manifest_path.starts_with(self.root_dir.join(ex))

0 commit comments

Comments
 (0)