mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 04:24:43 +00:00
82 lines
2.3 KiB
Rust
82 lines
2.3 KiB
Rust
use std::env::var;
|
|
use std::path::PathBuf;
|
|
|
|
use crate::normalize_path;
|
|
use crate::style::colors::*;
|
|
use crate::style::RESET;
|
|
|
|
fn _erg_path() -> PathBuf {
|
|
let path = var("ERG_PATH").unwrap_or_else(|_| env!("CARGO_ERG_PATH").to_string());
|
|
PathBuf::from(path).canonicalize().unwrap_or_else(|_| {
|
|
eprintln!("{RED}[ERR] ERG_PATH not found{RESET}");
|
|
PathBuf::from(".")
|
|
})
|
|
}
|
|
fn _erg_std_path() -> PathBuf {
|
|
_erg_path()
|
|
.join("lib")
|
|
.join("std")
|
|
.canonicalize()
|
|
.unwrap_or_else(|_| {
|
|
eprintln!("{RED}[ERR] ERG_PATH/lib/std not found{RESET}");
|
|
PathBuf::from("lib/std/")
|
|
})
|
|
}
|
|
fn _erg_std_decl_path() -> PathBuf {
|
|
_erg_path()
|
|
.join("lib")
|
|
.join("std.d")
|
|
.canonicalize()
|
|
.unwrap_or_else(|_| {
|
|
eprintln!("{RED}[ERR] ERG_PATH/lib/std.d not found {RESET}");
|
|
PathBuf::from("lib/std.d/")
|
|
})
|
|
}
|
|
fn _erg_pystd_path() -> PathBuf {
|
|
_erg_path()
|
|
.join("lib")
|
|
.join("pystd")
|
|
.canonicalize()
|
|
.unwrap_or_else(|_| {
|
|
eprintln!("{RED}[ERR] ERG_PATH/lib/pystd not found {RESET}");
|
|
PathBuf::from("lib/pystd/")
|
|
})
|
|
}
|
|
fn _erg_external_lib_path() -> PathBuf {
|
|
_erg_path()
|
|
.join("lib")
|
|
.join("external")
|
|
.canonicalize()
|
|
.unwrap_or_else(|_| {
|
|
eprintln!("{RED}[ERR] ERG_PATH/lib/external not found {RESET}");
|
|
PathBuf::from("lib/external/")
|
|
})
|
|
}
|
|
|
|
thread_local! {
|
|
pub static ERG_PATH: PathBuf = normalize_path(_erg_path());
|
|
pub static ERG_STD_PATH: PathBuf = normalize_path(_erg_std_path());
|
|
pub static ERG_STD_DECL_PATH: PathBuf = normalize_path(_erg_std_decl_path());
|
|
pub static ERG_PYSTD_PATH: PathBuf = normalize_path(_erg_pystd_path());
|
|
pub static ERG_EXTERNAL_LIB_PATH: PathBuf = normalize_path(_erg_external_lib_path());
|
|
}
|
|
|
|
pub fn erg_path() -> PathBuf {
|
|
ERG_PATH.with(|s| s.clone())
|
|
}
|
|
|
|
pub fn erg_std_path() -> PathBuf {
|
|
ERG_STD_PATH.with(|s| s.clone())
|
|
}
|
|
|
|
pub fn erg_std_decl_path() -> PathBuf {
|
|
ERG_STD_DECL_PATH.with(|s| s.clone())
|
|
}
|
|
|
|
pub fn erg_pystd_path() -> PathBuf {
|
|
ERG_PYSTD_PATH.with(|s| s.clone())
|
|
}
|
|
|
|
pub fn erg_py_external_lib_path() -> PathBuf {
|
|
ERG_EXTERNAL_LIB_PATH.with(|s| s.clone())
|
|
}
|