Repository navigation
Fix: update workspace members through the Cargo workspace root #217
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
xtask/src/documentation_integrity/dependabot/workspace_members.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //! This module owns workspace-member discovery from the root Cargo manifest. | ||
|
|
||
| use std::collections::BTreeSet; | ||
|
|
||
| use xtask::protocol_admission::posix_relative_path; | ||
|
|
||
| use super::DependencyScope; | ||
| use crate::documentation_integrity::error::DocumentationError; | ||
|
|
||
| pub(super) const ROOT_MANIFEST_PATH: &str = "Cargo.toml"; | ||
|
|
||
| /// Returns the Cargo scopes that belong to the root workspace, excluding the root. | ||
| /// | ||
| /// Xtask has no TOML parser and reads one fixed manifest, so this admits a single | ||
| /// inline list of exact paths. A glob or any other spelling is refused, because a | ||
| /// guess could drop a standalone manifest from Dependabot coverage. | ||
| pub(super) fn admit(manifest: &str) -> Result<BTreeSet<DependencyScope>, DocumentationError> { | ||
| let mut lists = manifest | ||
| .lines() | ||
| .skip_while(|line| *line != "[workspace]") | ||
| .skip(1) | ||
| .take_while(|line| !line.starts_with('[')) | ||
| .filter(|line| line.starts_with("members")); | ||
| let (Some(list), None) = (lists.next(), lists.next()) else { | ||
| return Err(contract("workspace declares exactly one member list")); | ||
| }; | ||
| let entries = list | ||
| .strip_prefix("members = [") | ||
| .and_then(|rest| rest.strip_suffix(']')) | ||
| .ok_or_else(|| contract("workspace members are one inline list"))?; | ||
| let mut members = BTreeSet::new(); | ||
| for entry in entries.split(", ") { | ||
| let path = entry | ||
| .strip_prefix('"') | ||
| .and_then(|rest| rest.strip_suffix('"')) | ||
| .ok_or_else(|| contract("workspace member is one quoted path"))?; | ||
| if path == "." { | ||
| continue; | ||
| } | ||
| if path.contains('*') || posix_relative_path(path).is_err() { | ||
| return Err(contract("workspace member is one exact relative path")); | ||
| } | ||
| members.insert(DependencyScope::new("cargo", &format!("/{path}"))); | ||
| } | ||
| Ok(members) | ||
| } | ||
|
|
||
| const fn contract(requirement: &'static str) -> DocumentationError { | ||
| DocumentationError::RepositoryContract { | ||
| path: ROOT_MANIFEST_PATH, | ||
| requirement, | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject every glob metacharacter in workspace member entries, not only
*.Cargo expands
membersentries as globs.?matches one character, and[...]matches a character class. Both forms can match a real member directory. For example,"xtas?"and"xtas[k]"both matchxtask.This check rejects
*only. It stores?and[as literal characters in the scope/xtas?or/xtas[k]. A configured/xtaskupdate directory then does not intersect that scope, so the member-scope check can pass when it should reject the directory.Reject all three metacharacters. Add refusal tests for
"xtas?"and"xtas[k]".Suggested fix
Committable suggestion