Rename SolveCraft to SolidCraft everywhere, with compatibility shims (#389)
* WIP deep rename (not for push) * WIP2 * WIP3 * WIP4 wxs fix * rustfmt * Rename the remaining identifiers in merged crash-report code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGw4gA5ZvKrU8MQP6sBgT --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27415e4dd7
commit
296683229d
464 files changed
+3408
-2956
No files matched your search
@@ -0,0 +1,55 @@
|
||||
//! SolidCraft's environment variables, read in one place.
|
||||
//!
|
||||
//! Every variable is `SOLIDCRAFT_<NAME>`. Compatibility shim (see docs/compatibility.md): when
|
||||
//! it is unset, the same variable under the product's former prefix is read instead, so
|
||||
//! scripts and service files written for earlier releases keep working.
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
/// The current prefix.
|
||||
pub const PREFIX: &str = "SOLIDCRAFT_";
|
||||
/// The former prefix, read only as a fallback.
|
||||
pub const LEGACY_PREFIX: &str = "SOLVECRAFT_";
|
||||
|
||||
/// `SOLIDCRAFT_<name>`, else the legacy `SOLVECRAFT_<name>`. `name` is the part after the
|
||||
/// prefix, e.g. `"RECOVERY_DIR"`.
|
||||
pub fn var_os(name: &str) -> Option<OsString> {
|
||||
lookup(name, |k| std::env::var_os(k))
|
||||
}
|
||||
|
||||
/// [`var_os`] as UTF-8; a value that is not valid UTF-8 counts as unset.
|
||||
pub fn var(name: &str) -> Option<String> {
|
||||
var_os(name).and_then(|v| v.into_string().ok())
|
||||
}
|
||||
|
||||
fn lookup(name: &str, get: impl Fn(&str) -> Option<OsString>) -> Option<OsString> {
|
||||
get(&format!("{PREFIX}{name}")).or_else(|| get(&format!("{LEGACY_PREFIX}{name}")))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn env(pairs: &[(&str, &str)]) -> impl Fn(&str) -> Option<OsString> {
|
||||
let m: HashMap<String, OsString> = pairs.iter().map(|(k, v)| ((*k).to_string(), OsString::from(*v))).collect();
|
||||
move |k| m.get(k).cloned()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_prefix_wins_over_legacy() {
|
||||
let get = env(&[("SOLIDCRAFT_RECOVERY_DIR", "/new"), ("SOLVECRAFT_RECOVERY_DIR", "/old")]);
|
||||
assert_eq!(lookup("RECOVERY_DIR", get), Some(OsString::from("/new")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_prefix_is_the_fallback() {
|
||||
let get = env(&[("SOLVECRAFT_CONTROL_PORT", "4000")]);
|
||||
assert_eq!(lookup("CONTROL_PORT", get), Some(OsString::from("4000")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unset_in_both_is_none() {
|
||||
assert_eq!(lookup("WAYLAND", env(&[("OTHER", "1")])), None);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Geometry foundation for SolveCraft: 2D/3D vectors, sketch planes, axis-aligned boxes,
|
||||
//! Geometry foundation for SolidCraft: 2D/3D vectors, sketch planes, axis-aligned boxes,
|
||||
//! triangle meshes with their measures (volume, area, centroid), and freeform surface maths
|
||||
//! (B-spline basis and NURBS surfaces in [`bspline`], T-splines in [`tspline`]). Units are
|
||||
//! millimetres.
|
||||
@@ -9,6 +9,7 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
pub mod bspline;
|
||||
pub mod env;
|
||||
mod mesh;
|
||||
mod plane;
|
||||
mod profile;
|
||||
|
||||
Reference in new issue
Block a user