From ae9f82b45229d42ce223766ead297b2345b0dfc8 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 2 Apr 2024 17:19:51 +0200 Subject: [PATCH] Read crate version from cargo.toml (fixes #4583) (#4584) --- crates/api/src/site/leave_admin.rs | 4 ++-- crates/api_common/src/request.rs | 8 ++------ crates/api_crud/src/site/read.rs | 4 ++-- crates/routes/src/nodeinfo.rs | 4 ++-- crates/utils/src/lib.rs | 3 ++- crates/utils/src/version.rs | 1 - docker/Dockerfile | 4 ---- src/lib.rs | 4 ++-- 8 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 crates/utils/src/version.rs diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 0d149d07d..f2db0fc26 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -15,7 +15,7 @@ use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView}; use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{ error::{LemmyError, LemmyErrorType}, - version, + VERSION, }; #[tracing::instrument(skip(context))] @@ -68,7 +68,7 @@ pub async fn leave_admin( Ok(Json(GetSiteResponse { site_view, admins, - version: version::VERSION.to_string(), + version: VERSION.to_string(), my_user: None, all_languages, discussion_languages, diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index 7c8768e41..d77ea2daa 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -19,8 +19,8 @@ use lemmy_utils::{ error::{LemmyError, LemmyErrorType}, settings::structs::{PictrsImageMode, Settings}, spawn_try_task, - version::VERSION, REQWEST_TIMEOUT, + VERSION, }; use mime::Mime; use reqwest::{header::CONTENT_TYPE, Client, ClientBuilder}; @@ -32,11 +32,7 @@ use urlencoding::encode; use webpage::HTML; pub fn client_builder(settings: &Settings) -> ClientBuilder { - let user_agent = format!( - "Lemmy/{}; +{}", - VERSION, - settings.get_protocol_and_hostname() - ); + let user_agent = format!("Lemmy/{VERSION}; +{}", settings.get_protocol_and_hostname()); Client::builder() .user_agent(user_agent.clone()) diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index e99a222fa..77113b08a 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -20,7 +20,7 @@ use lemmy_db_views_actor::structs::{ }; use lemmy_utils::{ error::{LemmyError, LemmyErrorExt, LemmyErrorType}, - version, + VERSION, }; use moka::future::Cache; use once_cell::sync::Lazy; @@ -52,7 +52,7 @@ pub async fn get_site( Ok(GetSiteResponse { site_view, admins, - version: version::VERSION.to_string(), + version: VERSION.to_string(), my_user: None, all_languages, discussion_languages, diff --git a/crates/routes/src/nodeinfo.rs b/crates/routes/src/nodeinfo.rs index 06d4c2dd6..62082b4c8 100644 --- a/crates/routes/src/nodeinfo.rs +++ b/crates/routes/src/nodeinfo.rs @@ -6,7 +6,7 @@ use lemmy_db_views::structs::SiteView; use lemmy_utils::{ cache_header::{cache_1hour, cache_3days}, error::LemmyError, - version, + VERSION, }; use serde::{Deserialize, Serialize}; use url::Url; @@ -56,7 +56,7 @@ async fn node_info(context: web::Data) -> Result crates/utils/src/version.rs; \ cargo build --features "${CARGO_BUILD_FEATURES}"; \ mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \ fi @@ -36,7 +35,6 @@ RUN --mount=type=cache,target=/lemmy/target set -ex; \ # Release build RUN --mount=type=cache,target=/lemmy/target set -ex; \ if [ "${RUST_RELEASE_MODE}" = "release" ]; then \ - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \ [ -z "$USE_RELEASE_CACHE" ] && cargo clean --release; \ cargo build --features "${CARGO_BUILD_FEATURES}" --release; \ mv target/"${RUST_RELEASE_MODE}"/lemmy_server ./lemmy_server; \ @@ -63,7 +61,6 @@ ENV RUST_RELEASE_MODE=${RUST_RELEASE_MODE} \ # Debug build RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \ if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \ - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \ cargo build --features "${CARGO_BUILD_FEATURES}"; \ mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \ fi @@ -71,7 +68,6 @@ RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \ # Release build RUN --mount=type=cache,target=./target,uid=10001,gid=10001 set -ex; \ if [ "${RUST_RELEASE_MODE}" = "release" ]; then \ - echo "pub const VERSION: &str = \"$(git describe --tag)\";" > crates/utils/src/version.rs; \ [ -z "$USE_RELEASE_CACHE" ] && cargo clean --release; \ cargo build --features "${CARGO_BUILD_FEATURES}" --release; \ mv "./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server" /home/lemmy/lemmy_server; \ diff --git a/src/lib.rs b/src/lib.rs index 1b2507f4e..777c5d9ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ use lemmy_utils::{ rate_limit::RateLimitCell, response::jsonify_plain_text_errors, settings::{structs::Settings, SETTINGS}, - version, + VERSION, }; use prometheus::default_registry; use prometheus_metrics::serve_prometheus; @@ -109,7 +109,7 @@ pub struct CmdArgs { /// Placing the main function in lib.rs allows other crates to import it and embed Lemmy pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> { // Print version number to log - println!("Lemmy v{}", version::VERSION); + println!("Lemmy v{VERSION}"); // return error 503 while running db migrations and startup tasks let mut startup_server_handle = None;