From 8294f431767aa88fc65713a4956beab898979511 Mon Sep 17 00:00:00 2001 From: Miraculous Owonubi Date: Sun, 28 Aug 2022 23:31:59 +0400 Subject: [PATCH] alt: shared target folder for faster CI --- cargo-near/src/cargo/metadata.rs | 4 +++- integration-tests/src/lib.rs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cargo-near/src/cargo/metadata.rs b/cargo-near/src/cargo/metadata.rs index 82cdee5f..42b048fb 100644 --- a/cargo-near/src/cargo/metadata.rs +++ b/cargo-near/src/cargo/metadata.rs @@ -22,7 +22,9 @@ impl CrateMetadata { let absolute_manifest_dir = manifest_path.directory()?; let absolute_workspace_root = metadata.workspace_root.canonicalize()?; - if absolute_manifest_dir != absolute_workspace_root { + if std::env::var("CARGO_NEAR_FORCE_WORKSPACE").map_or(false, |v| v == "1") + || absolute_manifest_dir != absolute_workspace_root + { // If the contract is a package in a workspace, we use the package name // as the name of the sub-folder where we put the `.contract` bundle. target_directory = target_directory.join(package_name); diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 68212bea..a3684b89 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -21,6 +21,9 @@ macro_rules! generate_abi { let lib_rs_path = src_dir.join("lib.rs"); fs::write(lib_rs_path, lib_rs)?; + std::env::set_var("CARGO_TARGET_DIR", workspace_dir.join("target")); + std::env::set_var("CARGO_NEAR_FORCE_WORKSPACE", "1"); + cargo_near::exec(cargo_near::NearCommand::Abi(cargo_near::AbiCommand { manifest_path: Some(cargo_path), doc: false, @@ -28,7 +31,7 @@ macro_rules! generate_abi { }))?; let abi_root: near_abi::AbiRoot = - serde_json::from_slice(&fs::read(workspace_dir.join(function_name!()).join("target").join("near").join("abi.json"))?)?; + serde_json::from_slice(&fs::read(workspace_dir.join("target").join("near").join(function_name!()).join("abi.json"))?)?; abi_root }}; (with Cargo $cargo_path:expr; $($code:tt)*) => {