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

(config-migration) Don't modify [profile.dist] until after migrations; consolidate migrations under one prompt. #1704

Merged
merged 3 commits into from
Jan 21, 2025
Merged
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
57 changes: 28 additions & 29 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ fn do_migrate_from_rust_workspace() -> DistResult<()> {
return Ok(());
}

eprintln!("migrating dist config from Cargo.toml to dist-workspace.toml...");

// Load in the root workspace toml to edit and write back
let workspace_toml = config::load_toml(&root_workspace.manifest_path)?;
let mut original_workspace_toml = workspace_toml.clone();
Expand Down Expand Up @@ -161,10 +163,11 @@ fn do_migrate_from_dist_toml() -> DistResult<()> {
return Ok(());
}

eprintln!("migrating dist config from dist.toml to dist-workspace.toml...");

// OK, now we know we have a root-level dist.toml. Time to fix that.
let workspace_toml = config::load_toml(&root_workspace.manifest_path)?;

eprintln!("Migrating tables");
// Init a generic workspace with the appropriate members
let mut new_workspace_toml = new_generic_workspace();
// First copy the [package] section
Expand Down Expand Up @@ -236,41 +239,19 @@ pub fn do_init(cfg: &Config, args: &InitArgs) -> DistResult<()> {
let root_workspace = workspaces.root_workspace();
let check = console::style("✔".to_string()).for_stderr().green();

eprintln!("let's setup your dist config...");
eprintln!();

// For each [workspace] Cargo.toml in the workspaces, initialize [profile]
let mut did_add_profile = false;
for workspace_idx in workspaces.all_workspace_indices() {
let workspace = workspaces.workspace(workspace_idx);
if workspace.kind == WorkspaceKind::Rust {
let mut workspace_toml = config::load_toml(&workspace.manifest_path)?;
did_add_profile |= init_dist_profile(cfg, &mut workspace_toml)?;
config::write_toml(&workspace.manifest_path, workspace_toml)?;
}
}

if did_add_profile {
eprintln!("{check} added [profile.dist] to your workspace Cargo.toml");
}

// Load in the root workspace toml to edit and write back
let workspace_toml = config::load_toml(&root_workspace.manifest_path)?;
let initted = has_metadata_table(root_workspace);

if root_workspace.kind == WorkspaceKind::Generic
let using_dist_toml = root_workspace.kind == WorkspaceKind::Generic
&& initted
&& root_workspace.manifest_path.file_name() == Some("dist.toml")
{
do_migrate()?;
return do_init(cfg, args);
}
&& root_workspace.manifest_path.file_name() == Some("dist.toml");

let using_cargo_toml = root_workspace.kind == WorkspaceKind::Rust && initted;

// Already-initted users should be asked whether to migrate.
if root_workspace.kind == WorkspaceKind::Rust && initted && !args.yes {
if (using_dist_toml || using_cargo_toml) && !args.yes {
let prompt = r#"Would you like to opt in to the new configuration format?
Future versions of dist will feature major changes to the
configuration format, including a new dist-specific configuration file."#;
Future versions of dist will feature major changes to the configuration format."#;
let is_migrating = dialoguer::Confirm::with_theme(&theme())
.with_prompt(prompt)
.default(false)
Expand All @@ -282,6 +263,24 @@ pub fn do_init(cfg: &Config, args: &InitArgs) -> DistResult<()> {
}
}

eprintln!("let's setup your dist config...");
eprintln!();

// For each [workspace] Cargo.toml in the workspaces, initialize [profile]
let mut did_add_profile = false;
for workspace_idx in workspaces.all_workspace_indices() {
let workspace = workspaces.workspace(workspace_idx);
if workspace.kind == WorkspaceKind::Rust {
let mut workspace_toml = config::load_toml(&workspace.manifest_path)?;
did_add_profile |= init_dist_profile(cfg, &mut workspace_toml)?;
config::write_toml(&workspace.manifest_path, workspace_toml)?;
}
}

if did_add_profile {
eprintln!("{check} added [profile.dist] to your workspace Cargo.toml");
}

// If this is a Cargo.toml, offer to either write their config to
// a dist-workspace.toml, or migrate existing config there
let mut newly_initted_generic = false;
Expand Down
Loading