From 832db73410712eb7d95ab66a8663da12709c8e5c Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 9 Feb 2022 07:23:57 +0800 Subject: [PATCH] ci: add logs --- frontend/scripts/makefile/protobuf.toml | 2 ++ shared-lib/lib-infra/src/pb_gen.rs | 37 ++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/frontend/scripts/makefile/protobuf.toml b/frontend/scripts/makefile/protobuf.toml index e60b67b99d..6c4334bd66 100644 --- a/frontend/scripts/makefile/protobuf.toml +++ b/frontend/scripts/makefile/protobuf.toml @@ -25,6 +25,7 @@ brew install protobuf echo "Install protoc_plugin (Dart)" dart pub global activate protoc_plugin +export PATH="$PATH":"$HOME/.pub-cache/bin" """ script_runner = "@shell" @@ -34,6 +35,7 @@ sudo apt-get install protobuf-compiler echo "Install protoc_plugin (Dart)" dart pub global activate protoc_plugin +export PATH="$PATH":"$HOME/.pub-cache/bin" """ script_runner = "@shell" diff --git a/shared-lib/lib-infra/src/pb_gen.rs b/shared-lib/lib-infra/src/pb_gen.rs index 4ca1a88c20..33e2179b0a 100644 --- a/shared-lib/lib-infra/src/pb_gen.rs +++ b/shared-lib/lib-infra/src/pb_gen.rs @@ -1,7 +1,10 @@ +#![allow(clippy::all)] #![allow(unused_imports)] #![allow(unused_attributes)] +#![allow(dead_code)] use std::fs::File; use std::io::Write; +use std::process::Command; use walkdir::WalkDir; pub fn gen(name: &str, root: &str) { @@ -19,6 +22,7 @@ pub fn gen(name: &str, root: &str) { file_names.push(file_name); } } + println!("cargo:rerun-if-changed=build.rs"); #[cfg(feature = "dart")] gen_pb_for_dart(name, root, &paths, &file_names); @@ -32,7 +36,6 @@ pub fn gen(name: &str, root: &str) { } #[cfg(feature = "dart")] -#[allow(dead_code)] fn gen_pb_for_dart(name: &str, root: &str, paths: &Vec, file_names: &Vec) { let output = format!( "{}/{}/{}", @@ -43,6 +46,10 @@ fn gen_pb_for_dart(name: &str, root: &str, paths: &Vec, file_names: &Vec if !std::path::Path::new(&output).exists() { std::fs::create_dir_all(&output).unwrap(); } + check_pb_compiler(); + + check_pb_dart_plugin(); + paths.iter().for_each(|path| { if cmd_lib::run_cmd! { protoc --dart_out=${output} --proto_path=${root} ${path} @@ -77,3 +84,31 @@ fn gen_pb_for_dart(name: &str, root: &str, paths: &Vec, file_names: &Vec } } } + +fn check_pb_compiler() { + assert!(run_command("command -v protoc"), "protoc was not installed correctly"); +} + +fn check_pb_dart_plugin() { + assert!( + run_command("command -v protoc-gen-dart"), + "protoc-gen-dart was not installed correctly" + ); +} + +fn run_command(cmd: &str) -> bool { + let output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(cmd) + .status() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(cmd) + .status() + .expect("failed to execute process") + }; + output.success() +}