Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for simple wilcard Anchor.toml's workspace.members #2785

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,37 +300,43 @@ impl WithPath<Config> {
}

pub fn canonicalize_workspace(&self) -> Result<(Vec<PathBuf>, Vec<PathBuf>)> {
let members = self
.workspace
.members
.iter()
.map(|m| {
self.path()
.parent()
.unwrap()
.join(m)
.canonicalize()
.unwrap_or_else(|_| {
panic!("Error reading workspace.members. File {:?} does not exist at path {:?}.", m, self.path)
})
})
.collect();
let exclude = self
.workspace
.exclude
let members = self.process_paths(&self.workspace.members)?;
let exclude = self.process_paths(&self.workspace.exclude)?;
Ok((members, exclude))
}

fn process_paths(&self, paths: &[String]) -> Result<Vec<PathBuf>, Error> {
let base_path = self.path().parent().unwrap();
paths
.iter()
.map(|m| {
self.path()
.parent()
.unwrap()
.join(m)
.canonicalize()
.unwrap_or_else(|_| {
panic!("Error reading workspace.exclude. File {:?} does not exist at path {:?}.", m, self.path)
})
.flat_map(|m| {
let path = base_path.join(m);
if m.ends_with("/*") {
let dir = path.parent().unwrap();
match fs::read_dir(dir) {
Ok(entries) => entries
.filter_map(|entry| entry.ok())
.map(|entry| self.process_single_path(&entry.path()))
.collect(),
Err(e) => vec![Err(Error::new(io::Error::new(
io::ErrorKind::Other,
format!("Error reading directory {:?}: {}", dir, e),
)))],
}
} else {
vec![self.process_single_path(&path)]
}
})
.collect();
Ok((members, exclude))
.collect()
}

fn process_single_path(&self, path: &PathBuf) -> Result<PathBuf, Error> {
path.canonicalize().map_err(|e| {
Error::new(io::Error::new(
io::ErrorKind::Other,
format!("Error canonicalizing path {:?}: {}", path, e),
))
})
}
}

Expand Down
Loading