blob: 82ec6a7297b3840a191524552ea97dffc7ea0406 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use std::path::{ Path, PathBuf };
use std::env::temp_dir;
use lazy_static::lazy_static;
pub mod python;
pub mod clang;
pub use python::PythonBackend;
pub use clang::ClangBackend;
lazy_static! {
static ref EVR_TMP_DIR: PathBuf = temp_dir().join("evr-tmp");
}
pub trait Backend {
fn get_template(&self) -> Option<&str>;
fn run(&self, fname: &Path) -> std::io::Result<()>;
fn try_guess_test_file(&self, fname: &Path) -> Option<PathBuf> {
let maybe_test = fname.with_extension("txt");
if maybe_test.exists() {
return Some(maybe_test);
}
None
}
}
fn mk_tmp_dir() -> std::io::Result<&'static std::path::PathBuf> {
if !EVR_TMP_DIR.exists() {
std::fs::create_dir(&*EVR_TMP_DIR)?;
} else {
if !EVR_TMP_DIR.is_dir() {
return Err(std::io::Error::new(std::io::ErrorKind::AlreadyExists,
"tmp dir already exists and not a directory"))
}
}
Ok(&*EVR_TMP_DIR)
}
|