-
-
Notifications
You must be signed in to change notification settings - Fork 121
feat: cargo profiles inheritance #2595
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
base: main
Are you sure you want to change the base?
Conversation
@sunshowers could you please take a look at this and give a review when you have a chance? |
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.
Thanks for working on this!
store_dir: Utf8PathBuf, | ||
default_profile: &'cfg DefaultProfileImpl, | ||
custom_profile: Option<&'cfg CustomProfileImpl>, | ||
inheritance_chain: Vec<&'cfg CustomProfileImpl>, |
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.
nice!
// Check custom profile first, then walk up inheritance chain | ||
if let Some(profile) = self.custom_profile { | ||
if let Some(retries) = profile.retries { | ||
return retries; | ||
} | ||
} | ||
|
||
// Walk up inheritance chain | ||
for parent in &self.inheritance_chain { | ||
if let Some(retries) = parent.retries { | ||
return retries; | ||
} | ||
} | ||
|
||
// Fall back to default | ||
self.default_profile.retries |
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.
This looks good -- you'll want to replicate this logic for all of the other config options here (can you extract this into a common function?)
)); | ||
} | ||
|
||
visited.insert(profile_name.to_string()); |
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.
Do you need the to_string
here? Or can you store references to the profile name?
You might run into variance issues with storing a reference, but I think you can have another lifetime parameter for that.
} | ||
|
||
fn check_inheritance_cycles(&self) -> Result<(), ConfigParseError> { | ||
let mut graph = Graph::<String, (), Directed>::new(); |
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.
same here, can you store references?
Err(cycle) => { | ||
let cycle_profile = graph[cycle.node_id()].clone(); | ||
Err(ConfigParseError::new( | ||
"Inheritance cycle detected in profile configuration", |
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.
We use lowercase for errors:
"Inheritance cycle detected in profile configuration", | |
"inheritance cycle detected in profile configuration", |
Err(ConfigParseError::new( | ||
"Inheritance cycle detected in profile configuration", | ||
None, | ||
ConfigParseErrorKind::InheritanceCycle(cycle_profile), |
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.
Could we use https://docs.rs/petgraph/latest/petgraph/algo/fn.kosaraju_scc.html to detect all cycles here? Each SCC returned by the algorithm is a cycle -- it would be nice to print out all such cycles here.
#[serde(default)] | ||
archive: Option<ArchiveConfig>, | ||
#[serde(default)] | ||
inherit: Option<String> |
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.
Need a trailing comma (did rustfmt not catch this?)
Ok(()) | ||
} | ||
|
||
fn check_inheritance_cycles(&self) -> Result<(), ConfigParseError> { |
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.
We need some tests, both for inheritance and for cycles.
No description provided.