From 8edc25168ea88bfc4904f50ec846eb4fd62f2c6e Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 4 Nov 2021 22:13:05 +0800 Subject: [PATCH] [rust]: update script --- Makefile.toml | 32 +++++++++++-------- app_flowy/.gitignore | 4 +-- rust-lib/dart-ffi/Cargo.toml | 2 +- .../src/services/doc/revision/persistence.rs | 12 ++++++- scripts/makefile/desktop.toml | 20 ++++++------ scripts/makefile/flutter.toml | 16 ++++------ 6 files changed, 49 insertions(+), 37 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 0acc516255..9e60ba7a89 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -10,61 +10,67 @@ extend = [ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true CARGO_MAKE_CRATE_FS_NAME = "dart_ffi" CARGO_MAKE_CRATE_NAME = "dart-ffi" +VERSION = "0.0.1" -#crate_type: https://doc.rust-lang.org/reference/linkage.html +#CRATE_TYPE: https://doc.rust-lang.org/reference/linkage.html [env.development-mac] DEV = true PROD = false TARGET_OS = "macos" DESKTOP_TARGET = "x86_64-apple-darwin" -crate_type = "cdylib" +CRATE_TYPE = "cdylib" BUILD_FLAG = "debug" -CROSS_PLATFORM = "macos" +FLUTTER_PLATFORM = "macos" FLUTTER_OUTPUT_DIR = "Debug" +PRODUCT_NAME = "app_flowy.app" [env.production-mac] DEV = false PROD = true TARGET_OS = "macos" DESKTOP_TARGET = "x86_64-apple-darwin" -crate_type = "cdylib" +CRATE_TYPE = "cdylib" BUILD_FLAG = "release" -CROSS_PLATFORM = "macos" +FLUTTER_PLATFORM = "macos" FLUTTER_OUTPUT_DIR = "Release" +PRODUCT_NAME = "app_flowy.app" [env.production-ios] DEV = false PROD = true TARGET_OS = "ios" -crate_type = "staticlib" +CRATE_TYPE = "staticlib" BUILD_FLAG = "release" -CROSS_PLATFORM = "ios" +FLUTTER_PLATFORM = "ios" FLUTTER_OUTPUT_DIR = "Release" +PRODUCT_NAME = "app_flowy.ipa" [env.production-android] DEV = false PROD = true TARGET_OS = "android" -crate_type = "cdylib" +CRATE_TYPE = "cdylib" BUILD_FLAG = "release" -CROSS_PLATFORM = "apk" +FLUTTER_PLATFORM = "apk" FLUTTER_OUTPUT_DIR = "Release" +PRODUCT_NAME = "app_flowy.apk" [env.production-win] DEV = false PROD = true TARGET_OS = "windows" -crate_type = "cdylib" +CRATE_TYPE = "cdylib" BUILD_FLAG = "release" -CROSS_PLATFORM = "apk" +FLUTTER_PLATFORM = "apk" FLUTTER_OUTPUT_DIR = "Release" +PRODUCT_NAME = "app_flowy.exe" [tasks.setup-crate-type] private = true script = [ """ toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml - val = replace ${toml} "rlib" ${crate_type} + val = replace ${toml} "rlib" ${CRATE_TYPE} result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml ${val} assert ${result} """, @@ -76,7 +82,7 @@ private = true script = [ """ toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml - val = replace ${toml} ${crate_type} "rlib" + val = replace ${toml} ${CRATE_TYPE} "rlib" result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/${CARGO_MAKE_CRATE_NAME}/Cargo.toml ${val} assert ${result} """, diff --git a/app_flowy/.gitignore b/app_flowy/.gitignore index efabc96754..2434bfe9a6 100644 --- a/app_flowy/.gitignore +++ b/app_flowy/.gitignore @@ -48,5 +48,5 @@ app.*.map.json /packages/flowy_protobuf /packages/flutter-quill -product/Release -product/Debug \ No newline at end of file +product/**/Release +product/**/Debug \ No newline at end of file diff --git a/rust-lib/dart-ffi/Cargo.toml b/rust-lib/dart-ffi/Cargo.toml index 1721d2672a..323e66b82b 100644 --- a/rust-lib/dart-ffi/Cargo.toml +++ b/rust-lib/dart-ffi/Cargo.toml @@ -35,7 +35,7 @@ flowy-net = {path = "../flowy-net"} [features] -observable = ["flowy-dart-notify/dart"] +flutter = ["flowy-dart-notify/dart"] http_server = ["flowy-sdk/http_server", "flowy-sdk/use_bunyan"] #use_serde = ["bincode"] #use_protobuf= ["protobuf"] \ No newline at end of file diff --git a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs index 1ebf63d6d4..1def0c394b 100644 --- a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs +++ b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs @@ -8,7 +8,7 @@ use async_stream::stream; use dashmap::DashMap; use flowy_database::ConnectionPool; use flowy_infra::future::ResultFuture; -use flowy_ot::core::{Delta, OperationTransformable}; +use flowy_ot::core::{Delta, Operation, OperationTransformable}; use futures::stream::StreamExt; use std::{collections::VecDeque, sync::Arc, time::Duration}; use tokio::{ @@ -200,6 +200,16 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc) -> DocRes }, } } + match delta.ops.last() { + None => {}, + Some(op) => { + let data = op.get_data(); + if !data.ends_with("\n") { + log::error!("The op must end with newline"); + } + }, + } + Result::::Ok(Doc { id: doc_id, data: delta.to_json(), diff --git a/scripts/makefile/desktop.toml b/scripts/makefile/desktop.toml index ce46d8f5bf..5c0c3aa838 100644 --- a/scripts/makefile/desktop.toml +++ b/scripts/makefile/desktop.toml @@ -8,19 +8,25 @@ run_task = { name = ["copy-to-sys-tmpdir"] } [tasks.flowy-sdk-build] condition = { channels = ["nightly"] } -run_task = { name = ["setup-crate-type","sdk_build", "post-desktop", "restore-crate-type"] } +run_task = { name = ["setup-crate-type","sdk-build", "post-desktop", "restore-crate-type"] } -[tasks.sdk_build] +[tasks.sdk-build] condition = { platforms = ["mac"] } description = "Build desktop targets." script = [ """ cd rust-lib/ - cargo build --${BUILD_FLAG} --package=dart-ffi --target ${DESKTOP_TARGET} --features="observable","http_server" + if [ ${PROD} == true ] + then + cargo build --${BUILD_FLAG} --package=dart-ffi --target ${DESKTOP_TARGET} --features="flutter","http_server" + else + cargo build --package=dart-ffi --target ${DESKTOP_TARGET} --features="flutter","http_server" + fi cd ../ """, ] + [tasks.post-desktop] private = true condition = { platforms = ["mac"] } @@ -50,11 +56,3 @@ script = [ ] script_runner = "@duckscript" -#[tasks.export-env] -#script = [ -# """ -# export MACOSX_DEPLOYMENT_TARGET=10.11 -# """, -#] -#script_runner = "@shell" - diff --git a/scripts/makefile/flutter.toml b/scripts/makefile/flutter.toml index 5396e31bf9..aeff1e1883 100644 --- a/scripts/makefile/flutter.toml +++ b/scripts/makefile/flutter.toml @@ -8,9 +8,9 @@ script_runner = "@shell" script = [ """ cd app_flowy/ -# flutter clean -# flutter pub get -# flutter build ${CROSS_PLATFORM} --${BUILD_FLAG} + flutter clean + flutter pub get + flutter build ${FLUTTER_PLATFORM} --${BUILD_FLAG} --build-name=${VERSION} """, ] script_runner = "@shell" @@ -19,17 +19,15 @@ script_runner = "@shell" [tasks.copy-to-product] script = [ """ - product_path=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/product + product_path=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/product/${VERSION} output_path=${product_path}/${FLUTTER_OUTPUT_DIR} if [ -d "${output_path}" ]; then rm -rf ${output_path}/ fi + mkdir -p ${output_path} - cd ${product_path} - mkdir ${FLUTTER_OUTPUT_DIR} - - cp -R ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/build/${CROSS_PLATFORM}/Build/Products/${FLUTTER_OUTPUT_DIR}/app_flowy.app \ - ${output_path}/app_flowy.app + cp -R ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/app_flowy/build/${FLUTTER_PLATFORM}/Build/Products/${FLUTTER_OUTPUT_DIR}/${PRODUCT_NAME} \ + ${output_path}/${PRODUCT_NAME} """, ] script_runner = "@shell"