Browse Source

Merge pull request #312 from AppFlowy-IO/fix_ci

feat: install protoc-gen-dart if not installed
Nathan.fooo 3 years ago
parent
commit
10187ce049

+ 2 - 0
.github/workflows/ci.yaml

@@ -32,6 +32,7 @@ jobs:
         run: |
           cargo install --force cargo-make
           cargo install --force duckscript_cli
+          brew install protobuf
           cargo make flowy_dev
       - name: Build
         working-directory: frontend
@@ -73,6 +74,7 @@ jobs:
         run: |
           cargo install --force cargo-make
           cargo install --force duckscript_cli
+          sudo apt-get install protobuf-compiler
           cargo make flowy_dev
       - name: Build
         working-directory: frontend

+ 14 - 1
frontend/scripts/makefile/desktop.toml

@@ -5,7 +5,7 @@
 # cargo make --profile production-windows-x86 flowy-sdk-dev
 
 [tasks.env_check]
-dependencies = ["echo_env"]
+dependencies = ["echo_env", "install-pb-tool-if-need"]
 condition = { env_set = [ "BUILD_FLAG", "RUST_COMPILE_TARGET", "CRATE_TYPE", "TARGET_OS"],  channels = ["stable"] }
 
 [tasks.flowy-sdk-dev]
@@ -142,3 +142,16 @@ script = [
   """,
 ]
 script_runner = "@duckscript"
+
+[tasks.check_protoc_cmd]
+script = [
+  """
+  ret = which protoc
+  if is_empty ${ret}
+      echo Please make sure <protoc_installation_folder>/bin/ is in PATH env var
+      echo See BUILD_ON_{LINUX|WINDOWS}.md for how to get protoc
+      exit -1
+  end
+  """,
+]
+script_runner = "@duckscript"

+ 0 - 24
frontend/scripts/makefile/env.toml

@@ -95,30 +95,6 @@ dependencies=["install_targets"]
 [tasks.install_prerequests.windows]
 dependencies=["install_targets", "install_windows_deps"]
 
-[tasks.install_protobuf]
-script = """
-dart pub global activate protoc_plugin
-cargo install --version 2.22.1 protobuf-codegen
-"""
-
-[tasks.install_protobuf.windows]
-script = """
-ret = which dart
-if is_empty ${ret}
-    echo Please make sure flutter/dart is properly installed and in PATH env var
-    exit -1
-end
-ret = which protoc-gen-dart
-if is_empty ${ret}
-    exec cmd.exe /c dart pub global activate protoc_plugin
-    home_dir = get_home_dir
-    echo Please add '${home_dir}\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\bin' into PATH env var
-    exit -1
-end
-exec cargo install --version 2.22.1 protobuf-codegen
-"""
-script_runner = "@duckscript"
-
 [tasks.install_tools]
 script = """
 rustup component add rustfmt

+ 46 - 0
frontend/scripts/makefile/protobuf.toml

@@ -2,6 +2,52 @@
 [tasks.pb]
 dependencies = ["check_protoc_cmd", "gen_pb_file"]
 
+[tasks.install-pb-tool-if-need]
+condition_script = [
+    """
+    if [ ! "$(command -v dart)" ]; then
+        echo Please make sure flutter/dart is properly installed and in PATH env var
+        exit 1
+    fi
+
+    if [ ! "$(command -v protoc-gen-dart)" ]; then
+        # not install
+        exit 0
+    fi
+
+    # installed
+    exit 1
+    """,
+]
+run_task = { name = ["install_protobuf"] }
+
+[tasks.install_protobuf]
+script = """
+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]
+script = """
+ret = which dart
+if is_empty ${ret}
+    echo Please make sure flutter/dart is properly installed and in PATH env var
+    exit -1
+end
+ret = which protoc-gen-dart
+if is_empty ${ret}
+    exec cmd.exe /c dart pub global activate protoc_plugin
+    home_dir = get_home_dir
+    echo Please add '${home_dir}\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\bin' into PATH env var
+    exit -1
+end
+"""
+script_runner = "@duckscript"
+
 [tasks.check_protoc_cmd]
 script = [
     """

+ 5 - 2
shared-lib/lib-infra/src/pb_gen.rs

@@ -1,8 +1,10 @@
 #![allow(unused_imports)]
+#![allow(unused_attributes)]
 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![];
@@ -19,8 +21,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")
@@ -31,6 +33,7 @@ pub fn gen(name: &str, root: &str) {
 }
 
 #[cfg(feature = "dart")]
+#[allow(dead_code)]
 fn gen_pb_for_dart(name: &str, root: &str, paths: &Vec<String>, file_names: &Vec<String>) {
     let output = format!(
         "{}/{}/{}",