Move ninja requirements to a dynamic check, when actually building

It isn't practical to determine whether we'll build LLVM very early in the
pipeline, so move the ninja checking to a dynamic check.
This commit is contained in:
Mark Rousskov
2020-09-01 09:17:26 -04:00
parent e88e908e66
commit d77c351c89
5 changed files with 51 additions and 45 deletions

View File

@@ -650,7 +650,7 @@ impl Build {
}
} else {
let base = self.llvm_out(self.config.build).join("build");
let base = if !self.config.ninja && self.config.build.contains("msvc") {
let base = if !self.ninja() && self.config.build.contains("msvc") {
if self.config.llvm_optimize {
if self.config.llvm_release_debuginfo {
base.join("RelWithDebInfo")
@@ -1328,6 +1328,43 @@ impl Build {
}
fs::remove_file(f).unwrap_or_else(|_| panic!("failed to remove {:?}", f));
}
/// Returns if config.ninja is enabled, and checks for ninja existence,
/// exiting with a nicer error message if not.
fn ninja(&self) -> bool {
let mut cmd_finder = crate::sanity::Finder::new();
if self.config.ninja_in_file {
// Some Linux distros rename `ninja` to `ninja-build`.
// CMake can work with either binary name.
if cmd_finder.maybe_have("ninja-build").is_none()
&& cmd_finder.maybe_have("ninja").is_none()
{
eprintln!(
"
Couldn't find required command: ninja
You should install ninja, or set ninja=false in config.toml
"
);
std::process::exit(1);
}
}
// If ninja isn't enabled but we're building for MSVC then we try
// doubly hard to enable it. It was realized in #43767 that the msbuild
// CMake generator for MSVC doesn't respect configuration options like
// disabling LLVM assertions, which can often be quite important!
//
// In these cases we automatically enable Ninja if we find it in the
// environment.
if !self.config.ninja_in_file && self.config.build.contains("msvc") {
if cmd_finder.maybe_have("ninja").is_some() {
return true;
}
}
self.config.ninja_in_file
}
}
#[cfg(unix)]