Skip to content

Commit 6ee82a9

Browse files
authored
Merge branch 'master' into bitzoic-signature
2 parents 442e134 + 7aa59f9 commit 6ee82a9

File tree

43 files changed

+3006
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3006
-85
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ jobs:
239239
cargo install --locked --debug --path ./forc-plugins/forc-doc
240240
cargo install --locked --debug --path ./forc-plugins/forc-tx
241241
cargo install --locked --debug --path ./forc-plugins/forc-crypto
242+
cargo install --locked --debug --path ./forc-plugins/forc-migrate
242243
cargo install --locked --debug forc-explore
243244
- name: Install mdbook-forc-documenter
244245
run: cargo install --locked --debug --path ./scripts/mdbook-forc-documenter

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"forc-plugins/forc-doc",
1010
"forc-plugins/forc-fmt",
1111
"forc-plugins/forc-lsp",
12+
"forc-plugins/forc-migrate",
1213
"forc-plugins/forc-tx",
1314
"forc-test",
1415
"forc-tracing",

docs/book/spell-check-custom-words.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,9 @@ fmt
231231
deallocated
232232
deallocate
233233
destructors
234-
destructor
234+
destructor
235+
semiautomatically
236+
FuelLabs
237+
github
238+
toml
239+
hardcoded

docs/book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@
105105
- [forc explore](./forc/plugins/forc_explore.md)
106106
- [forc fmt](./forc/plugins/forc_fmt.md)
107107
- [forc lsp](./forc/plugins/forc_lsp.md)
108+
- [forc migrate](./forc/plugins/forc_migrate.md)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# forc migrate

forc-plugins/forc-doc/src/cli.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ forc_util::cli_examples! {
88
[ Build the docs for a project in the current path and open it in the browser => "forc doc --open" ]
99
[ Build the docs for a project located in another path => "forc doc --path {path}" ]
1010
[ Build the docs for the current project exporting private types => "forc doc --document-private-items" ]
11-
[ Build the docs offline without downloading any dependency from the network => "forc doc --offline" ]
11+
[ Build the docs offline without downloading any dependencies => "forc doc --offline" ]
1212
}
1313
}
1414

@@ -35,11 +35,8 @@ pub struct Command {
3535
/// Meaning it will only try to use previously downloaded dependencies.
3636
#[clap(long = "offline")]
3737
pub offline: bool,
38-
/// Silent mode. Don't output any warnings or errors to the command line.
39-
#[clap(long = "silent", short = 's')]
40-
pub silent: bool,
4138
/// Requires that the Forc.lock file is up-to-date. If the lock file is missing, or it
42-
/// needs to be updated, Forc will exit with an error
39+
/// needs to be updated, Forc will exit with an error.
4340
#[clap(long)]
4441
pub locked: bool,
4542
/// Do not build documentation for dependencies.
@@ -50,10 +47,11 @@ pub struct Command {
5047
/// Possible values: PUBLIC, LOCAL, <GATEWAY_URL>
5148
#[clap(long)]
5249
pub ipfs_node: Option<IPFSNode>,
53-
5450
#[cfg(test)]
5551
pub(crate) doc_path: Option<String>,
56-
5752
#[clap(flatten)]
5853
pub experimental: sway_features::CliFields,
54+
/// Silent mode. Don't output any warnings or errors to the command line.
55+
#[clap(long = "silent", short = 's')]
56+
pub silent: bool,
5957
}

forc-plugins/forc-fmt/src/main.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use forc_pkg::{
77
WorkspaceManifestFile,
88
};
99
use forc_tracing::{init_tracing_subscriber, println_error, println_green, println_red};
10-
use forc_util::fs_locking::PidFileLocking;
10+
use forc_util::fs_locking::is_file_dirty;
1111
use prettydiff::{basic::DiffOp, diff_lines};
1212
use std::{
1313
default::Default,
@@ -101,15 +101,6 @@ fn run() -> Result<()> {
101101
Ok(())
102102
}
103103

104-
/// Checks if the specified file is marked as "dirty".
105-
/// This is used to prevent formatting files that are currently open in an editor
106-
/// with unsaved changes.
107-
///
108-
/// Returns `true` if a corresponding "dirty" flag file exists, `false` otherwise.
109-
fn is_file_dirty<X: AsRef<Path>>(path: X) -> bool {
110-
PidFileLocking::lsp(path.as_ref()).is_locked()
111-
}
112-
113104
/// Recursively get a Vec<PathBuf> of subdirectories that contains a Forc.toml.
114105
fn get_sway_dirs(workspace_dir: PathBuf) -> Vec<PathBuf> {
115106
let mut dirs_to_format = vec![];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "forc-migrate"
3+
version.workspace = true
4+
description = "Migrate Sway projects to the next breaking change version of Sway."
5+
authors.workspace = true
6+
edition.workspace = true
7+
homepage.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
11+
[dependencies]
12+
anyhow.workspace = true
13+
clap = { workspace = true, features = ["derive"] }
14+
forc-pkg.workspace = true
15+
forc-tracing.workspace = true
16+
forc-util.workspace = true
17+
itertools.workspace = true
18+
num-bigint.workspace = true
19+
sha2.workspace = true
20+
sway-ast.workspace = true
21+
sway-core.workspace = true
22+
sway-error.workspace = true
23+
sway-features.workspace = true
24+
sway-types.workspace = true
25+
swayfmt.workspace = true
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use clap::Parser;
2+
3+
use crate::{
4+
cli::{
5+
self,
6+
shared::{
7+
compile_package, create_migration_diagnostic, print_features_and_migration_steps,
8+
},
9+
},
10+
get_migration_steps_or_return,
11+
migrations::{DryRun, MigrationStepKind},
12+
};
13+
use anyhow::{Ok, Result};
14+
use forc_util::format_diagnostic;
15+
use itertools::Itertools;
16+
use sway_core::Engines;
17+
18+
forc_util::cli_examples! {
19+
crate::cli::Opt {
20+
[ Check the project in the current path => "forc migrate check"]
21+
[ Check the project located in another path => "forc migrate check --path {path}" ]
22+
}
23+
}
24+
25+
/// Check the project for code that needs to be migrated.
26+
///
27+
/// Dry-runs the migration steps and prints places in code that need to be reviewed or changed.
28+
#[derive(Debug, Parser)]
29+
pub(crate) struct Command {
30+
#[clap(flatten)]
31+
pub check: cli::shared::Compile,
32+
}
33+
34+
pub(crate) fn exec(command: Command) -> Result<()> {
35+
let migration_steps = get_migration_steps_or_return!();
36+
let engines = Engines::default();
37+
let build_instructions = command.check;
38+
39+
let mut program_info = compile_package(&engines, &build_instructions)?;
40+
41+
// Dry-run all the migration steps.
42+
let mut check_result = vec![];
43+
for (feature, migration_steps) in migration_steps.iter() {
44+
for migration_step in migration_steps.iter() {
45+
let migration_point_spans = match migration_step.kind {
46+
MigrationStepKind::Instruction(instruction) => instruction(&program_info)?,
47+
MigrationStepKind::CodeModification(modification, _) => {
48+
modification(&mut program_info.as_mut(), DryRun::Yes)?
49+
}
50+
MigrationStepKind::Interaction(instruction, _, _) => instruction(&program_info)?,
51+
};
52+
53+
check_result.push((feature, migration_step, migration_point_spans));
54+
}
55+
}
56+
57+
// For every migration step, display the found occurrences in code that require migration effort, if any.
58+
for (feature, migration_step, occurrences_spans) in check_result.iter() {
59+
if let Some(diagnostic) =
60+
create_migration_diagnostic(engines.se(), feature, migration_step, occurrences_spans)
61+
{
62+
format_diagnostic(&diagnostic);
63+
}
64+
}
65+
66+
// Display the summary of the migration effort.
67+
let features_and_migration_steps = check_result
68+
.iter()
69+
.chunk_by(|(feature, _, _)| feature)
70+
.into_iter()
71+
.map(|(key, chunk)| {
72+
(
73+
**key,
74+
chunk
75+
.map(|(_, migration_step, migration_point_spans)| {
76+
(*migration_step, Some(migration_point_spans.len()))
77+
})
78+
.collect::<Vec<_>>(),
79+
)
80+
})
81+
.collect::<Vec<_>>();
82+
83+
println!("Migration effort:");
84+
println!();
85+
print_features_and_migration_steps(&features_and_migration_steps);
86+
87+
Ok(())
88+
}

0 commit comments

Comments
 (0)