-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add forc-migrate
tool
#6790
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
Merged
Merged
Add forc-migrate
tool
#6790
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
680c735
Add `forc migrate` tool
ironcev d16a7be
Fix spell checking errors
ironcev 50c4ae8
Fix Markdown issues
ironcev 336a78d
Fix mdbook issues
ironcev 2f3027b
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev c9e9e7b
Smaller refactoring and comments
ironcev 3f3af88
Rename `--manifest-path` to `--path`
ironcev a24e2e7
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev 5273852
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev 4089ebb
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev 749482b
Fix merge issues
ironcev 50210ba
Add matching and modifying and improve storage domains migrations
ironcev 2782874
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev d71d4c9
Fix Clippy and fmt issues
ironcev 8a6fb71
Fix newer Clippy issues
ironcev df8a28c
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev 977ab63
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev d7e94a2
Merge branch 'master' into ironcev/forc-migrate-tool
ironcev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -231,4 +231,9 @@ fmt | |
deallocated | ||
deallocate | ||
destructors | ||
destructor | ||
destructor | ||
semiautomatically | ||
FuelLabs | ||
github | ||
toml | ||
hardcoded |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# forc migrate |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "forc-migrate" | ||
version.workspace = true | ||
description = "Migrate Sway projects to the next breaking change version of Sway." | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
clap = { workspace = true, features = ["derive"] } | ||
forc-pkg.workspace = true | ||
forc-tracing.workspace = true | ||
forc-util.workspace = true | ||
itertools.workspace = true | ||
sway-ast.workspace = true | ||
sway-core.workspace = true | ||
sway-error.workspace = true | ||
sway-features.workspace = true | ||
sway-types.workspace = true | ||
swayfmt.workspace = true |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use clap::Parser; | ||
|
||
use crate::{ | ||
cli::{ | ||
self, | ||
shared::{ | ||
compile_package, create_migration_diagnostic, print_features_and_migration_steps, | ||
}, | ||
}, | ||
get_migration_steps_or_return, | ||
migrations::{DryRun, MigrationStepKind}, | ||
}; | ||
use anyhow::{Ok, Result}; | ||
use forc_util::format_diagnostic; | ||
use itertools::Itertools; | ||
use sway_core::Engines; | ||
|
||
forc_util::cli_examples! { | ||
crate::cli::Opt { | ||
[ Check the project in the current path => "forc migrate check"] | ||
[ Check the project located in another path => "forc migrate check --path {path}" ] | ||
} | ||
} | ||
|
||
/// Check the project for code that needs to be migrated. | ||
/// | ||
/// Dry-runs the migration steps and prints places in code that need to be reviewed or changed. | ||
#[derive(Debug, Parser)] | ||
pub(crate) struct Command { | ||
#[clap(flatten)] | ||
pub check: cli::shared::Compile, | ||
} | ||
|
||
pub(crate) fn exec(command: Command) -> Result<()> { | ||
let migration_steps = get_migration_steps_or_return!(); | ||
let engines = Engines::default(); | ||
let build_instructions = command.check; | ||
|
||
let mut program_info = compile_package(&engines, &build_instructions)?; | ||
|
||
// Dry-run all the migration steps. | ||
let mut check_result = vec![]; | ||
for (feature, migration_steps) in migration_steps.iter() { | ||
for migration_step in migration_steps.iter() { | ||
let migration_point_spans = match migration_step.kind { | ||
MigrationStepKind::Instruction(migration) => migration(&program_info)?, | ||
MigrationStepKind::CodeTransformation(migration, _) => { | ||
migration(&mut program_info.as_mut(), DryRun::Yes)? | ||
} | ||
}; | ||
|
||
check_result.push((feature, migration_step, migration_point_spans)); | ||
} | ||
} | ||
|
||
// For every migration step, display the found occurrences in code that require migration effort, if any. | ||
for (feature, migration_step, occurrences_spans) in check_result.iter() { | ||
if let Some(diagnostic) = | ||
create_migration_diagnostic(engines.se(), feature, migration_step, occurrences_spans) | ||
{ | ||
format_diagnostic(&diagnostic); | ||
} | ||
} | ||
|
||
// Display the summary of the migration effort. | ||
let features_and_migration_steps = check_result | ||
.iter() | ||
.chunk_by(|(feature, _, _)| feature) | ||
.into_iter() | ||
.map(|(key, chunk)| { | ||
( | ||
**key, | ||
chunk | ||
.map(|(_, migration_step, migration_point_spans)| { | ||
(*migration_step, Some(migration_point_spans.len())) | ||
}) | ||
.collect::<Vec<_>>(), | ||
) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
println!("Migration effort:"); | ||
println!(); | ||
print_features_and_migration_steps(&features_and_migration_steps); | ||
|
||
Ok(()) | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) mod check; | ||
pub(crate) mod run; | ||
pub(crate) mod show; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.