Repository navigation
compiler: fall back to local on distributed-compile failure #2777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
69bdf61
650b3e5
0ff4674
280c4d4
d65f06f
89e0b8e
21671bf
1178a21
b46e138
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,8 +84,6 @@ fn exit(code: i32) -> ! { | |
| } | ||
|
|
||
| pub fn main() { | ||
| init_logging(); | ||
|
|
||
| let command = match cmdline::try_parse() { | ||
| Ok(cmd) => cmd, | ||
| Err(e) => match e.downcast::<clap::error::Error>() { | ||
|
|
@@ -105,6 +103,10 @@ pub fn main() { | |
| }, | ||
| }; | ||
|
|
||
| // Logging is initialized after parsing so the compile-wrapper case can keep | ||
| // sccache's own log records off the wrapped compiler's stderr. | ||
| init_logging(&command); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is unrelated to the fallback, please split it into its own PR |
||
| exit(match commands::run_command(command) { | ||
| Ok(s) => s, | ||
| Err(e) => { | ||
|
|
@@ -117,7 +119,7 @@ pub fn main() { | |
| }); | ||
| } | ||
|
|
||
| fn init_logging() { | ||
| fn init_logging(command: &cmdline::Command) { | ||
| if env::var(LOGGING_ENV).is_ok() { | ||
| let mut builder = env_logger::Builder::from_env(LOGGING_ENV); | ||
|
|
||
|
|
@@ -126,6 +128,35 @@ fn init_logging() { | |
| builder.format_timestamp_millis(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the log file can't be opened, we silently drop everything? |
||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so |
||
| // When sccache runs as a compiler wrapper (`sccache <compiler> ...`) it | ||
| // shares stderr with the wrapped compiler. Build tools treat any | ||
| // unexpected stderr on a feature probe as a compiler failure: libtool's | ||
| // `-fPIC` check sets `pic_flag=""` on non-empty stderr, producing non-PIC | ||
| // objects that then fail to link into a shared library. sccache's own log | ||
| // records must never reach that stderr. Send them to SCCACHE_ERROR_LOG | ||
| // when set; otherwise keep stderr only for an interactive terminal (so | ||
| // `SCCACHE_LOG=debug sccache gcc ...` at a prompt still shows logs) and | ||
| // discard them when stderr is captured by a build. | ||
| if matches!(command, cmdline::Command::Compile { .. }) { | ||
| use std::io::IsTerminal; | ||
| let target: Option<Box<dyn std::io::Write + Send + 'static>> = | ||
| match env::var("SCCACHE_ERROR_LOG") { | ||
| Ok(path) if !path.is_empty() => Some( | ||
| std::fs::OpenOptions::new() | ||
| .create(true) | ||
| .append(true) | ||
| .open(&path) | ||
| .map(|f| Box::new(f) as Box<dyn std::io::Write + Send + 'static>) | ||
| .unwrap_or_else(|_| Box::new(std::io::sink())), | ||
| ), | ||
| _ if !std::io::stderr().is_terminal() => Some(Box::new(std::io::sink())), | ||
| _ => None, | ||
| }; | ||
| if let Some(target) = target { | ||
| builder.target(env_logger::Target::Pipe(target)); | ||
| } | ||
| } | ||
|
|
||
| match builder.try_init() { | ||
| Ok(_) => (), | ||
| Err(e) => panic!("Failed to initialize logging: {:?}", e), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make the comment shorter, no need to document what older binaries do