mirror of
https://github.com/rust-lang/cargo
synced 2024-09-13 21:11:44 +00:00
feat(fix): Migrate inherited deps with ignored default-features
This commit is contained in:
parent
10012ce9cf
commit
627b1d1470
|
@ -683,6 +683,13 @@ impl TomlDependency {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_features(&self) -> Option<bool> {
|
||||||
|
match self {
|
||||||
|
TomlDependency::Detailed(d) => d.default_features(),
|
||||||
|
TomlDependency::Simple(..) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unused_keys(&self) -> Vec<String> {
|
pub fn unused_keys(&self) -> Vec<String> {
|
||||||
match self {
|
match self {
|
||||||
TomlDependency::Simple(_) => vec![],
|
TomlDependency::Simple(_) => vec![],
|
||||||
|
|
|
@ -45,6 +45,7 @@ use std::{env, fs, str};
|
||||||
|
|
||||||
use anyhow::{bail, Context as _};
|
use anyhow::{bail, Context as _};
|
||||||
use cargo_util::{exit_status_to_string, is_simple_exit_code, paths, ProcessBuilder};
|
use cargo_util::{exit_status_to_string, is_simple_exit_code, paths, ProcessBuilder};
|
||||||
|
use cargo_util_schemas::manifest::TomlManifest;
|
||||||
use rustfix::diagnostics::Diagnostic;
|
use rustfix::diagnostics::Diagnostic;
|
||||||
use rustfix::CodeFix;
|
use rustfix::CodeFix;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
@ -265,6 +266,10 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
|
||||||
format!("{file} from {existing_edition} edition to {prepare_for_edition}"),
|
format!("{file} from {existing_edition} edition to {prepare_for_edition}"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let ws_original_toml = match ws.root_maybe() {
|
||||||
|
MaybePackage::Package(package) => package.manifest().original_toml(),
|
||||||
|
MaybePackage::Virtual(manifest) => manifest.original_toml(),
|
||||||
|
};
|
||||||
if Edition::Edition2024 <= prepare_for_edition {
|
if Edition::Edition2024 <= prepare_for_edition {
|
||||||
let mut document = pkg.manifest().document().clone().into_mut();
|
let mut document = pkg.manifest().document().clone().into_mut();
|
||||||
let mut fixes = 0;
|
let mut fixes = 0;
|
||||||
|
@ -290,10 +295,15 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
|
||||||
fixes += rename_array_of_target_fields_2024(root, "test");
|
fixes += rename_array_of_target_fields_2024(root, "test");
|
||||||
fixes += rename_array_of_target_fields_2024(root, "bench");
|
fixes += rename_array_of_target_fields_2024(root, "bench");
|
||||||
fixes += rename_dep_fields_2024(root, "dependencies");
|
fixes += rename_dep_fields_2024(root, "dependencies");
|
||||||
|
fixes += remove_ignored_default_features_2024(root, "dependencies", ws_original_toml);
|
||||||
fixes += rename_table(root, "dev_dependencies", "dev-dependencies");
|
fixes += rename_table(root, "dev_dependencies", "dev-dependencies");
|
||||||
fixes += rename_dep_fields_2024(root, "dev-dependencies");
|
fixes += rename_dep_fields_2024(root, "dev-dependencies");
|
||||||
|
fixes +=
|
||||||
|
remove_ignored_default_features_2024(root, "dev-dependencies", ws_original_toml);
|
||||||
fixes += rename_table(root, "build_dependencies", "build-dependencies");
|
fixes += rename_table(root, "build_dependencies", "build-dependencies");
|
||||||
fixes += rename_dep_fields_2024(root, "build-dependencies");
|
fixes += rename_dep_fields_2024(root, "build-dependencies");
|
||||||
|
fixes +=
|
||||||
|
remove_ignored_default_features_2024(root, "build-dependencies", ws_original_toml);
|
||||||
for target in root
|
for target in root
|
||||||
.get_mut("target")
|
.get_mut("target")
|
||||||
.and_then(|t| t.as_table_like_mut())
|
.and_then(|t| t.as_table_like_mut())
|
||||||
|
@ -302,10 +312,22 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
|
||||||
.filter_map(|(_k, t)| t.as_table_like_mut())
|
.filter_map(|(_k, t)| t.as_table_like_mut())
|
||||||
{
|
{
|
||||||
fixes += rename_dep_fields_2024(target, "dependencies");
|
fixes += rename_dep_fields_2024(target, "dependencies");
|
||||||
|
fixes +=
|
||||||
|
remove_ignored_default_features_2024(target, "dependencies", ws_original_toml);
|
||||||
fixes += rename_table(target, "dev_dependencies", "dev-dependencies");
|
fixes += rename_table(target, "dev_dependencies", "dev-dependencies");
|
||||||
fixes += rename_dep_fields_2024(target, "dev-dependencies");
|
fixes += rename_dep_fields_2024(target, "dev-dependencies");
|
||||||
|
fixes += remove_ignored_default_features_2024(
|
||||||
|
target,
|
||||||
|
"dev-dependencies",
|
||||||
|
ws_original_toml,
|
||||||
|
);
|
||||||
fixes += rename_table(target, "build_dependencies", "build-dependencies");
|
fixes += rename_table(target, "build_dependencies", "build-dependencies");
|
||||||
fixes += rename_dep_fields_2024(target, "build-dependencies");
|
fixes += rename_dep_fields_2024(target, "build-dependencies");
|
||||||
|
fixes += remove_ignored_default_features_2024(
|
||||||
|
target,
|
||||||
|
"build-dependencies",
|
||||||
|
ws_original_toml,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 < fixes {
|
if 0 < fixes {
|
||||||
|
@ -337,6 +359,47 @@ fn rename_dep_fields_2024(parent: &mut dyn toml_edit::TableLike, dep_kind: &str)
|
||||||
fixes
|
fixes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remove_ignored_default_features_2024(
|
||||||
|
parent: &mut dyn toml_edit::TableLike,
|
||||||
|
dep_kind: &str,
|
||||||
|
ws_original_toml: &TomlManifest,
|
||||||
|
) -> usize {
|
||||||
|
let mut fixes = 0;
|
||||||
|
for (name_in_toml, target) in parent
|
||||||
|
.get_mut(dep_kind)
|
||||||
|
.and_then(|t| t.as_table_like_mut())
|
||||||
|
.iter_mut()
|
||||||
|
.flat_map(|t| t.iter_mut())
|
||||||
|
.filter_map(|(k, t)| t.as_table_like_mut().map(|t| (k, t)))
|
||||||
|
{
|
||||||
|
let name_in_toml: &str = &name_in_toml;
|
||||||
|
let ws_deps = ws_original_toml
|
||||||
|
.workspace
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|ws| ws.dependencies.as_ref());
|
||||||
|
if let Some(ws_dep) = ws_deps.and_then(|ws_deps| ws_deps.get(name_in_toml)) {
|
||||||
|
if ws_dep.default_features() == Some(false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if target
|
||||||
|
.get("workspace")
|
||||||
|
.and_then(|i| i.as_value())
|
||||||
|
.and_then(|i| i.as_bool())
|
||||||
|
== Some(true)
|
||||||
|
&& target
|
||||||
|
.get("default-features")
|
||||||
|
.and_then(|i| i.as_value())
|
||||||
|
.and_then(|i| i.as_bool())
|
||||||
|
== Some(false)
|
||||||
|
{
|
||||||
|
target.remove("default-features");
|
||||||
|
fixes += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fixes
|
||||||
|
}
|
||||||
|
|
||||||
fn rename_array_of_target_fields_2024(root: &mut dyn toml_edit::TableLike, kind: &str) -> usize {
|
fn rename_array_of_target_fields_2024(root: &mut dyn toml_edit::TableLike, kind: &str) -> usize {
|
||||||
let mut fixes = 0;
|
let mut fixes = 0;
|
||||||
for target in root
|
for target in root
|
||||||
|
|
|
@ -2753,12 +2753,7 @@ dep_df_false = { version = "0.1.0", default-features = false }
|
||||||
[MIGRATING] pkg_default/Cargo.toml from 2021 edition to 2024
|
[MIGRATING] pkg_default/Cargo.toml from 2021 edition to 2024
|
||||||
[MIGRATING] pkg_df_true/Cargo.toml from 2021 edition to 2024
|
[MIGRATING] pkg_df_true/Cargo.toml from 2021 edition to 2024
|
||||||
[MIGRATING] pkg_df_false/Cargo.toml from 2021 edition to 2024
|
[MIGRATING] pkg_df_false/Cargo.toml from 2021 edition to 2024
|
||||||
[WARNING] [CWD]/pkg_df_false/Cargo.toml: `default-features` is ignored for dep_df_true, since `default-features` was true for `workspace.dependencies.dep_df_true`, this could become a hard error in the future
|
[FIXED] pkg_df_false/Cargo.toml (6 fixes)
|
||||||
[WARNING] [CWD]/pkg_df_false/Cargo.toml: `default-features` is ignored for dep_simple, since `default-features` was not specified for `workspace.dependencies.dep_simple`, this could become a hard error in the future
|
|
||||||
[WARNING] [CWD]/pkg_df_false/Cargo.toml: `default-features` is ignored for dep_df_true, since `default-features` was true for `workspace.dependencies.dep_df_true`, this could become a hard error in the future
|
|
||||||
[WARNING] [CWD]/pkg_df_false/Cargo.toml: `default-features` is ignored for dep_simple, since `default-features` was not specified for `workspace.dependencies.dep_simple`, this could become a hard error in the future
|
|
||||||
[WARNING] [CWD]/pkg_df_false/Cargo.toml: `default-features` is ignored for dep_df_true, since `default-features` was true for `workspace.dependencies.dep_df_true`, this could become a hard error in the future
|
|
||||||
[WARNING] [CWD]/pkg_df_false/Cargo.toml: `default-features` is ignored for dep_simple, since `default-features` was not specified for `workspace.dependencies.dep_simple`, this could become a hard error in the future
|
|
||||||
[UPDATING] `dummy-registry` index
|
[UPDATING] `dummy-registry` index
|
||||||
[LOCKING] 6 packages to latest compatible versions
|
[LOCKING] 6 packages to latest compatible versions
|
||||||
[DOWNLOADING] crates ...
|
[DOWNLOADING] crates ...
|
||||||
|
@ -2790,18 +2785,18 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dep_simple = { workspace = true, default-features = false }
|
dep_simple = { workspace = true}
|
||||||
dep_df_true = { workspace = true, default-features = false }
|
dep_df_true = { workspace = true}
|
||||||
dep_df_false = { workspace = true, default-features = false }
|
dep_df_false = { workspace = true, default-features = false }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
dep_simple = { workspace = true, default-features = false }
|
dep_simple = { workspace = true}
|
||||||
dep_df_true = { workspace = true, default-features = false }
|
dep_df_true = { workspace = true}
|
||||||
dep_df_false = { workspace = true, default-features = false }
|
dep_df_false = { workspace = true, default-features = false }
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
dep_simple = { workspace = true, default-features = false }
|
dep_simple = { workspace = true}
|
||||||
dep_df_true = { workspace = true, default-features = false }
|
dep_df_true = { workspace = true}
|
||||||
dep_df_false = { workspace = true, default-features = false }
|
dep_df_false = { workspace = true, default-features = false }
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue