/
main.rs
74 lines (64 loc) · 2.19 KB
/
main.rs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
mod bindgen;
mod flags;
use anyhow::Result;
use flags::*;
use std::path::{Path, PathBuf};
fn main() {
if let Err(e) = try_main() {
eprintln!("{}", e);
for cause in e.chain().skip(1) {
eprintln!("Caused By: {}", cause);
}
std::process::exit(-1);
}
}
fn try_main() -> Result<()> {
let root = project_root();
let _d = xshell::pushd(root)?;
let flags = flags::Xtask::from_env()?;
if flags.verbose {
VERBOSE.store(true, std::sync::atomic::Ordering::Relaxed);
}
match flags.subcommand {
XtaskCmd::Help(_) => eprintln!("{}", flags::Xtask::HELP),
XtaskCmd::Lint(_) => lint_all()?,
XtaskCmd::Test(_) => test_all()?,
XtaskCmd::Bindgen(cmd) => cmd.run()?,
}
Ok(())
}
fn lint_all() -> Result<()> {
// Lint with only default, only docking, and only freetype, and everything
xshell::cmd!("cargo clippy --workspace --all-targets").run()?;
xshell::cmd!("cargo clippy --workspace --all-targets --features docking").run()?;
xshell::cmd!("cargo clippy --workspace --all-targets --features freetype").run()?;
xshell::cmd!("cargo clippy --workspace --all-targets --all-features").run()?;
// Check formatting
xshell::cmd!("cargo fmt --all -- --check").run()?;
Ok(())
}
fn test_all() -> Result<()> {
// Test with default/docking/freetype features
xshell::cmd!("cargo test --workspace --all-targets").run()?;
xshell::cmd!("cargo test --workspace --all-targets --features docking").run()?;
xshell::cmd!("cargo test --workspace --all-targets --features freetype").run()?;
// Test doc examples
xshell::cmd!("cargo test --workspace --doc").run()?;
// Run heavy tests in release mode
xshell::cmd!("cargo test -p imgui --release -- --ignored").run()?;
Ok(())
}
static VERBOSE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
pub fn verbose() -> bool {
VERBOSE.load(std::sync::atomic::Ordering::Relaxed)
}
pub fn project_root() -> PathBuf {
Path::new(
&std::env::var("CARGO_MANIFEST_DIR")
.unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()),
)
.ancestors()
.nth(1)
.unwrap()
.to_path_buf()
}