mirror of https://github.com/aya-rs/aya
test,xtask: Replace lazy_static with OnceCell
This doesn't affect MSRV because this is testing code.pull/639/head
parent
ff86f1385c
commit
5a2906a6c9
@ -1,17 +1,15 @@
|
||||
use lazy_static::lazy_static;
|
||||
use serde_json::Value;
|
||||
use std::process::Command;
|
||||
use std::{cell::OnceCell, process::Command};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref WORKSPACE_ROOT: String = workspace_root();
|
||||
}
|
||||
|
||||
fn workspace_root() -> String {
|
||||
let output = Command::new("cargo").arg("metadata").output().unwrap();
|
||||
if !output.status.success() {
|
||||
panic!("unable to run cargo metadata")
|
||||
}
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
let v: Value = serde_json::from_str(&stdout).unwrap();
|
||||
v["workspace_root"].as_str().unwrap().to_string()
|
||||
pub fn workspace_root() -> &'static str {
|
||||
static mut WORKSPACE_ROOT: OnceCell<String> = OnceCell::new();
|
||||
unsafe { &mut WORKSPACE_ROOT }.get_or_init(|| {
|
||||
let output = Command::new("cargo").arg("metadata").output().unwrap();
|
||||
if !output.status.success() {
|
||||
panic!("unable to run cargo metadata")
|
||||
}
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
let v: Value = serde_json::from_str(&stdout).unwrap();
|
||||
v["workspace_root"].as_str().unwrap().to_string()
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue