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};
//---------------------------------------------------------------------------------------------------- Version
/// The name of the project and main directory.
pub const CUPRATE: &str = "Cuprate";
/// The name of the Cuprate node binary.
pub const CUPRATE_BIN: &str = "cuprate";
pub const BIN: &str = "cuprate";
/// `cuprate` version
///
/// This is the version of `cuprate`, the `daemon`, determined by the `Cargo.toml` 'version'.
pub const CUPRATE_VERSION: &str = {
let version = env!("CARGO_PKG_VERSION");
assertcp!(version.len() != 0, "CARGO_PKG_VERSION is 0 length");
formatcp!("v{version}")
pub const VERSION: &str = {
const V: &str = env!("CARGO_PKG_VERSION");
assertcp!(V.len() != 0, "CARGO_PKG_VERSION is 0 length");
formatcp!("v{V}")
};
/// `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
/// - OS + Arch
@ -28,7 +31,7 @@ pub const CUPRATE_NAME_VER: &str = formatcp!("{CUPRATE_BIN} {CUPRATE_VERSION}");
/// windows x86_64
/// 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.
///
@ -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.
///
/// This should get set automatically in `build.rs`.
pub const CUPRATE_COMMIT: &str = env!("COMMIT");
pub const COMMIT: &str = env!("COMMIT");
//---------------------------------------------------------------------------------------------------- Identifiers
/// Build profile (debug/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.
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`.
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:
/// - `windows x86_64`
/// - `macos aarch64`
/// - `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
/// Cuprate's icon:
/// - `512x512`
/// - `RGBA`
/// - `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`].
pub const CUPRATE_ICON_SIZE: u32 = 512;
/// The height and width of [`ICON`].
pub const ICON_SIZE: u32 = 512;
//---------------------------------------------------------------------------------------------------- Directory locations
/// The name of the main project folder.
///
/// 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.
pub const CUPRATE_DB_SUB_DIR: &str = "db";
pub const DB_SUB_DIR: &str = "db";
/// 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.
pub const CUPRATE_TXT_SUB_DIR: &str = "txt";
pub const TXT_SUB_DIR: &str = "txt";
/// The sub-directory for SSL (cert/key) files.
pub const CUPRATE_SSL_SUB_DIR: &str = "ssl";
pub const SSL_SUB_DIR: &str = "ssl";
//---------------------------------------------------------------------------------------------------- Text
/// Cuprate's copyright notice.
pub const CUPRATE_COPYRIGHT: &str =
pub const COPYRIGHT: &str =
r#"Cuprate is dual-licensed under MIT/AGPL-3.0.
Its dependency tree includes many other licenses.
For more information on the project, see below:
@ -95,19 +98,19 @@ For more information on the project, see below:
//---------------------------------------------------------------------------------------------------- Network
/// Default P2P port for `cuprate`.
pub const CUPRATE_P2P_PORT: u16 = 18080;
pub const DEFAULT_P2P_PORT: u16 = 18080;
/// Default RPC port for `cuprate`.
pub const CUPRATE_RPC_PORT: u16 = 18081;
pub const DEFAULT_RPC_PORT: u16 = 18081;
/// 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`.
pub const CUPRATE_RESTRICTED_RPC_PORT: u16 = 18089;
pub const DEFAULT_RESTRICTED_RPC_PORT: u16 = 18089;
//---------------------------------------------------------------------------------------------------- Config
/// The default configuration file, as a `str`.
///
/// `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
//#[cfg(test)]

View file

@ -4,7 +4,7 @@ use disk::Empty;
use std::path::{Path,PathBuf};
use const_format::formatcp;
use once_cell::sync::OnceCell;
use crate::constants::CUPRATE_PROJECT_DIR;
use crate::constants::PROJECT_DIR;
//---------------------------------------------------------------------------------------------------- Constants
// 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.
//
// 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:
// 1. We want to log within `init()`, but...