From c9c222a25ccd3cadb62607f263578c1a4aa17bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Wed, 10 Jan 2024 12:35:22 +0100 Subject: [PATCH] Fix workspace detection --- src/actions/build.rs | 8 +++----- src/project.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/actions/build.rs b/src/actions/build.rs index 6baed5f..a882a58 100644 --- a/src/actions/build.rs +++ b/src/actions/build.rs @@ -84,10 +84,8 @@ impl BuildAction<'_> { paths::wasm_path_in_wasm_dir(&contract.struct_name(), self.project.project_root()); log::info(format!("Saving {}", target.display())); command::cp(source.clone(), target); - // if a contract is in a module, copy the file also to the module wasm folder - if self.project.odra_toml().has_module(&contract.module_name()) - && contract.module_name() != self.project.name - { + // if it's a workspace, copy the file also to the module wasm folder + if self.project.is_workspace() { let module_wasm_dir = self .project .project_root() @@ -107,7 +105,7 @@ impl BuildAction<'_> { log::info("Optimizing wasm files..."); for contract in self.contracts() { command::wasm_strip(&contract.struct_name(), self.project.project_root()); - if contract.module_name() != self.project.name { + if self.project.is_workspace() { command::wasm_strip( &contract.struct_name(), self.project.project_root().join(contract.module_name()), diff --git a/src/project.rs b/src/project.rs index e3246ab..e543184 100644 --- a/src/project.rs +++ b/src/project.rs @@ -237,6 +237,11 @@ impl Project { } } + /// Checks if the project is a workspace. + pub fn is_workspace(&self) -> bool { + !self.members.is_empty() + } + /// Searches for main Projects' Cargo.toml. pub fn find_cargo_toml(path: PathBuf) -> Option { match Self::find_file_upwards("Odra.toml", path) { @@ -310,14 +315,10 @@ impl Project { .filter(|member| odra_toml.has_module(member)) .map(|member| (member.clone(), member.clone())) .collect(), - None => vec![(Self::detect_project_name(cargo_toml_path), "".to_string())], + None => vec![], } } - fn detect_project_name(cargo_toml_path: &PathBuf) -> String { - load_cargo_toml(cargo_toml_path).package.unwrap().name - } - fn odra_project_dependency(odra_location: OdraLocation, init: bool) -> Dependency { let (version, path, git, branch) = match odra_location { OdraLocation::Local(path) => {