Skip to content

Commit

Permalink
refactored clone_contract_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Feb 27, 2024
1 parent ede1bf9 commit 6a1f839
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interactive-clap = "0.2.8"
interactive-clap-derive = "0.2.8"
near-cli-rs = { version = "0.7.7", default-features = false }
dunce = "1"
tempfile = "3.10.1"

[features]
default = ["ledger"]
Expand Down
28 changes: 18 additions & 10 deletions cargo-near/src/commands/build_command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,28 @@ pub fn docker_run(args: BuildCommand) -> color_eyre::eyre::Result<camino::Utf8Pa
.to_string();
cargo_args.extend(&["--color", &color]);

let contract_path: camino::Utf8PathBuf = if let Some(manifest_path) = &args.manifest_path {
let mut contract_path: camino::Utf8PathBuf = if let Some(manifest_path) = &args.manifest_path {
manifest_path.into()
} else {
camino::Utf8PathBuf::from_path_buf(std::env::current_dir()?).map_err(|err| {
color_eyre::eyre::eyre!("failed to convert path {}", err.to_string_lossy())
color_eyre::eyre::eyre!("Failed to convert path {}", err.to_string_lossy())
})?
};

let mut tmp_contract_path = contract_path.clone();
tmp_contract_path.push("tmp");
let mut clone_contract_cmd = Command::new("cp");
clone_contract_cmd.args(["-a", &contract_path.as_str(), &tmp_contract_path.as_str()]);
let tmp_contract_dir = tempfile::tempdir()?;
let mut tmp_contract_path = tmp_contract_dir.path().to_path_buf();

let mut clone_contract_cmd = Command::new("git");
clone_contract_cmd.args([
"clone",
&contract_path.as_str(),
&tmp_contract_path.to_string_lossy(),
]);
clone_contract_cmd
.status()
.wrap_err("Failed to clone project to temporary directory.")?;

let volume = format!("{tmp_contract_path}:/host");
let volume = format!("{}:/host", tmp_contract_path.to_string_lossy());
let mut docker_args = vec![
"--name",
"cargo-near-container",
Expand Down Expand Up @@ -146,9 +151,12 @@ pub fn docker_run(args: BuildCommand) -> color_eyre::eyre::Result<camino::Utf8Pa

for entry in dir.flatten() {
if entry.path().extension().unwrap().to_str().unwrap() == "wasm" {
return camino::Utf8PathBuf::from_path_buf(entry.path()).map_err(|err| {
color_eyre::eyre::eyre!("failed to convert path {}", err.to_string_lossy())
});
contract_path.push("contract.wasm");
let _ = std::fs::rename::<std::path::PathBuf, camino::Utf8PathBuf>(
entry.path(),
contract_path.clone(),
);
return Ok(contract_path);
}
}

Expand Down

0 comments on commit 6a1f839

Please sign in to comment.