From 6aeb382706e29c31554ef7bcfecf7e213e2e30c7 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Mon, 21 Feb 2022 12:08:45 +0100 Subject: [PATCH] move state inspector for sled store into corresponding crate --- crates/matrix-sdk-base/Cargo.toml | 17 +------- crates/matrix-sdk-crypto/src/lib.rs | 2 +- crates/matrix-sdk-sled/Cargo.toml | 21 +++++++++ .../bin}/state_inspector.rs | 41 +++++------------- .../bin}/syntaxes.bin | Bin .../bin}/themes.bin | Bin 6 files changed, 33 insertions(+), 48 deletions(-) rename crates/{matrix-sdk-base/examples => matrix-sdk-sled/bin}/state_inspector.rs (90%) rename crates/{matrix-sdk-base/examples => matrix-sdk-sled/bin}/syntaxes.bin (100%) rename crates/{matrix-sdk-base/examples => matrix-sdk-sled/bin}/themes.bin (100%) diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index 1df76d630..11b3fc0f9 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -58,19 +58,4 @@ features = ["client-api-c"] [dev-dependencies] futures = { version = "0.3.15", default-features = false, features = ["executor"] } http = "0.2.4" -matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } - -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] -atty = "0.2.14" -clap = "3.0.13" -rustyline = "9.0.0" -rustyline-derive = "0.6.0" -syntect = "4.5.0" -tokio = { version = "1.7.1", default-features = false, features = [ - "rt-multi-thread", - "macros", -] } -tempfile = "3.2.0" - -[[example]] -name = "state_inspector" +matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } \ No newline at end of file diff --git a/crates/matrix-sdk-crypto/src/lib.rs b/crates/matrix-sdk-crypto/src/lib.rs index 1c56d647d..57bef0fc1 100644 --- a/crates/matrix-sdk-crypto/src/lib.rs +++ b/crates/matrix-sdk-crypto/src/lib.rs @@ -43,8 +43,8 @@ mod utilities; mod verification; #[cfg(feature = "testing")] -pub mod testing { /// Testing facilities and helpers for crypto tests +pub mod testing { pub use crate::identities::{ device::testing::get_device, user::testing::{get_other_identity, get_own_identity}, diff --git a/crates/matrix-sdk-sled/Cargo.toml b/crates/matrix-sdk-sled/Cargo.toml index 3b96fbe7a..48db98bcf 100644 --- a/crates/matrix-sdk-sled/Cargo.toml +++ b/crates/matrix-sdk-sled/Cargo.toml @@ -3,10 +3,23 @@ name = "matrix-sdk-sled" version = "0.1.0" edition = "2021" +[[bin]] +name = "state-inspector" +path = "bin/state_inspector.rs" +required-features = ["binary-build"] + [features] default = ["encryption"] encryption = ["matrix-sdk-crypto"] +binary-build = [ + "atty", + "clap", + "futures", + "rustyline", + "rustyline-derive", + "syntect", +] [dependencies] futures-core = "0.3.15" @@ -23,6 +36,14 @@ tracing = "0.1.26" anyhow = "1" dashmap = "4.0.2" +# binary-build only +atty = { version = "0.2.14", optional = true } +clap = { version = "3.1.0", optional = true } +futures = { version = "0.3.15", default-features = false, features = ["executor"], optional = true} +rustyline = { version = "9.0.0", optional = true } +rustyline-derive = { version = "0.6.0", optional = true } +syntect = { version = "4.5.0", optional = true } + [dev-dependencies] lazy_static = "1.4" tempfile = "3.2.0" diff --git a/crates/matrix-sdk-base/examples/state_inspector.rs b/crates/matrix-sdk-sled/bin/state_inspector.rs similarity index 90% rename from crates/matrix-sdk-base/examples/state_inspector.rs rename to crates/matrix-sdk-sled/bin/state_inspector.rs index 7ea2f5131..fa149d0b6 100644 --- a/crates/matrix-sdk-base/examples/state_inspector.rs +++ b/crates/matrix-sdk-sled/bin/state_inspector.rs @@ -1,13 +1,11 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc}; -#[cfg(not(target_arch = "wasm32"))] use atty::Stream; -#[cfg(not(target_arch = "wasm32"))] -use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg, ArgMatches}; +use clap::{Command as Argparse, Arg, ArgMatches}; use futures::executor::block_on; use matrix_sdk_base::{RoomInfo, Store}; -use ruma::{events::EventType, RoomId, UserId}; -#[cfg(not(target_arch = "wasm32"))] +use matrix_sdk_sled::{StateStore}; +use matrix_sdk_common::ruma::{events::EventType, RoomId, UserId}; use rustyline::{ completion::{Completer, Pair}, error::ReadlineError, @@ -16,10 +14,8 @@ use rustyline::{ validate::{MatchingBracketValidator, Validator}, CompletionType, Config, Context, EditMode, Editor, OutputStreamType, }; -#[cfg(not(target_arch = "wasm32"))] use rustyline_derive::Helper; use serde::Serialize; -#[cfg(not(target_arch = "wasm32"))] use syntect::{ dumps::from_binary, easy::HighlightLines, @@ -29,14 +25,12 @@ use syntect::{ }; #[derive(Clone)] -#[cfg(not(target_arch = "wasm32"))] struct Inspector { store: Store, printer: Printer, } #[derive(Helper)] -#[cfg(not(target_arch = "wasm32"))] struct InspectorHelper { store: Store, _highlighter: MatchingBracketHighlighter, @@ -44,7 +38,6 @@ struct InspectorHelper { _hinter: HistoryHinter, } -#[cfg(not(target_arch = "wasm32"))] impl InspectorHelper { const EVENT_TYPES: &'static [&'static str] = &[ "m.room.aliases", @@ -92,7 +85,6 @@ impl InspectorHelper { } } -#[cfg(not(target_arch = "wasm32"))] impl Completer for InspectorHelper { type Candidate = Pair; @@ -151,19 +143,15 @@ impl Completer for InspectorHelper { } } -#[cfg(not(target_arch = "wasm32"))] impl Hinter for InspectorHelper { type Hint = String; } -#[cfg(not(target_arch = "wasm32"))] impl Highlighter for InspectorHelper {} -#[cfg(not(target_arch = "wasm32"))] impl Validator for InspectorHelper {} #[derive(Clone, Debug)] -#[cfg(not(target_arch = "wasm32"))] struct Printer { ps: Arc, ts: Arc, @@ -171,7 +159,6 @@ struct Printer { color: bool, } -#[cfg(not(target_arch = "wasm32"))] impl Printer { fn new(json: bool, color: bool) -> Self { let syntax_set: SyntaxSet = from_binary(include_bytes!("./syntaxes.bin")); @@ -210,12 +197,10 @@ impl Printer { } } -#[cfg(not(target_arch = "wasm32"))] impl Inspector { fn new(database_path: &str, json: bool, color: bool) -> Self { let printer = Printer::new(json, color); - // FIXME: THIS DOESN"T MAKE SENSE - let store = Store::open_memory_store(); + let store = Store::new(Box::new(StateStore::open_with_path(database_path).expect("Can't open sled database"))); Self { store, printer } } @@ -308,10 +293,10 @@ impl Inspector { async fn parse_and_run(&self, input: &str) { let argparse = Argparse::new("state-inspector") - .global_setting(ArgParseSettings::DisableHelpFlag) - .global_setting(ArgParseSettings::DisableVersionFlag) - .global_setting(ArgParseSettings::NoBinaryName) - .setting(ArgParseSettings::SubcommandRequiredElseHelp) + .disable_version_flag(true) + .disable_help_flag(true) + .no_binary_name(true) + .arg_required_else_help(true) .subcommands(Inspector::subcommands()); match argparse.try_get_matches_from(input.split_ascii_whitespace()) { @@ -325,10 +310,9 @@ impl Inspector { } } -#[cfg(not(target_arch = "wasm32"))] fn main() { let argparse = Argparse::new("state-inspector") - .global_setting(ArgParseSettings::DisableVersionFlag) + .disable_version_flag(true) .arg(Arg::new("database").required(true)) .arg( Arg::new("json") @@ -367,9 +351,4 @@ fn main() { } else { block_on(inspector.run(matches)); } -} - -#[cfg(target_arch = "wasm32")] -fn main() { - panic!("This example doesn't run on WASM"); -} +} \ No newline at end of file diff --git a/crates/matrix-sdk-base/examples/syntaxes.bin b/crates/matrix-sdk-sled/bin/syntaxes.bin similarity index 100% rename from crates/matrix-sdk-base/examples/syntaxes.bin rename to crates/matrix-sdk-sled/bin/syntaxes.bin diff --git a/crates/matrix-sdk-base/examples/themes.bin b/crates/matrix-sdk-sled/bin/themes.bin similarity index 100% rename from crates/matrix-sdk-base/examples/themes.bin rename to crates/matrix-sdk-sled/bin/themes.bin