MCPcopy Create free account
hub / github.com/CodeSentryAI/lockbud / main

Function main

src/main.rs:22–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20use rustc_session::EarlyDiagCtxt;
21
22fn main() -> std::process::ExitCode {
23 // Initialize loggers.
24 let handler = EarlyDiagCtxt::new(ErrorOutputType::default());
25 if std::env::var("RUSTC_LOG").is_ok() {
26 rustc_driver::init_rustc_env_logger(&handler);
27 }
28 if std::env::var("LOCKBUD_LOG").is_ok() {
29 let e = env_logger::Env::new()
30 .filter("LOCKBUD_LOG")
31 .write_style("LOCKBUD_LOG_STYLE");
32 env_logger::init_from_env(e);
33 }
34 // Get any options specified via the LOCKBUD_FLAGS environment variable
35 let options = Options::parse_from_str(&std::env::var("LOCKBUD_FLAGS").unwrap_or_default())
36 .unwrap_or_default();
37 debug!("LOCKBUD options from environment: {options:?}");
38 let mut args = std::env::args_os()
39 .enumerate()
40 .map(|(i, arg)| {
41 arg.into_string().unwrap_or_else(|arg| {
42 handler.early_fatal(format!("Argument {i} is not valid Unicode: {arg:?}"))
43 })
44 })
45 .collect::<Vec<_>>();
46 assert!(!args.is_empty());
47
48 // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
49 // We're invoking the compiler programmatically, so we remove it if present.
50 if args.len() > 1 && std::path::Path::new(&args[1]).file_stem() == Some("rustc".as_ref()) {
51 args.remove(1);
52 }
53
54 let mut rustc_command_line_arguments = args;
55 rustc_driver::install_ice_hook("ice ice ice baby", |_| ());
56 let exit_code = rustc_driver::catch_with_exit_code(|| {
57 let print = "--print=";
58 if rustc_command_line_arguments
59 .iter()
60 .any(|arg| arg.starts_with(print))
61 {
62 // If a --print option is given on the command line we wont get called to analyze
63 // anything. We also don't want to the caller to know that LOCKBUD adds configuration
64 // parameters to the command line, lest the caller be cargo and it panics because
65 // the output from --print=cfg is not what it expects.
66 } else {
67 let sysroot = "--sysroot";
68 if !rustc_command_line_arguments
69 .iter()
70 .any(|arg| arg.starts_with(sysroot))
71 {
72 // Tell compiler where to find the std library and so on.
73 // The compiler relies on the standard rustc driver to tell it, so we have to do likewise.
74 rustc_command_line_arguments.push(format!("{sysroot}={}", find_sysroot()));
75 }
76
77 let always_encode_mir = "always-encode-mir";
78 if !rustc_command_line_arguments
79 .iter()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected