constants: dedup CUPRATE_*

This commit is contained in:
hinto.janai 2023-12-11 20:04:31 -05:00
parent 6a48806e4b
commit 2853e8ed5f
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
3 changed files with 31 additions and 28 deletions

View file

@ -2,20 +2,23 @@
use const_format::{formatcp,assertcp}; use const_format::{formatcp,assertcp};
//---------------------------------------------------------------------------------------------------- Version //---------------------------------------------------------------------------------------------------- Version
/// The name of the project and main directory.
pub const CUPRATE: &str = "Cuprate";
/// The name of the Cuprate node binary. /// The name of the Cuprate node binary.
pub const CUPRATE_BIN: &str = "cuprate"; pub const BIN: &str = "cuprate";
/// `cuprate` version /// `cuprate` version
/// ///
/// This is the version of `cuprate`, the `daemon`, determined by the `Cargo.toml` 'version'. /// This is the version of `cuprate`, the `daemon`, determined by the `Cargo.toml` 'version'.
pub const CUPRATE_VERSION: &str = { pub const VERSION: &str = {
let version = env!("CARGO_PKG_VERSION"); const V: &str = env!("CARGO_PKG_VERSION");
assertcp!(version.len() != 0, "CARGO_PKG_VERSION is 0 length"); assertcp!(V.len() != 0, "CARGO_PKG_VERSION is 0 length");
formatcp!("v{version}") formatcp!("v{V}")
}; };
/// `cuprate` + version, e.g: `cuprate v0.0.1` /// `cuprate` + version, e.g: `cuprate v0.0.1`
pub const CUPRATE_NAME_VER: &str = formatcp!("{CUPRATE_BIN} {CUPRATE_VERSION}"); pub const NAME_VER: &str = formatcp!("{BIN} {VERSION}");
/// - cuprate name + version /// - cuprate name + version
/// - OS + Arch /// - OS + Arch
@ -28,7 +31,7 @@ pub const CUPRATE_NAME_VER: &str = formatcp!("{CUPRATE_BIN} {CUPRATE_VERSION}");
/// windows x86_64 /// windows x86_64
/// 34dd105a0c585dc34ba0a1ace625663bde00a1dc /// 34dd105a0c585dc34ba0a1ace625663bde00a1dc
/// ``` /// ```
pub const CUPRATE_BUILD_INFO: &str = formatcp!("{CUPRATE_NAME_VER}\n{OS_ARCH}\n{COMMIT}"); pub const BUILD_INFO: &str = formatcp!("{NAME_VER}\n{OS_ARCH}\n{COMMIT}");
/// Build commit. /// Build commit.
/// ///
@ -37,57 +40,57 @@ pub const CUPRATE_BUILD_INFO: &str = formatcp!("{CUPRATE_NAME_VER}\n{OS_ARCH}\n{
/// CI running on PR branches with different branch names messes it up. /// CI running on PR branches with different branch names messes it up.
/// ///
/// This should get set automatically in `build.rs`. /// This should get set automatically in `build.rs`.
pub const CUPRATE_COMMIT: &str = env!("COMMIT"); pub const COMMIT: &str = env!("COMMIT");
//---------------------------------------------------------------------------------------------------- Identifiers //---------------------------------------------------------------------------------------------------- Identifiers
/// Build profile (debug/release) /// Build profile (debug/release)
/// ///
/// This is `Debug` is `debug_assertions` is detected, else it is `Release`. /// This is `Debug` is `debug_assertions` is detected, else it is `Release`.
pub const CUPRATE_BUILD: &str = if cfg!(debug_assertions) { "Debug" } else { "Release" }; pub const BUILD: &str = if cfg!(debug_assertions) { "Debug" } else { "Release" };
/// Cuprate's `dbus` connection name. /// Cuprate's `dbus` connection name.
pub const CUPRATE_DBUS: &str = "com.github.Cuprate"; pub const DBUS: &str = "com.github.Cuprate";
/// `cuprate`'s HTTP user-agent, e.g: `cuprate/v0.0.1`. /// `cuprate`'s HTTP user-agent, e.g: `cuprate/v0.0.1`.
pub const CUPRATE_USER_AGENT: &str = formatcp!("{CUPRATE_BIN}/{CUPRATE_VERSION}"); pub const USER_AGENT: &str = formatcp!("{BIN}/{VERSION}");
/// Depends on build target, e.g: /// Depends on build target, e.g:
/// - `windows x86_64` /// - `windows x86_64`
/// - `macos aarch64` /// - `macos aarch64`
/// - `linux x86_64` /// - `linux x86_64`
pub const OS_ARCH: &str = formatcp!("{} {}", std::env::consts::OS, std::env::consts::ARCH);; pub const OS_ARCH: &str = formatcp!("{} {}", std::env::consts::OS, std::env::consts::ARCH);
//---------------------------------------------------------------------------------------------------- Image //---------------------------------------------------------------------------------------------------- Image
/// Cuprate's icon: /// Cuprate's icon:
/// - `512x512` /// - `512x512`
/// - `RGBA` /// - `RGBA`
/// - `PNG` /// - `PNG`
pub const CUPRATE_ICON: &[u8] = include_bytes!("../../assets/images/icon/512.png"); pub const ICON: &[u8] = todo!(); // include_bytes!("../../assets/images/icon/512.png");
/// The height and width of [`CUPRATE_ICON`]. /// The height and width of [`ICON`].
pub const CUPRATE_ICON_SIZE: u32 = 512; pub const ICON_SIZE: u32 = 512;
//---------------------------------------------------------------------------------------------------- Directory locations //---------------------------------------------------------------------------------------------------- Directory locations
/// The name of the main project folder. /// The name of the main project folder.
/// ///
/// Capitalization may depend on OS (if using `disk`). /// Capitalization may depend on OS (if using `disk`).
pub const CUPRATE_PROJECT_DIR: &str = "Cuprate"; pub const PROJECT_DIR: &str = "Cuprate";
/// The sub-directory where database files are saved. /// The sub-directory where database files are saved.
pub const CUPRATE_DB_SUB_DIR: &str = "db"; pub const DB_SUB_DIR: &str = "db";
/// The sub-directory where state is saved. /// The sub-directory where state is saved.
pub const CUPRATE_STATE_SUB_DIR: &str = "state"; pub const STATE_SUB_DIR: &str = "state";
/// The sub-directory for misc text files. /// The sub-directory for misc text files.
pub const CUPRATE_TXT_SUB_DIR: &str = "txt"; pub const TXT_SUB_DIR: &str = "txt";
/// The sub-directory for SSL (cert/key) files. /// The sub-directory for SSL (cert/key) files.
pub const CUPRATE_SSL_SUB_DIR: &str = "ssl"; pub const SSL_SUB_DIR: &str = "ssl";
//---------------------------------------------------------------------------------------------------- Text //---------------------------------------------------------------------------------------------------- Text
/// Cuprate's copyright notice. /// Cuprate's copyright notice.
pub const CUPRATE_COPYRIGHT: &str = pub const COPYRIGHT: &str =
r#"Cuprate is dual-licensed under MIT/AGPL-3.0. r#"Cuprate is dual-licensed under MIT/AGPL-3.0.
Its dependency tree includes many other licenses. Its dependency tree includes many other licenses.
For more information on the project, see below: For more information on the project, see below:
@ -95,19 +98,19 @@ For more information on the project, see below:
//---------------------------------------------------------------------------------------------------- Network //---------------------------------------------------------------------------------------------------- Network
/// Default P2P port for `cuprate`. /// Default P2P port for `cuprate`.
pub const CUPRATE_P2P_PORT: u16 = 18080; pub const DEFAULT_P2P_PORT: u16 = 18080;
/// Default RPC port for `cuprate`. /// Default RPC port for `cuprate`.
pub const CUPRATE_RPC_PORT: u16 = 18081; pub const DEFAULT_RPC_PORT: u16 = 18081;
/// Default ZMQ port for `cuprate`. /// Default ZMQ port for `cuprate`.
pub const CUPRATE_ZMQ_PORT: u16 = 18083; pub const DEFAULT_ZMQ_PORT: u16 = 18083;
/// Default restricted RPC port for `cuprate`. /// Default restricted RPC port for `cuprate`.
pub const CUPRATE_RESTRICTED_RPC_PORT: u16 = 18089; pub const DEFAULT_RESTRICTED_RPC_PORT: u16 = 18089;
//---------------------------------------------------------------------------------------------------- Config //---------------------------------------------------------------------------------------------------- Config
/// The default configuration file, as a `str`. /// The default configuration file, as a `str`.
/// ///
/// `cuprate` will write this to disk and use it if there is no config detected. /// `cuprate` will write this to disk and use it if there is no config detected.
pub const CUPRATE_CONFIG: &str = include_str!(formatcp!("../config/{CUPRATE_VERSION}.toml")); pub const DEFAULT_CONFIG: &str = todo!(); // include_str!(formatcp!("../config/{VERSION}.toml"));
//---------------------------------------------------------------------------------------------------- TESTS //---------------------------------------------------------------------------------------------------- TESTS
//#[cfg(test)] //#[cfg(test)]

View file

@ -4,7 +4,7 @@ use disk::Empty;
use std::path::{Path,PathBuf}; use std::path::{Path,PathBuf};
use const_format::formatcp; use const_format::formatcp;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use crate::constants::CUPRATE_PROJECT_DIR; use crate::constants::PROJECT_DIR;
//---------------------------------------------------------------------------------------------------- Constants //---------------------------------------------------------------------------------------------------- Constants
// Compile-time zipped bytes of Cuprate documentation. // Compile-time zipped bytes of Cuprate documentation.

View file

@ -26,7 +26,7 @@ fn main() {
// Merge CLI options with on-disk config and init the logger. // Merge CLI options with on-disk config and init the logger.
// //
// INVARIANT1: Logger gets set here, don't init elsewhere. // INVARIANT1: Logger gets set here, don't init elsewhere.
// INVARIANT2: Initialize `CONFIG` - this must be set once only // INVARIANT2: WE must initialize `crate::config::CONFIG`
// //
// The reason the logger gets initialized here is because: // The reason the logger gets initialized here is because:
// 1. We want to log within `init()`, but... // 1. We want to log within `init()`, but...