Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/autofix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl AutoFixer {
as_table.remove("default-features");
}
} else {
unreachable!("Unknown kind of dependency: {:?}", dep);
return Err("Dependency is not a string or an inline table".into())
}
Ok(())
}
Expand Down
81 changes: 51 additions & 30 deletions src/cmd/transpose/lift_to_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub struct LiftToWorkspaceCmd {
#[clap(long, alias = "version-resolver", value_enum, default_value_t = VersionSelectorMode::Unambiguous, requires_if("exact", "exact_version"))]
version_selector: VersionSelectorMode,

/// Do not try to modify this package.
#[clap(long)]
skip_package: Option<String>,

/// Optionally only check dependencies with this source location.
#[clap(long, value_enum)]
source_location: Option<SourceLocationSelector>,
Expand Down Expand Up @@ -173,36 +177,6 @@ impl LiftToWorkspaceCmd {
// them off.
let workspace_default_features_enabled = all_use_default_features;

for (pkg, dep) in by_version.values().flatten() {
if !check_can_modify(&meta.workspace_root, &pkg.manifest_path)? {
continue
}

fixers.entry(pkg.name.clone()).or_insert_with(|| {
(Some(pkg.clone()), AutoFixer::from_manifest(&pkg.manifest_path).unwrap())
});
let (_, fixer) = fixers.get_mut(&pkg.name).unwrap();
// We can safely use the rename here, since we found it with `detect_rename`.
let dep_name = dep.rename.as_ref().unwrap_or(&dep.name);
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());
};

if dep.uses_default_features != workspace_default_features_enabled {
fixer.lift_dependency(
dep_name,
&dep.kind,
Some(dep.uses_default_features),
location,
)?;
} else {
fixer.lift_dependency(dep_name, &dep.kind, None, location)?;
}
}

// Now create fixer for the root package
let root_manifest_path = meta.workspace_root.join("Cargo.toml");
fixers
Expand Down Expand Up @@ -233,6 +207,41 @@ impl LiftToWorkspaceCmd {
location.as_deref(),
)?;

for (pkg, dep) in by_version.values().flatten() {
if !check_can_modify(&meta.workspace_root, &pkg.manifest_path)? {
continue
}
if let Some(skip_package) = &self.skip_package {
if pkg.name == *skip_package {
continue
}
}

fixers.entry(pkg.name.clone()).or_insert_with(|| {
(Some(pkg.clone()), AutoFixer::from_manifest(&pkg.manifest_path).unwrap())
});
let (_, fixer) = fixers.get_mut(&pkg.name).unwrap();
// We can safely use the rename here, since we found it with `detect_rename`.
let dep_name = dep.rename.as_ref().unwrap_or(&dep.name);
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());
};

if dep.uses_default_features != workspace_default_features_enabled {
fixer.lift_dependency(
dep_name,
&dep.kind,
Some(dep.uses_default_features),
location,
)?;
} else {
fixer.lift_dependency(dep_name, &dep.kind, None, location)?;
}
}

#[cfg(feature = "logging")]
{
let total_changes = by_version.values().map(|v| v.len()).sum::<usize>();
Expand Down Expand Up @@ -277,6 +286,12 @@ impl LiftToWorkspaceCmd {
// TODO check that they all point to the same folder

for pkg in meta.packages.iter() {
if let Some(skip_package) = &self.skip_package {
if pkg.name == *skip_package {
continue
}
}

for dep in pkg.dependencies.iter() {
if dep.name == name {
if dep.path.is_some() {
Expand Down Expand Up @@ -312,6 +327,12 @@ impl LiftToWorkspaceCmd {
let mut unnrenamed = BTreeSet::<String>::new();

for pkg in meta.packages.iter() {
if let Some(skip_package) = &self.skip_package {
if pkg.name == *skip_package {
continue
}
}

for dep in pkg.dependencies.iter() {
if dep.name == name {
if let Some(rename) = &dep.rename {
Expand Down
Loading