Migrate proto build actions to ninja_gen; switch from dyn Error to anyhow
This commit is contained in:
parent
0bf4fddf40
commit
baa631c6ef
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use ninja_gen::action::BuildAction;
|
||||
use ninja_gen::command::RunCommand;
|
||||
use ninja_gen::copy::CopyFile;
|
||||
|
@ -14,7 +15,6 @@ use ninja_gen::node::TypescriptCheck;
|
|||
use ninja_gen::python::python_format;
|
||||
use ninja_gen::python::PythonTest;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
use ninja_gen::Utf8Path;
|
||||
use ninja_gen::Utf8PathBuf;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use ninja_gen::action::BuildAction;
|
||||
use ninja_gen::archives::download_and_extract;
|
||||
use ninja_gen::archives::empty_manifest;
|
||||
|
@ -14,7 +15,6 @@ use ninja_gen::input::BuildInput;
|
|||
use ninja_gen::inputs;
|
||||
use ninja_gen::python::PythonEnvironment;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
use ninja_gen::Utf8Path;
|
||||
|
||||
use crate::anki_version;
|
||||
|
|
|
@ -4,17 +4,20 @@
|
|||
mod aqt;
|
||||
mod bundle;
|
||||
mod platform;
|
||||
mod proto;
|
||||
mod pylib;
|
||||
mod python;
|
||||
mod rust;
|
||||
mod web;
|
||||
|
||||
use anyhow::Result;
|
||||
use aqt::build_and_check_aqt;
|
||||
use bundle::build_bundle;
|
||||
use ninja_gen::glob;
|
||||
use ninja_gen::inputs;
|
||||
use ninja_gen::protobuf::check_proto;
|
||||
use ninja_gen::protobuf::setup_protoc;
|
||||
use ninja_gen::python::setup_python;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
use pylib::build_pylib;
|
||||
use pylib::check_pylib;
|
||||
use python::check_python;
|
||||
|
@ -25,8 +28,6 @@ use rust::check_rust;
|
|||
use web::build_and_check_web;
|
||||
use web::check_sql;
|
||||
|
||||
use crate::proto::check_proto;
|
||||
|
||||
fn anki_version() -> String {
|
||||
std::fs::read_to_string(".version")
|
||||
.unwrap()
|
||||
|
@ -38,6 +39,9 @@ fn main() -> Result<()> {
|
|||
let mut build = Build::new()?;
|
||||
let build = &mut build;
|
||||
|
||||
setup_protoc(build)?;
|
||||
check_proto(build, inputs![glob!["proto/**/*.proto"]])?;
|
||||
|
||||
setup_python(build)?;
|
||||
setup_venv(build)?;
|
||||
|
||||
|
@ -50,7 +54,7 @@ fn main() -> Result<()> {
|
|||
check_rust(build)?;
|
||||
check_pylib(build)?;
|
||||
check_python(build)?;
|
||||
check_proto(build)?;
|
||||
|
||||
check_sql(build)?;
|
||||
check_minilints(build)?;
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use std::env;
|
||||
|
||||
use ninja_gen::archives::download_and_extract;
|
||||
use ninja_gen::archives::with_exe;
|
||||
use ninja_gen::glob;
|
||||
use ninja_gen::hashmap;
|
||||
use ninja_gen::inputs;
|
||||
use ninja_gen::protobuf::protoc_archive;
|
||||
use ninja_gen::protobuf::ClangFormat;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
use ninja_gen::Utf8Path;
|
||||
|
||||
pub fn setup_protoc(build: &mut Build) -> Result<()> {
|
||||
let protoc_binary = match env::var("PROTOC_BINARY") {
|
||||
Ok(path) => {
|
||||
assert!(
|
||||
Utf8Path::new(&path).is_absolute(),
|
||||
"PROTOC_BINARY must be absolute"
|
||||
);
|
||||
path.into()
|
||||
}
|
||||
Err(_) => {
|
||||
download_and_extract(
|
||||
build,
|
||||
"protoc",
|
||||
protoc_archive(build.host_platform),
|
||||
hashmap! {
|
||||
"bin" => [with_exe("bin/protoc")]
|
||||
},
|
||||
)?;
|
||||
inputs![":extract:protoc:bin"]
|
||||
}
|
||||
};
|
||||
build.add_dependency("protoc_binary", protoc_binary);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check_proto(build: &mut Build) -> Result<()> {
|
||||
build.add_action(
|
||||
"check:format:proto",
|
||||
ClangFormat {
|
||||
inputs: inputs![glob!["proto/**/*.proto"]],
|
||||
check_only: true,
|
||||
},
|
||||
)?;
|
||||
build.add_action(
|
||||
"format:proto",
|
||||
ClangFormat {
|
||||
inputs: inputs![glob!["proto/**/*.proto"]],
|
||||
check_only: false,
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use ninja_gen::action::BuildAction;
|
||||
use ninja_gen::archives::Platform;
|
||||
use ninja_gen::command::RunCommand;
|
||||
|
@ -11,7 +12,6 @@ use ninja_gen::inputs;
|
|||
use ninja_gen::python::python_format;
|
||||
use ninja_gen::python::PythonTest;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
|
||||
use crate::anki_version;
|
||||
use crate::platform::overriden_python_target_platform;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use ninja_gen::action::BuildAction;
|
||||
use ninja_gen::archives::Platform;
|
||||
use ninja_gen::build::FilesHandle;
|
||||
|
@ -15,7 +16,6 @@ use ninja_gen::python::PythonLint;
|
|||
use ninja_gen::python::PythonTypecheck;
|
||||
use ninja_gen::rsync::RsyncFiles;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
|
||||
pub fn setup_venv(build: &mut Build) -> Result<()> {
|
||||
let platform_deps = if cfg!(windows) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use ninja_gen::action::BuildAction;
|
||||
use ninja_gen::build::FilesHandle;
|
||||
use ninja_gen::cargo::CargoBuild;
|
||||
|
@ -14,14 +15,11 @@ use ninja_gen::glob;
|
|||
use ninja_gen::input::BuildInput;
|
||||
use ninja_gen::inputs;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
|
||||
use crate::platform::overriden_rust_target_triple;
|
||||
use crate::proto::setup_protoc;
|
||||
|
||||
pub fn build_rust(build: &mut Build) -> Result<()> {
|
||||
prepare_translations(build)?;
|
||||
setup_protoc(build)?;
|
||||
prepare_proto_descriptors(build)?;
|
||||
build_rsbridge(build)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use ninja_gen::action::BuildAction;
|
||||
use ninja_gen::command::RunCommand;
|
||||
use ninja_gen::glob;
|
||||
|
@ -20,7 +21,6 @@ use ninja_gen::node::SvelteCheck;
|
|||
use ninja_gen::node::TypescriptCheck;
|
||||
use ninja_gen::rsync::RsyncFiles;
|
||||
use ninja_gen::Build;
|
||||
use ninja_gen::Result;
|
||||
|
||||
pub fn build_and_check_web(build: &mut Build) -> Result<()> {
|
||||
setup_node(build)?;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::build::FilesHandle;
|
||||
use crate::Build;
|
||||
use crate::Result;
|
||||
|
||||
pub trait BuildAction {
|
||||
/// Command line to invoke for each build statement.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use camino::Utf8Path;
|
||||
use camino::Utf8PathBuf;
|
||||
|
||||
|
@ -11,7 +12,6 @@ use crate::action::BuildAction;
|
|||
use crate::input::BuildInput;
|
||||
use crate::inputs;
|
||||
use crate::Build;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct OnlineArchive {
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
|||
use std::collections::HashSet;
|
||||
use std::fmt::Write;
|
||||
|
||||
use anyhow::Result;
|
||||
use camino::Utf8PathBuf;
|
||||
use itertools::Itertools;
|
||||
|
||||
|
@ -13,7 +14,6 @@ use crate::archives::Platform;
|
|||
use crate::configure::ConfigureBuild;
|
||||
use crate::input::space_separated;
|
||||
use crate::input::BuildInput;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Build {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use camino::Utf8Path;
|
||||
use camino::Utf8PathBuf;
|
||||
|
||||
|
@ -10,7 +11,6 @@ use crate::build::FilesHandle;
|
|||
use crate::input::BuildInput;
|
||||
use crate::inputs;
|
||||
use crate::Build;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum RustOutput<'a> {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::action::BuildAction;
|
||||
use crate::build::FilesHandle;
|
||||
use crate::cargo::CargoBuild;
|
||||
|
@ -8,7 +10,6 @@ use crate::cargo::RustOutput;
|
|||
use crate::glob;
|
||||
use crate::inputs;
|
||||
use crate::Build;
|
||||
use crate::Result;
|
||||
|
||||
pub struct ConfigureBuild {}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
use super::*;
|
||||
|
|
|
@ -24,8 +24,6 @@ pub use camino::Utf8PathBuf;
|
|||
pub use maplit::hashmap;
|
||||
pub use which::which;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! inputs {
|
||||
($($param:expr),+ $(,)?) => {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
use super::*;
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use std::env;
|
||||
|
||||
use anyhow::Result;
|
||||
use camino::Utf8Path;
|
||||
use maplit::hashmap;
|
||||
|
||||
use crate::action::BuildAction;
|
||||
|
@ -11,6 +15,7 @@ use crate::archives::Platform;
|
|||
use crate::hash::simple_hash;
|
||||
use crate::input::BuildInput;
|
||||
use crate::inputs;
|
||||
use crate::Build;
|
||||
|
||||
pub fn protoc_archive(platform: Platform) -> OnlineArchive {
|
||||
match platform {
|
||||
|
@ -91,7 +96,7 @@ impl BuildAction for ClangFormat {
|
|||
let hash = simple_hash(&self.inputs);
|
||||
build.add_output_stamp(format!("tests/clang-format.{mode}.{hash}"));
|
||||
}
|
||||
fn on_first_instance(&self, build: &mut crate::Build) -> crate::Result<()> {
|
||||
fn on_first_instance(&self, build: &mut crate::Build) -> anyhow::Result<()> {
|
||||
let binary = with_exe("clang-format");
|
||||
download_and_extract(
|
||||
build,
|
||||
|
@ -103,3 +108,46 @@ impl BuildAction for ClangFormat {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setup_protoc(build: &mut Build) -> Result<()> {
|
||||
let protoc_binary = match env::var("PROTOC_BINARY") {
|
||||
Ok(path) => {
|
||||
assert!(
|
||||
Utf8Path::new(&path).is_absolute(),
|
||||
"PROTOC_BINARY must be absolute"
|
||||
);
|
||||
path.into()
|
||||
}
|
||||
Err(_) => {
|
||||
download_and_extract(
|
||||
build,
|
||||
"protoc",
|
||||
protoc_archive(build.host_platform),
|
||||
hashmap! {
|
||||
"bin" => [with_exe("bin/protoc")]
|
||||
},
|
||||
)?;
|
||||
inputs![":extract:protoc:bin"]
|
||||
}
|
||||
};
|
||||
build.add_dependency("protoc_binary", protoc_binary);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check_proto(build: &mut Build, inputs: BuildInput) -> Result<()> {
|
||||
build.add_action(
|
||||
"check:format:proto",
|
||||
ClangFormat {
|
||||
inputs: inputs.clone(),
|
||||
check_only: true,
|
||||
},
|
||||
)?;
|
||||
build.add_action(
|
||||
"format:proto",
|
||||
ClangFormat {
|
||||
inputs,
|
||||
check_only: false,
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
use std::env;
|
||||
|
||||
use anyhow::Result;
|
||||
use camino::Utf8Path;
|
||||
use maplit::hashmap;
|
||||
|
||||
|
@ -14,7 +15,6 @@ use crate::hash::simple_hash;
|
|||
use crate::input::BuildInput;
|
||||
use crate::inputs;
|
||||
use crate::Build;
|
||||
use crate::Result;
|
||||
|
||||
pub fn python_archive(platform: Platform) -> OnlineArchive {
|
||||
match platform {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::action::BuildAction;
|
||||
use crate::cargo::CargoInstall;
|
||||
use crate::input::space_separated;
|
||||
use crate::input::BuildInput;
|
||||
use crate::inputs;
|
||||
use crate::Build;
|
||||
use crate::Result;
|
||||
|
||||
pub struct CompileSassWithGrass {
|
||||
pub input: BuildInput,
|
||||
|
|
Loading…
Reference in New Issue