Skip to content

Commit

Permalink
Fix workspace detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaplas committed Jan 10, 2024
1 parent 55e1a73 commit c9c222a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/actions/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()),
Expand Down
11 changes: 6 additions & 5 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
match Self::find_file_upwards("Odra.toml", path) {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit c9c222a

Please sign in to comment.