From 837666d36db025d10cafcbd8a292fee3f119e2df Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 9 Feb 2022 01:14:54 +0800 Subject: [PATCH 1/3] ci: fix dart pb --- .github/workflows/ci.yaml | 1 - frontend/scripts/makefile/desktop.toml | 2 +- frontend/scripts/makefile/protobuf.toml | 28 +++++++++++++++---------- shared-lib/lib-infra/src/pb_gen.rs | 7 +++---- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3b37270dde..2e8fb92aae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,6 @@ jobs: run: | cargo install --force cargo-make cargo install --force duckscript_cli - brew install protobuf cargo make flowy_dev - name: Build working-directory: frontend diff --git a/frontend/scripts/makefile/desktop.toml b/frontend/scripts/makefile/desktop.toml index 157b1a4b92..3b4f8aed4e 100644 --- a/frontend/scripts/makefile/desktop.toml +++ b/frontend/scripts/makefile/desktop.toml @@ -5,7 +5,7 @@ # cargo make --profile production-windows-x86 flowy-sdk-dev [tasks.env_check] -dependencies = ["echo_env", "install-pb-tool-if-need"] +dependencies = ["echo_env", "install_protobuf"] condition = { env_set = [ "BUILD_FLAG", "RUST_COMPILE_TARGET", "CRATE_TYPE", "TARGET_OS"], channels = ["stable"] } [tasks.flowy-sdk-dev] diff --git a/frontend/scripts/makefile/protobuf.toml b/frontend/scripts/makefile/protobuf.toml index 5dc076a013..e60b67b99d 100644 --- a/frontend/scripts/makefile/protobuf.toml +++ b/frontend/scripts/makefile/protobuf.toml @@ -2,16 +2,14 @@ [tasks.pb] dependencies = ["check_protoc_cmd", "gen_pb_file"] -[tasks.install-pb-tool-if-need] +[tasks.install_protobuf] condition_script = [ """ - if [ ! "$(command -v dart)" ]; then - echo Please make sure flutter/dart is properly installed and in PATH env var - exit 1 + if [ ! "$(command -v protoc)" ]; then + exit 0 fi if [ ! "$(command -v protoc-gen-dart)" ]; then - # not install exit 0 fi @@ -19,19 +17,27 @@ condition_script = [ exit 1 """, ] -run_task = { name = ["install_protobuf"] } +run_task = { name = ["install_protobuf_compiler"] } -[tasks.install_protobuf] +[tasks.install_protobuf_compiler] script = """ +brew install protobuf + echo "Install protoc_plugin (Dart)" dart pub global activate protoc_plugin -export PATH="$HOME/.pub-cache/bin:$PATH" - -cargo install --version 2.22.1 protobuf-codegen """ script_runner = "@shell" -[tasks.install_protobuf.windows] +[tasks.install_protobuf_compiler.linux] +script = """ +sudo apt-get install protobuf-compiler + +echo "Install protoc_plugin (Dart)" +dart pub global activate protoc_plugin +""" +script_runner = "@shell" + +[tasks.install_protobuf_compiler.windows] script = """ ret = which dart if is_empty ${ret} diff --git a/shared-lib/lib-infra/src/pb_gen.rs b/shared-lib/lib-infra/src/pb_gen.rs index b63c6a0067..4ca1a88c20 100644 --- a/shared-lib/lib-infra/src/pb_gen.rs +++ b/shared-lib/lib-infra/src/pb_gen.rs @@ -4,7 +4,6 @@ use std::fs::File; use std::io::Write; use walkdir::WalkDir; -#[allow(dead_code)] pub fn gen(name: &str, root: &str) { let mut paths = vec![]; let mut file_names = vec![]; @@ -21,8 +20,8 @@ pub fn gen(name: &str, root: &str) { } } - // #[cfg(feature = "dart")] - // gen_pb_for_dart(name, root, &paths, &file_names); + #[cfg(feature = "dart")] + gen_pb_for_dart(name, root, &paths, &file_names); protoc_rust::Codegen::new() .out_dir("./src/protobuf/model") @@ -50,7 +49,7 @@ fn gen_pb_for_dart(name: &str, root: &str, paths: &Vec, file_names: &Vec } .is_err() { - panic!("Run flutter protoc fail") + panic!("Generate pb file failed with: {}", path) }; }); From 832db73410712eb7d95ab66a8663da12709c8e5c Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 9 Feb 2022 07:23:57 +0800 Subject: [PATCH 2/3] 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() +} From 30bedb337f575dd37600fa01b3329d125c65a58f Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 9 Feb 2022 07:32:59 +0800 Subject: [PATCH 3/3] ci: export path to CI --- .github/workflows/ci.yaml | 3 ++- frontend/scripts/makefile/protobuf.toml | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e8fb92aae..6c89e47281 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,6 +33,7 @@ jobs: cargo install --force cargo-make cargo install --force duckscript_cli cargo make flowy_dev + echo PATH="$PATH":"$HOME/.pub-cache/bin" >> $GITHUB_PATH - name: Build working-directory: frontend run: cargo make --profile production-mac-x86 appflowy @@ -73,8 +74,8 @@ jobs: run: | cargo install --force cargo-make cargo install --force duckscript_cli - sudo apt-get install protobuf-compiler cargo make flowy_dev + echo PATH="$PATH":"$HOME/.pub-cache/bin" >> $GITHUB_PATH - name: Build working-directory: frontend run: cargo make --profile production-linux-x86 appflowy diff --git a/frontend/scripts/makefile/protobuf.toml b/frontend/scripts/makefile/protobuf.toml index 6c4334bd66..e60b67b99d 100644 --- a/frontend/scripts/makefile/protobuf.toml +++ b/frontend/scripts/makefile/protobuf.toml @@ -25,7 +25,6 @@ brew install protobuf echo "Install protoc_plugin (Dart)" dart pub global activate protoc_plugin -export PATH="$PATH":"$HOME/.pub-cache/bin" """ script_runner = "@shell" @@ -35,7 +34,6 @@ 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"