refactor(cargo): parse tool options locally#9922
Conversation
Greptile SummaryThis PR wraps cargo backend option parsing in a
Confidence Score: 5/5Safe to merge — the change is a pure refactor that encapsulates existing option reads and simultaneously corrects a long-standing inconsistency in lockfile fingerprinting for platform-specific bin values. All option-read semantics are preserved identically; the only behavioural change (platform-aware bin in lockfile) is intentional and verified by the new unit test. No new code paths are introduced that could fail at runtime. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "fix(cargo): lock target-specific bin opt..." | Re-trigger Greptile |
There was a problem hiding this comment.
Code Review
This pull request refactors the CargoBackend in src/backend/cargo.rs by introducing a CargoOptions struct to encapsulate tool version options, replacing manual map lookups with structured methods. The review feedback suggests making this implementation platform-aware by using platform_string lookups instead of top-level string access, which ensures that platform-specific overrides in configuration files are correctly respected. Additionally, the reviewer recommends passing the PlatformTarget argument into the lockfile resolution logic to ensure the generated lockfile accurately reflects the settings for the specific target platform.
I am having trouble creating individual review comments. Click here to see my feedback.
src/backend/cargo.rs (35-85)
The CargoOptions implementation should leverage platform-aware lookups for all tool options to ensure that platform-specific overrides in mise.toml (e.g., platforms.linux-x64.features = "...") are correctly respected. Currently, methods like locked, features, and default_features_disabled only look at top-level string values, which ignores these overrides.
Additionally, lockfile_options should take a PlatformTarget argument and use platform_string_for_target to ensure the lockfile accurately reflects the settings for the target platform being locked.
impl<'a> CargoOptions<'a> {
fn new(raw: &'a ToolVersionOptions) -> Self {
Self {
values: BackendOptions::new(raw),
}
}
fn bin(&self) -> Option<String> {
self.values.platform_string("bin")
}
fn locked(&self) -> bool {
self.values
.platform_string("locked")
.is_none_or(|v| v.to_lowercase() != "false")
}
fn features(&self) -> Option<String> {
self.values.platform_string("features")
}
fn default_features_disabled(&self) -> bool {
self.values
.platform_string("default-features")
.is_some_and(|v| v.to_lowercase() == "false")
}
fn crate_arg(&self) -> Option<String> {
self.values.platform_string("crate")
}
fn install_env(&self) -> &'a IndexMap<String, String> {
&self.values.raw().install_env
}
fn has_features_options(&self) -> bool {
self.values.platform_string("features").is_some()
|| self.values.platform_string("default-features").is_some()
}
fn lockfile_options(&self, target: &PlatformTarget) -> BTreeMap<String, String> {
let mut result = BTreeMap::new();
for key in ["features", "default-features", "bin"] {
if let Some(value) = self.values.platform_string_for_target(key, target) {
result.insert(key.to_string(), value);
}
}
result
}
}References
- When overriding a method, use the provided parameters instead of re-deriving their values from a more general context. This implementation supports that by allowing the target to be passed in.
src/backend/cargo.rs (232-236)
Pass the target to lockfile_options to ensure that platform-specific overrides are correctly captured in the lockfile. This ensures we use the provided parameter instead of re-deriving it.
fn resolve_lockfile_options(
&self,
request: &ToolRequest,
target: &PlatformTarget,
) -> BTreeMap<String, String> {
let opts = request.options();
CargoOptions::new(&opts).lockfile_options(target)
}References
- When overriding a method, use the provided parameters instead of re-deriving their values from a more general context.
Summary
CargoOptionswrapper around cargo backend tool optionsVerification
This PR was generated by an AI coding assistant.