From 9ea1695f018fccf0c9ad34a3eae6e5dac94b88f8 Mon Sep 17 00:00:00 2001 From: bing Date: Wed, 22 Mar 2023 01:10:45 +0000 Subject: [PATCH] forc-pkg: throw error for nested workspaces (#4321) --- forc-pkg/src/manifest.rs | 4 ++++ .../forc/unexpected_nested_workspace/.gitignore | 2 ++ .../forc/unexpected_nested_workspace/Forc.toml | 2 ++ .../forc/unexpected_nested_workspace/test.toml | 3 +++ .../test_workspace/Forc.lock | 14 ++++++++++++++ .../test_workspace/Forc.toml | 2 ++ .../test_workspace/test_contract/.gitignore | 2 ++ .../test_workspace/test_contract/Forc.toml | 9 +++++++++ .../test_workspace/test_contract/src/main.sw | 1 + .../test_workspace/test_lib/.gitignore | 2 ++ .../test_workspace/test_lib/Forc.toml | 6 ++++++ .../test_workspace/test_lib/src/lib.sw | 1 + .../test_workspace/test_script/.gitignore | 2 ++ .../test_workspace/test_script/Forc.toml | 12 ++++++++++++ .../test_workspace/test_script/src/main.sw | 5 +++++ 15 files changed, 67 insertions(+) create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/.gitignore create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/.gitignore create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/.gitignore create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/.gitignore create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/src/main.sw diff --git a/forc-pkg/src/manifest.rs b/forc-pkg/src/manifest.rs index d38b56b1cb1..90ed23637fe 100644 --- a/forc-pkg/src/manifest.rs +++ b/forc-pkg/src/manifest.rs @@ -835,6 +835,10 @@ impl WorkspaceManifest { member_path ); } + if Self::from_file(&member_path).is_ok() { + bail!("Unexpected nested workspace '{}'. Workspaces are currently only allowed in the project root.", member.display()); + }; + let member_manifest_file = PackageManifestFile::from_file(member_path.clone())?; let pkg_name = member_manifest_file.manifest.project.name; pkg_name_to_paths diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/.gitignore b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/Forc.toml new file mode 100644 index 00000000000..5164e9ff852 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/Forc.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["test_workspace"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test.toml new file mode 100644 index 00000000000..1bf22e98747 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test.toml @@ -0,0 +1,3 @@ +category = "fail" + +# check: $()Unexpected nested workspace 'test_workspace'. Workspaces are currently only allowed in the project root. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.lock new file mode 100644 index 00000000000..81630a591ff --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.lock @@ -0,0 +1,14 @@ +[[package]] +name = 'test_contract' +source = 'member' +dependencies = ['test_lib'] + +[[package]] +name = 'test_lib' +source = 'member' + +[[package]] +name = 'test_script' +source = 'member' +dependencies = ['test_lib'] +contract-dependencies = ['test_contract'] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.toml new file mode 100644 index 00000000000..026c84f44a3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/Forc.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["test_contract", "test_script", "test_lib"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/.gitignore b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/Forc.toml new file mode 100644 index 00000000000..0df18621e96 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "test_contract" +implicit-std = false + +[dependencies] +test_lib = { path = "../test_lib/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/src/main.sw new file mode 100644 index 00000000000..841cc78e0ec --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_contract/src/main.sw @@ -0,0 +1 @@ +contract; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/.gitignore b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/Forc.toml new file mode 100644 index 00000000000..bfce4bee3f8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "test_lib" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/src/lib.sw new file mode 100644 index 00000000000..316a905aa9b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_lib/src/lib.sw @@ -0,0 +1 @@ +library; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/.gitignore b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/Forc.toml new file mode 100644 index 00000000000..5051eff3079 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/Forc.toml @@ -0,0 +1,12 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "test_script" +implicit-std = false + +[dependencies] +test_lib = { path = "../test_lib/" } + +[contract-dependencies] +test_contract = { path = "../test_contract" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/src/main.sw new file mode 100644 index 00000000000..a83d7e638c0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/forc/unexpected_nested_workspace/test_workspace/test_script/src/main.sw @@ -0,0 +1,5 @@ +script; + +fn main() { + +}