From 3133c48f6aa7404947379fdc65412a80b0adaf82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= <26653921+dj8yfo@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:27:19 +0300 Subject: [PATCH] fix(nep330): Fallback to `CARGO_PKG_REPOSITORY` and `CARGO_PKG_VERSION` when `NEP330_*` variables are not provided (#1215) To avoid problems on manual `cargo build` and older versions of cargo-near (<0.7.0) that do not provide `NEP330_*` environment variables --- near-sdk-macros/src/core_impl/contract_metadata/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/near-sdk-macros/src/core_impl/contract_metadata/mod.rs b/near-sdk-macros/src/core_impl/contract_metadata/mod.rs index b2d51588e..91b2c0503 100644 --- a/near-sdk-macros/src/core_impl/contract_metadata/mod.rs +++ b/near-sdk-macros/src/core_impl/contract_metadata/mod.rs @@ -56,13 +56,17 @@ struct Standard { impl ContractMetadata { fn populate(mut self) -> Self { if self.link.is_none() { - let field_val = std::env::var("NEP330_LINK").unwrap_or(String::from("")); + let field_val = std::env::var("NEP330_LINK") + .or(std::env::var("CARGO_PKG_REPOSITORY")) + .unwrap_or(String::from("")); if !field_val.is_empty() { self.link = Some(field_val); } } if self.version.is_none() { - let field_val = std::env::var("NEP330_VERSION").unwrap_or(String::from("")); + let field_val = std::env::var("NEP330_VERSION") + .or(std::env::var("CARGO_PKG_VERSION")) + .unwrap_or(String::from("")); if !field_val.is_empty() { self.version = Some(field_val); }