-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add do_migrate_from_v0() implementation
- Loading branch information
1 parent
934cc26
commit 30c9a66
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,50 @@ | ||
use crate::errors::DistResult; | ||
use crate::{config, errors::DistResult}; | ||
use crate::config::v0::V0DistConfig; | ||
use crate::config::v1::DistConfig; | ||
use axoasset::toml; | ||
|
||
// A purely-functional subset of `do_migrate_from_v0()`: | ||
// takes a DistMetadata (v0) and returns an equivalent DistConfig (v1) | ||
// without touching files on disk. | ||
// | ||
// This could theoretically have unit tests written for it, but we would | ||
// need to make every piece of DistConfig derive/impl PartialEq, which is | ||
// a lot. -duckinator | ||
fn migrate_from_v0_dist_config(old_config: V0DistConfig) -> DistConfig { | ||
let dist = old_config.dist.map(|dist| dist.to_toml_layer(true)); | ||
let workspace = old_config.workspace; | ||
let package = old_config.package; | ||
|
||
config::v1::DistConfig { | ||
dist, | ||
workspace, | ||
package, | ||
} | ||
} | ||
|
||
pub fn do_migrate_from_v0() -> DistResult<()> { | ||
unimplemented!() | ||
let workspaces = config::get_project()?; | ||
let root_workspace = workspaces.root_workspace(); | ||
let manifest_path = &root_workspace.manifest_path; | ||
|
||
if config::v1::load(manifest_path).is_ok() { | ||
// We're already on a V1 config, no need to migrate! | ||
return Ok(()); | ||
} | ||
|
||
// Load in the root workspace toml to edit and write back | ||
let Ok(old_config) = config::v0::load(manifest_path) else { | ||
// We don't have a valid v0 _or_ v1 config. No migration can be done. | ||
// It feels weird to return Ok(()) here, but I think it's right? | ||
return Ok(()); | ||
}; | ||
|
||
let config = migrate_from_v0_dist_config(old_config); | ||
|
||
let workspace_toml_text = toml::to_string(&config)?; | ||
|
||
// Write new config file. | ||
axoasset::LocalAsset::write_new(&workspace_toml_text, manifest_path)?; | ||
|
||
Ok(()) | ||
} |