-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
3,403 additions
and
86 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -231,4 +231,9 @@ fmt | |
deallocated | ||
deallocate | ||
destructors | ||
destructor | ||
destructor | ||
semiautomatically | ||
FuelLabs | ||
github | ||
toml | ||
hardcoded |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# forc migrate |
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[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 | ||
num-bigint.workspace = true | ||
sha2.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 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,88 @@ | ||
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(instruction) => instruction(&program_info)?, | ||
MigrationStepKind::CodeModification(modification, _) => { | ||
modification(&mut program_info.as_mut(), DryRun::Yes)? | ||
} | ||
MigrationStepKind::Interaction(instruction, _, _) => instruction(&program_info)?, | ||
}; | ||
|
||
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 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.