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

[WIP] Implement config v0 -> v1 migration. #1653

Draft
wants to merge 51 commits into
base: main
Choose a base branch
from
Draft

Conversation

duckinator
Copy link
Contributor

@duckinator duckinator commented Dec 18, 2024

The following PRs have been split off of this one:

  1. (config-migration) Add BoolOr<T> and Option<BoolOr<T>> helper functions. #1697
  2. (config-migration) Implement Display for ChecksumStyle, derive Default for ArtifactLayer and InstallerLayer #1698
  3. (config-migration) Add the ability to determine and track the config version. #1699
  4. (config-migration) Add config::v0::load() and friends #1701
  5. (config-migration) Add validate_install_paths() and merge_workspace_config() to TomlLayer #1703
  6. (config-migration) Don't modify [profile.dist] until after migrations; consolidate migrations under one prompt. #1704
  7. (config-migration) Make dist::init and dist::tasks into folder-based modules #1705
  8. (config-migration) Move v0-specific functions into dist::config::v0. #1706
  9. (config-migration) Move src/init/{mod -> v0}.rs, add new src/init/mod.rs to re-export functions #1717
  10. (config-migration) Split dist::migrate out from dist::init #1718
  11. (config-migration) Move root_workspace + workspace_toml to where they're used; remove unneeded desired_workspace_kind #1719
  12. (config-migration) Split parts out of dist::init::v0 into other dist::init submodules #1721
  13. (config-migration) Add dist::config::load() and friends #1723
  14. (config-migration) Add config::version::want_v1() and empty do_migrate_from_v0() #1724
  15. (config-migration) Add do_migrate_from_v0() implementation #1725
  16. (config-migration) Split init_dist_profile() out into its own file #1726
  17. (config-migration) Add dist::init::apply_dist #1727
  18. (WIP) Finish apply_dist() #1730
  19. (WIP) add v1 "dist init" #1737

Required functionality for this PR:

  1. make dist migrate move v0 to v1
    • Have do_migrate_from_v0() actually copy workspace members to the new configuration.
  2. make dist init use v1
  3. make everything but dist init load v1
  4. make sure dist plan (and other commands) gives an actionable error for v0 configs

Current state (2025-01-10):

image

image

@duckinator duckinator force-pushed the dist-migrate-v1 branch 4 times, most recently from ce26547 to 9a7d939 Compare December 20, 2024 17:15
@duckinator
Copy link
Contributor Author

duckinator commented Dec 20, 2024

This is currently based off #1661. When that gets merged, I'll rebase off main.

@duckinator
Copy link
Contributor Author

The various apply_*() functions should compile now, and some of it will actually be updated properly.

TODO:

  1. get_new_dist_metadata()
  2. finish up the apply_*() functions

@mistydemeo
Copy link
Contributor

mistydemeo commented Jan 7, 2025

We were discussing get_new_dist_metadata during the call. I'll summarize what it does.

This is the interactive portion of init. It's used in two code paths: a newly-initted system, in which case we have no existing config, and updating existing configuration. If there's existing config, the interactive portions are designed to prefill the choice with the decisions that had already been made the last time; this ensures that mashing enter through the settings preserves the user's existing config without changing anything.

Unlike most of the rest of init, which operates on toml_edit documents, get_new_dist_metadata operates on a DistMetadata struct. It parses the existing config to DistMetadata, edits it in place, and returns the altered document. If there's no existing configuration, it instead initializes a completely empty DistMetadata.

Because this code is working from and generating a DistMetadata, we might not actually have to do any changes at all for this branch beyond swapping to the v1 version of DistMetadata.

For each bit of user-selectable config, we use the dialoguer crate to prompt the user for their input unless the user passed the --yes/-y flag, in which case we pick defaults/their existing config without prompting.

Copy link
Contributor

@mistydemeo mistydemeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment on the as-yet incomplete items in init.rs, just to track them, along with a couple of things to keep an eye on testing.

Aside from the remaining init.rs changes, I think the only other remaining work is in the tests. All of our tests are written in the old config format, and are specifically using Cargo.toml, so they need to be updated to use dist-workspace.toml in the new config format in order to pass.

cargo-dist/src/init.rs Outdated Show resolved Hide resolved
cargo-dist/src/init.rs Outdated Show resolved Hide resolved
cargo-dist/src/init.rs Outdated Show resolved Hide resolved
cargo-dist/src/init.rs Outdated Show resolved Hide resolved
} = &meta;

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole section needs to be uncommented and reimplemented for the new structure.


apply_installers_common(npm_table, &npm.common);

// TODO: similar to shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impl missing here.


apply_installers_common(powershell_table, &powershell.common);

// TODO: similar to shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impl missing here.


apply_installers_common(shell_table, &shell.common);

// TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impl missing here.

cargo-dist/src/init.rs Outdated Show resolved Hide resolved
panic!("Expected [dist.publishers] to be a table");
};

// ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impl missing here.

@mistydemeo mistydemeo mentioned this pull request Jan 11, 2025
11 tasks
package_configs.push(app_config(
workspaces,
pkg_idx,
workspace_layer.clone(),
package_metadata.to_toml_layer(false),
package_metadata.clone(), // fixme: this seems suspect since we call seemingly-mutating functions on it later
Copy link
Contributor Author

@duckinator duckinator Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably fine because package_metadata.to_toml_layer(false) returned a new object anyway?

Comment on lines -237 to -254
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");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved later in the function, to avoid dist init being canceled but still overwriting Cargo.toml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants