Skip to content

Commit

Permalink
Update dependencies and minimal rust version
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Aug 5, 2023
1 parent 9ed5485 commit 0a701fe
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 202 deletions.
37 changes: 19 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,66 @@
name = "dbgen"
version = "0.8.0"
authors = ["kennytm <[email protected]>"]
edition = "2018"
edition = "2021"
license = "MIT"
description = "Generate random test cases for databases"
repository = "https://github.com/kennytm/dbgen"
exclude = ["fuzz.sh", "release/*"]
readme = "README.md"
keywords = ["cli", "generator", "database", "fake"]
categories = ["command-line-utilities", "simulation"]
rust-version = "1.71.0"

[workspace]
members = ["dbgen-playground", "dbdbgen"]

[dependencies]
structopt = { version = "0.3", optional = true }
pest = "2.1"
pest_derive = "2.1"
pest = "2.7"
pest_derive = "2.7"
thiserror = "1.0"
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
data-encoding = "2.3"
rand = { version = "0.8.5", default-features = false, features = ["getrandom"] }
data-encoding = "2.4"
data-encoding-macro = "0.1"
regex-syntax = "0.6"
pbr = { version = "1.0", optional = true }
regex-syntax = "0.7"
pbr = { version = "1.1", optional = true }
num-traits = "0.2"
rayon = { version = "1.3", optional = true }
rayon = { version = "1.7", optional = true }
zipf = "7.0"
chrono = { version = "0.4", default-features = false, features = ["serde"] }
chrono = { version = "0.4.26", default-features = false, features = ["std", "serde", "clock"] }
tzfile = "0.1"
ryu = "1.0"
serde = "1.0"
muldiv = { version = "1.0", optional = true }
rand_distr = { version = "0.4", default-features = false, features = ["alloc"] }
rand_regex = "0.15.1"
rand_regex = "0.16"
rand_pcg = { version = "0.3", optional = true }
rand_isaac = { version = "0.3", optional = true }
rand_chacha = { version = "0.3", optional = true }
rand_hc = "0.3"
rand_xorshift = { version = "0.3", optional = true }
shlex = { version = "1.0", optional = true }
shlex = { version = "1.1", optional = true }
flate2 = { version = "1.0", optional = true }
xz2 = { version = "0.1", optional = true }
zstd = { version = "0.9", default-features = false, optional = true }
smallvec = { version = "1.1", default-features = false }
memchr = "2.3"
zstd = { version = "0.12", default-features = false, optional = true }
smallvec = { version = "1.11", default-features = false }
memchr = "2.5"
numcmp = "0.1"
parse-size = { version = "1.0", optional = true }

[dev-dependencies]
regex = { version = "1.3", default-features = false }
tempfile = "3.1"
regex = { version = "1.9", default-features = false }
tempfile = "3.7"
serde_json = "1.0"
diff = "0.1"
criterion = "0.3"
criterion = "0.5"

[[bench]]
name = "benchmark"
harness = false

[build-dependencies]
vergen = { version = "5.1", default-features = false, features = ["git", "cargo"] }
vergen = { version = "8.2", default-features = false, features = ["git", "gitcl", "cargo"] }

[features]
default = ["cli"]
Expand Down
17 changes: 6 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use vergen::{vergen, Config};
use vergen::EmitBuilder;

fn main() {
let mut cfg = Config::default();
let git = cfg.git_mut();
*git.branch_mut() = false;
*git.commit_timestamp_mut() = false;
*git.semver_mut() = false;
let cargo = cfg.cargo_mut();
*cargo.features_mut() = false;
*cargo.profile_mut() = false;

vergen(cfg).unwrap();
EmitBuilder::builder()
.git_sha(false)
.cargo_target_triple()
.emit()
.unwrap();
}
8 changes: 4 additions & 4 deletions dbdbgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ dbgen = { path = "../" }
jsonnet-rs = "0.17"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
clap = "2.33"
clap = { version = "4.3", features = ["string"] }
thiserror = "1.0"
rand_core = { version = "0.6", features = ["getrandom"] }
data-encoding = "2.3"
sha2 = "0.9"
parse-size = "1.0"
data-encoding = "2.4"
sha2 = "0.10"
parse-size = { version = "1.0", features = ["std"] }
26 changes: 14 additions & 12 deletions dbdbgen/src/bin/dbdbgen.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
use clap::{App, AppSettings, Arg};
use clap::{Arg, ArgAction, Command};
use dbdbgen::{cli::ensure_seed, error::Error, jsvm::Vm};
use dbgen::{span::Registry, FULL_VERSION};
use std::error::Error as StdError;
use std::{error::Error as StdError, ffi::OsStr};

fn run() -> Result<(), Error> {
let global_matches = App::new("dbdbgen")
let global_matches = Command::new("dbdbgen")
.long_version(FULL_VERSION)
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.args(&[
Arg::with_name("dry-run")
Arg::new("dry-run")
.long("dry-run")
.action(ArgAction::SetTrue)
.help("Only display the evaluated dbdbgen result without generating data."),
Arg::with_name("allow-import")
Arg::new("allow-import")
.long("allow-import")
.action(ArgAction::SetTrue)
.help("Allows `import` and `importstr` to read files."),
Arg::with_name("file")
Arg::new("file")
.help("The Jsonnet file to execute, followed by the arguments passed to it.")
.multiple(true)
.action(ArgAction::Append)
.required(true)
.allow_hyphen_values(true),
])
.get_matches();
let mut args = global_matches.values_of_os("file").unwrap();
let src_file = args.next().unwrap();
let mut args = global_matches.get_many("file").unwrap();
let src_file: &&OsStr = args.next().unwrap();

let mut vm = Vm::new(src_file, global_matches.is_present("allow-import"))?;
let mut vm = Vm::new(src_file, global_matches.get_flag("allow-import"))?;
let app = vm.eval_arguments()?;
let mut matches = app.get_matches(args);
ensure_seed(&mut matches);
let steps = vm.eval_steps(matches)?;

if global_matches.is_present("dry-run") {
if global_matches.get_flag("dry-run") {
println!(
"/* dbdbgen{}\n*/\n{{\"steps\": {}}}",
FULL_VERSION,
Expand Down
132 changes: 59 additions & 73 deletions dbdbgen/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use clap::{
self,
builder::{PossibleValuesParser, ValueParser},
value_parser, ArgAction, Command,
};
use data_encoding::HEXLOWER_PERMISSIVE;
use parse_size::parse_size;
use rand_core::{OsRng, RngCore};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, ffi::OsString};

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ArgType {
Bool,
Expand All @@ -16,21 +20,26 @@ pub enum ArgType {
}

impl ArgType {
fn parse_input(&self, input: &str) -> Result<Match, String> {
fn arg_action(&self) -> ArgAction {
match self {
Self::Int => match input.parse() {
Ok(u) => Ok(Match::Int(u)),
Err(e) => Err(e.to_string()),
},
Self::Float => match input.parse() {
Ok(f) => Ok(Match::Float(f)),
Err(e) => Err(e.to_string()),
},
Self::Size => match parse_size(input) {
Ok(u) => Ok(Match::Int(u)),
Err(e) => Err(e.to_string()),
},
_ => Ok(Match::Str(input.to_owned())),
Self::Bool => ArgAction::SetTrue,
Self::Choices { multiple: true, .. } => ArgAction::Append,
_ => ArgAction::Set,
}
}

fn value_parser(&self) -> ValueParser {
fn specialized_parse_size(s: &str) -> Result<u64, parse_size::Error> {
parse_size::parse_size(s)
}

match self {
Self::Bool => ValueParser::bool(),
Self::Str => ValueParser::string(),
Self::Int => value_parser!(u64).into(),
Self::Size => ValueParser::new(specialized_parse_size),
Self::Float => value_parser!(f64).into(),
Self::Choices { choices, .. } => ValueParser::new(PossibleValuesParser::new(choices)),
}
}
}
Expand Down Expand Up @@ -75,55 +84,25 @@ pub type Matches<'a> = HashMap<&'a str, Match>;

impl App {
/// Constructs the clap App from this simplified specification.
fn to_clap_app(&self) -> clap::App<'_, '_> {
let mut app = clap::App::new(&self.name)
.bin_name(format!("dbdbgen {}", self.name))
.version(&*self.version)
.about(&*self.about)
.settings(&[
clap::AppSettings::NoBinaryName,
clap::AppSettings::UnifiedHelpMessage,
clap::AppSettings::NextLineHelp,
]);

for (name, arg) in &self.args {
let mut clap_arg = clap::Arg::with_name(name)
.long(if arg.long.is_empty() { name } else { &arg.long })
.help(&arg.help);
if !arg.short.is_empty() {
clap_arg = clap_arg.short(&arg.short);
}
match &arg.r#type {
ArgType::Bool => {}
ArgType::Str => {
clap_arg = clap_arg.takes_value(true);
}
ArgType::Int | ArgType::Float | ArgType::Size => {
let t = arg.r#type.clone();
clap_arg = clap_arg
.takes_value(true)
.validator(move |s| t.parse_input(&s).map(drop));
}
ArgType::Choices { choices, multiple } => {
for choice in choices {
clap_arg = clap_arg.possible_value(choice);
}
if *multiple {
clap_arg = clap_arg.required(true).use_delimiter(true).multiple(true);
}
}
}
if arg.required {
clap_arg = clap_arg.required(true);
}
if let Some(default) = &arg.default {
clap_arg = clap_arg.default_value(default);
}
fn to_clap_app(&self) -> Command {
use clap::builder::{OsStr, Resettable};

app = app.arg(clap_arg);
}

app
Command::new(&self.name)
.bin_name(format!("dbdbgen {}", self.name))
.version(&self.version)
.about(&self.about)
.no_binary_name(true)
.next_line_help(true)
.args(self.args.iter().map(|(name, arg)| {
clap::Arg::new(name)
.long(if arg.long.is_empty() { name } else { &arg.long })
.help(&arg.help)
.short(arg.short.chars().next())
.action(arg.r#type.arg_action())
.value_parser(arg.r#type.value_parser())
.required(arg.required)
.default_value(Resettable::from(arg.default.as_ref().map(OsStr::from)))
}))
}

/// Obtains the matches from the command line.
Expand All @@ -136,18 +115,25 @@ impl App {
let matches = clap_app.get_matches_from(args);
let mut result = HashMap::with_capacity(self.args.len());
for (name, arg) in &self.args {
let value = match &arg.r#type {
ArgType::Bool => Match::Bool(matches.is_present(name)),
ArgType::Choices { multiple: true, .. } => {
if let Some(values) = matches.values_of(name) {
Match::Array(values.map(String::from).collect())
macro_rules! get_one {
($ty:ty) => {
if let Some(value) = matches.get_one(name) {
let value: &$ty = value;
value.clone()
} else {
continue;
}
}
_ => {
if let Some(value) = matches.value_of(name) {
arg.r#type.parse_input(value).unwrap()
};
}

let value = match &arg.r#type {
ArgType::Bool => Match::Bool(matches.get_flag(name)),
ArgType::Str | ArgType::Choices { multiple: false, .. } => Match::Str(get_one!(String)),
ArgType::Int | ArgType::Size => Match::Int(get_one!(u64)),
ArgType::Float => Match::Float(get_one!(f64)),
ArgType::Choices { multiple: true, .. } => {
if let Some(values) = matches.get_many(name) {
Match::Array(values.map(|s: &&str| s.to_string()).collect())
} else {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion dbdbgen/src/jsvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'p> Vm<'p> {

let mut steps = Vec::new();
for (i, steps_js) in steps_js_stream.iter().enumerate() {
let step = deserialize(&steps_js, Purpose::Execution { step: i })?;
let step = deserialize(steps_js, Purpose::Execution { step: i })?;
steps.push(step);
}

Expand Down
3 changes: 2 additions & 1 deletion dbgen-playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ crate-type = ["cdylib"]
[dependencies]
dbgen = { path = "../", default-features = false }
chrono = { version = "0.4", default-features = false }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
wasm-bindgen = "0.2"
serde-wasm-bindgen = "0.4"
rand = { version = "0.8", default-features = false }
rand_hc = "0.3"
serde = { version = "1.0", features = ["derive"] }
2 changes: 1 addition & 1 deletion dbgen-playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn try_generate_rows(
pub fn generate_rows(template: &str, rows: usize, now: &str, seed: &[u8]) -> Result<JsValue, JsValue> {
let mut registry = Registry::default();
match try_generate_rows(template, rows, now, seed, &mut registry) {
Ok(result) => JsValue::from_serde(&result).map_err(|e| e.to_string().into()),
Ok(result) => serde_wasm_bindgen::to_value(&result).map_err(|e| e.to_string().into()),
Err(e) => Err(registry.describe(&e).into()),
}
}
Expand Down
22 changes: 16 additions & 6 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ name = 'zipf'
version = '7.0'

[[licenses.exceptions]]
allow = ['0BSD']
name = 'enum-iterator' # dependency of vergen v5.1
version = '0.7'
allow = ['Apache-2.0']
name = 'ciborium'
version = '0.2'

[[licenses.exceptions]]
allow = ['Apache-2.0']
name = 'ciborium-io'
version = '0.2'

[[licenses.exceptions]]
allow = ['Apache-2.0']
name = 'ciborium-ll'
version = '0.2'

[[licenses.exceptions]]
allow = ['0BSD']
name = 'enum-iterator-derive' # dependency of vergen v5.1
version = '0.7'
allow = ['Unicode-DFS-2016']
name = 'unicode-ident'
version = '1.0.11'
Loading

0 comments on commit 0a701fe

Please sign in to comment.