Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover other than default target dirs #69

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/paths.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Paths utils.

use std::path::{Path, PathBuf};
use std::{
path::{Path, PathBuf},
process::Command,
};

use convert_case::{Boundary, Case, Casing};

Expand All @@ -11,11 +14,41 @@ pub fn wasm_file_name(contract_name: &str) -> PathBuf {

/// Returns *.wasm file path in target directory.
pub fn wasm_path_in_target(contract_name: &str, project_root: PathBuf) -> PathBuf {
// extract target dir
let target_dir = get_build_target_dir();
project_root
.join("target/wasm32-unknown-unknown/release")
.join(format!(
"{}/wasm32-unknown-unknown/release",
target_dir.display()
))
.join(wasm_file_name(contract_name))
}

fn get_build_target_dir() -> PathBuf {
let cmd = "cargo config get build.target-dir -Z unstable-options";
let output = Command::new("sh").arg("-c").arg(cmd).output();

if output.is_err() {
return PathBuf::from("target");
}

// convert output to string
let target_dir = String::from_utf8(output.unwrap().stdout).unwrap();

// output is in format build.target-dir = "../target"
// convert it to PathBuf
let target_dir = target_dir.split('=').collect::<Vec<&str>>();
let target_dir = target_dir.get(1);

if target_dir.is_none() {
return PathBuf::from("target");
}

let target = target_dir.unwrap().trim().to_string().replace('\"', "");

PathBuf::from(target)
}

/// Returns *.wasm file path in wasm directory.
pub fn wasm_path_in_wasm_dir(contract_name: &str, project_root: &Path) -> PathBuf {
wasm_dir(project_root).join(wasm_file_name(contract_name))
Expand Down
Loading