diff options
| author | The Miri Conjob Bot <miri@cron.bot> | 2024-02-19 05:12:20 +0000 |
|---|---|---|
| committer | The Miri Conjob Bot <miri@cron.bot> | 2024-02-19 05:12:20 +0000 |
| commit | e118c3e8af2ee5c0d20d21e8bf08c1a254a317fb (patch) | |
| tree | cf3e5436c033a6b38daa21eb498b7f53d417936c /compiler/rustc_session/src | |
| parent | 6b6da93e51851d098574b5e6f39b6d187e78f34a (diff) | |
| parent | d5735645753e990a72446094f703df9b5e421555 (diff) | |
Merge from rustc
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/filesearch.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_session/src/utils.rs | 20 |
3 files changed, 20 insertions, 3 deletions
diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 6e459ac45d3..2456b4b3a15 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -143,7 +143,6 @@ fn current_dll_path() -> Result<PathBuf, String> { &mut module, ) } - .ok() .map_err(|e| e.to_string())?; let mut filename = vec![0; 1024]; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 25c20be8e62..9d1133c487f 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -22,7 +22,7 @@ use rustc_errors::emitter::{DynEmitter, HumanEmitter, HumanReadableErrorType}; use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; use rustc_errors::{ - codes::*, fallback_fluent_bundle, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, ErrCode, + codes::*, fallback_fluent_bundle, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, FatalAbort, FluentBundle, IntoDiagnostic, LazyFallbackBundle, TerminalUrl, }; use rustc_macros::HashStable_Generic; diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index f76c69af526..50ebbdccf67 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -1,7 +1,10 @@ use crate::session::Session; use rustc_data_structures::profiling::VerboseTimingGuard; use rustc_fs_util::try_canonicalize; -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, + sync::OnceLock, +}; impl Session { pub fn timer(&self, what: &'static str) -> VerboseTimingGuard<'_> { @@ -158,3 +161,18 @@ pub fn extra_compiler_flags() -> Option<(Vec<String>, bool)> { if !result.is_empty() { Some((result, excluded_cargo_defaults)) } else { None } } + +/// Returns whenever rustc was launched by Cargo as opposed to another build system. +/// +/// To be used in diagnostics to avoid printing Cargo specific suggestions to other +/// build systems (like Bazel, Buck2, Makefile, ...). +pub fn was_invoked_from_cargo() -> bool { + static FROM_CARGO: OnceLock<bool> = OnceLock::new(); + + // To be able to detect Cargo, we use the simplest and least intrusive + // way: we check whenever the `CARGO_CRATE_NAME` env is set. + // + // Note that it is common in Makefiles to define the `CARGO` env even + // though we may not have been called by Cargo, so we avoid using it. + *FROM_CARGO.get_or_init(|| std::env::var_os("CARGO_CRATE_NAME").is_some()) +} |
