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
use std::sync::Arc;

use calypso_base::ui::termcolor::{Color, ColorSpec, WriteColor};
use calypso_common::gcx::GlobalCtxt;
use calypso_diagnostic::prelude::*;

use crate::buildinfo::BUILD_INFO;
use crate::cli::InternalCmd;
use crate::commands::internal::unpretty::unpretty;

pub mod unpretty;

#[allow(clippy::single_match)]
pub fn internal(gcx: &Arc<GlobalCtxt>, cmd: &InternalCmd) -> CalResult<()> {
    match cmd {
        InternalCmd::BuildInfo => buildinfo(gcx),
        InternalCmd::Panic => panic!("Intentional panic to test ICE handling, please ignore."),
        InternalCmd::Unpretty {
            format,
            input,
            repl,
        } => unpretty(gcx, *format, input.as_ref(), *repl),
    }
}

pub fn buildinfo(gcx: &Arc<GlobalCtxt>) -> CalResult<()> {
    let mut bi = BUILD_INFO;

    let mut emit = gcx.emit.write();
    let out = &mut emit.out;

    out.info("=:= Version =:=", None)?
        .newline()?
        .info("version", Some(bi.version))?
        .info("git branch", Some(bi.git_branch))?
        .info("git commit", Some(bi.git_commit))?
        .newline()?
        .info("=:= Build Env =:=", None)?
        .newline()?
        .info("features:", None)?;

    if bi.cargo_features.is_empty() {
        bi.cargo_features = "no cargo features enabled";
    }

    for feature in bi.cargo_features.split(',') {
        out.set_color(
            ColorSpec::new()
                .set_fg(Some(Color::Green))
                .set_bold(true)
                .set_intense(true),
        )?;
        out.print("  =>")?;
        out.reset()?;
        out.print(&format!(" {}", feature))?.newline()?;
    }

    out.info("profile", Some(bi.cargo_profile))?
        .info("target triple", Some(bi.cargo_target_triple))?
        .newline()?
        .info("=:= Rust =:=", None)?
        .newline()?
        .info("channel", Some(bi.rustc_channel))?
        .info("commit date", Some(bi.rustc_commit_date))?
        .info("commit hash", Some(bi.rustc_commit_hash))?
        .info("host triple", Some(bi.rustc_host_triple))?
        .info("llvm version", Some(bi.rustc_llvm_version))?
        .info("version", Some(bi.rustc_version))?
        .flush()?;

    Ok(())
}