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

Extend transpose deps command #108

Merged
merged 12 commits into from
Jun 10, 2024
38 changes: 20 additions & 18 deletions src/cmd/transpose/lift_to_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,18 @@ impl LiftToWorkspaceCmd {
let mut dep = by_version.values().next().unwrap().first().unwrap().1.clone();
dep.req = best_version.parse().unwrap();

let location = if source_location == Some(SourceLocationSelector::Local) {
let Some(ref path) = dep.path else {
unreachable!("Could not detect local source location for '{}'", name);
};
let relative = path.strip_prefix(&meta.workspace_root).unwrap_or_else(|_| {
log::warn!("Dependency '{}' is not in the workspace root", name);
path
});
Some(relative.to_string())
} else {
None
let location = match source_location {
SourceLocationSelector::Local => {
let Some(ref path) = dep.path else {
unreachable!("Could not detect local source location for '{}'", name);
};
let relative = path.strip_prefix(&meta.workspace_root).unwrap_or_else(|_| {
log::warn!("Dependency '{}' is not in the workspace root", name);
path
});
Some(relative.to_string())
},
SourceLocationSelector::Remote => None,
};

workspace_fixer.add_workspace_dep(
Expand Down Expand Up @@ -226,9 +227,7 @@ impl LiftToWorkspaceCmd {
if let Some(rename) = &maybe_rename {
assert_eq!(rename, dep_name);
}
let Some(ref location) = source_location else {
return Err("Could not determine source location".to_string());
};
let ref location = source_location;

if dep.uses_default_features != workspace_default_features_enabled {
fixer.lift_dependency(
Expand Down Expand Up @@ -279,7 +278,7 @@ impl LiftToWorkspaceCmd {
&self,
meta: &cargo_metadata::Metadata,
name: &str,
) -> Result<Option<SourceLocationSelector>, String> {
) -> Result<SourceLocationSelector, String> {
let mut local = false;
let mut remote = false;

Expand Down Expand Up @@ -309,11 +308,14 @@ impl LiftToWorkspaceCmd {
name
))
} else if local {
Ok(Some(SourceLocationSelector::Local))
Ok(SourceLocationSelector::Local)
} else if remote {
Ok(Some(SourceLocationSelector::Remote))
Ok(SourceLocationSelector::Remote)
} else {
Ok(None)
Err(format!(
"Dependency '{}' is not used in the workspace. This cannot be fixed automatically.",
name
))
}
}

Expand Down
Loading