mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Let ninja/n2 do the configure invocation
I'd introduced maybe_reconfigure_build() after running into issues where configure was not being invoked, but have discovered why that was happening: the out folder path must be identical to the canonical path listed in build.ninja, which it wasn't when a symlink was used. With this change, we avoid having to invoke ninja twice, and get visibility into the configure step. This also makes rsbridge only depend on out/env, which prevents it from being rebuilt when any reconfigure happens.
This commit is contained in:
parent
58c0f61d31
commit
b4bfc1a80d
4 changed files with 19 additions and 24 deletions
|
@ -115,7 +115,7 @@ fn build_rsbridge(build: &mut Build) -> Result<()> {
|
||||||
":rslib:i18n",
|
":rslib:i18n",
|
||||||
":rslib:proto",
|
":rslib:proto",
|
||||||
// when env vars change the build hash gets updated
|
// when env vars change the build hash gets updated
|
||||||
"$builddir/build.ninja",
|
"$builddir/env",
|
||||||
// building on Windows requires python3.lib
|
// building on Windows requires python3.lib
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
inputs![":extract:python"]
|
inputs![":extract:python"]
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl Build {
|
||||||
groups: Default::default(),
|
groups: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
build.add_action("build:run_configure", ConfigureBuild {})?;
|
build.add_action("build:configure", ConfigureBuild {})?;
|
||||||
|
|
||||||
Ok(build)
|
Ok(build)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl BuildAction for ConfigureBuild {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn files(&mut self, build: &mut impl FilesHandle) {
|
fn files(&mut self, build: &mut impl FilesHandle) {
|
||||||
build.add_inputs("cmd", inputs![":build:configure"]);
|
build.add_inputs("cmd", inputs![":build:configure_bin"]);
|
||||||
// reconfigure when external inputs change
|
// reconfigure when external inputs change
|
||||||
build.add_inputs("", inputs!["$builddir/env", ".version", ".git"]);
|
build.add_inputs("", inputs!["$builddir/env", ".version", ".git"]);
|
||||||
build.add_outputs("", ["build.ninja"])
|
build.add_outputs("", ["build.ninja"])
|
||||||
|
@ -27,7 +27,7 @@ impl BuildAction for ConfigureBuild {
|
||||||
|
|
||||||
fn on_first_instance(&self, build: &mut Build) -> Result<()> {
|
fn on_first_instance(&self, build: &mut Build) -> Result<()> {
|
||||||
build.add_action(
|
build.add_action(
|
||||||
"build:configure",
|
"build:configure_bin",
|
||||||
CargoBuild {
|
CargoBuild {
|
||||||
inputs: inputs![glob!["build/**/*"]],
|
inputs: inputs![glob!["build/**/*"]],
|
||||||
outputs: &[RustOutput::Binary("configure")],
|
outputs: &[RustOutput::Binary("configure")],
|
||||||
|
@ -38,4 +38,12 @@ impl BuildAction for ConfigureBuild {
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generator(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_output_timestamps(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ use std::process::Command;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use camino::Utf8Path;
|
use camino::Utf8Path;
|
||||||
|
use camino::Utf8PathBuf;
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use termcolor::Color;
|
use termcolor::Color;
|
||||||
use termcolor::ColorChoice;
|
use termcolor::ColorChoice;
|
||||||
|
@ -22,7 +23,7 @@ pub struct BuildArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_build(args: BuildArgs) {
|
pub fn run_build(args: BuildArgs) {
|
||||||
let build_root = setup_build_root();
|
let build_root = &setup_build_root();
|
||||||
|
|
||||||
let path = if cfg!(windows) {
|
let path = if cfg!(windows) {
|
||||||
format!(
|
format!(
|
||||||
|
@ -47,8 +48,6 @@ pub fn run_build(args: BuildArgs) {
|
||||||
let build_file = build_root.join("build.ninja");
|
let build_file = build_root.join("build.ninja");
|
||||||
if !build_file.exists() {
|
if !build_file.exists() {
|
||||||
bootstrap_build();
|
bootstrap_build();
|
||||||
} else {
|
|
||||||
maybe_reconfigure_build(&build_file, &path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatically convert foo:bar references to foo_bar, as Ninja can not
|
// automatically convert foo:bar references to foo_bar, as Ninja can not
|
||||||
|
@ -117,7 +116,7 @@ fn get_ninja_command() -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_build_root() -> &'static Utf8Path {
|
fn setup_build_root() -> Utf8PathBuf {
|
||||||
let build_root = Utf8Path::new("out");
|
let build_root = Utf8Path::new("out");
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -139,22 +138,10 @@ fn setup_build_root() -> &'static Utf8Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::create_dir_all(build_root).unwrap();
|
fs::create_dir_all(build_root).unwrap();
|
||||||
|
if cfg!(windows) {
|
||||||
build_root
|
build_root.to_owned()
|
||||||
}
|
} else {
|
||||||
|
build_root.canonicalize_utf8().unwrap()
|
||||||
fn maybe_reconfigure_build(build_file: &Utf8Path, path: &str) {
|
|
||||||
let output = Command::new(get_ninja_command())
|
|
||||||
.arg("-f")
|
|
||||||
.arg(build_file)
|
|
||||||
.arg("build_run_configure")
|
|
||||||
.env("PATH", path)
|
|
||||||
.output()
|
|
||||||
.expect("ninja installed");
|
|
||||||
if !output.status.success() {
|
|
||||||
// The existing build.ninja may be invalid if files have been renamed/removed;
|
|
||||||
// resort to a slower cargo invocation instead to regenerate it.
|
|
||||||
bootstrap_build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue