add build-time config file; live -> hot

master
Avril 4 years ago
parent cc31004e52
commit 260482290a
Signed by: flanchan
GPG Key ID: 284488987C31F630

137
Cargo.lock generated

@ -1,5 +1,20 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "addr2line"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
[[package]]
name = "anymap"
version = "0.12.1"
@ -23,6 +38,20 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "backtrace"
version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "1.2.1"
@ -52,6 +81,18 @@ dependencies = [
"time",
]
[[package]]
name = "config_struct"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aefd4a90b45fed157c31d107f8fdd9f8aaee79f0df625cefb773a9a1a10059f"
dependencies = [
"failure",
"linear-map",
"quote",
"toml",
]
[[package]]
name = "crossbeam-channel"
version = "0.4.3"
@ -73,6 +114,28 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
]
[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "filetime"
version = "0.2.10"
@ -221,6 +284,12 @@ dependencies = [
"slab",
]
[[package]]
name = "gimli"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
[[package]]
name = "hermit-abi"
version = "0.1.15"
@ -287,6 +356,16 @@ version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
[[package]]
name = "linear-map"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfae20f6b19ad527b550c223fddc3077a547fc70cda94b9b566575423fd303ee"
dependencies = [
"serde",
"serde_test",
]
[[package]]
name = "log"
version = "0.4.11"
@ -302,6 +381,7 @@ version = "0.1.0"
dependencies = [
"cfg-if",
"chrono",
"config_struct",
"futures",
"lazy_static",
"notify",
@ -318,6 +398,15 @@ version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "miniz_oxide"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.6.22"
@ -421,6 +510,12 @@ dependencies = [
"libc",
]
[[package]]
name = "object"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
[[package]]
name = "once_cell"
version = "1.4.0"
@ -506,6 +601,12 @@ version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "rustc-demangle"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -539,6 +640,21 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
[[package]]
name = "serde_test"
version = "1.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f58190d074af17bd48118303db08afadbd506bc2ba511b4582cebd8f882a9b8d"
dependencies = [
"serde",
]
[[package]]
name = "sexp"
version = "1.1.4"
@ -562,6 +678,18 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
name = "time"
version = "0.1.43"
@ -600,6 +728,15 @@ dependencies = [
"syn",
]
[[package]]
name = "toml"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
dependencies = [
"serde",
]
[[package]]
name = "unicode-xid"
version = "0.2.1"

@ -40,4 +40,5 @@ chrono = "0.4"
cfg-if = "0.1"
[build-dependencies]
rustc_version = "0.2"
rustc_version = "0.2"
config_struct = {version= "0.5", features=["toml-parsing"]}

@ -2,7 +2,9 @@
extern crate rustc_version;
use rustc_version::{version, version_meta, Channel};
fn main() {
use config_struct::{Error, StructOptions};
fn main() -> Result<(), Error> {
// Assert we haven't travelled back in time
assert!(version().unwrap().major >= 1);
@ -21,4 +23,11 @@ fn main() {
println!("cargo:rustc-cfg=dev");
}
}
config_struct::create_struct(
"build/config.toml",
"src/config/build_cfg.rs",
&StructOptions::default())?;
Ok(())
}

@ -0,0 +1,4 @@
# Compilation time options for hotreload module.
[hot]
backlog = 100
timeout = 5

@ -0,0 +1,24 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(dead_code)]
use std::borrow::Cow;
#[derive(Debug, Clone)]
#[allow(non_camel_case_types)]
pub struct Config {
pub hot: _Config__hot,
}
#[derive(Debug, Clone)]
#[allow(non_camel_case_types)]
pub struct _Config__hot {
pub backlog: i64,
pub timeout: i64,
}
pub const CONFIG: Config = Config {
hot: _Config__hot {
backlog: 100,
timeout: 5,
},
};

@ -3,8 +3,8 @@ use std::{
str,
fmt,
path::{
PathBuf,
Path,
PathBuf,
Path,
},
};
@ -22,6 +22,8 @@ pub use job::*;
mod global;
pub use global::*;
/// Parse a single config file
#[inline]
pub async fn parse_global_single(path: impl AsRef<Path>) -> Result<Config, error::Error>
@ -30,3 +32,41 @@ pub async fn parse_global_single(path: impl AsRef<Path>) -> Result<Config, error
parse::global(&mut cfg, path).await?;
Ok(cfg)
}
/// Re-exporting `build/config.toml`
#[allow(unused_imports)]
mod build_cfg;
pub mod build
{
use super::build_cfg::*;
use crate::static_assert;
/// Config for hotreload module `hot`
pub mod hot {
pub use super::*;
/// `GLOBAL_BACKLOG`
pub const BACKLOG: usize = CONFIG.hot.backlog as usize;
/// `GLOBAL_TIMEOUT`
pub const TIMEOUT: u64 = CONFIG.hot.timeout as u64;
static_assert!(BACKLOG > 0);
static_assert!(TIMEOUT > 0);
}
/// Print the status of `build.toml` vars
#[cfg(any(debug_assertions,feature="debug_logger"))]
pub fn stat()
{
use crate::status;
status!("Static options:");
status!(" hot::BACKLOG = {}", hot::BACKLOG);
status!(" hot::TIMEOUT = {}", hot::TIMEOUT);
}
/// Print the status of `build.toml` vars
#[cfg(not(any(debug_assertions,feature="debug_logger")))]
#[inline]
pub const fn stat(){}
}

@ -47,8 +47,8 @@ struct InnerContext
/// Worker for this context, that updates the children when needed.
worker: task::JoinHandle<()>,
/// Hook to send `live::Oneesan` events to.
live_hook: mpsc::Sender<live::Event>,
/// Hook to send `hot::Oneesan` events to.
live_hook: mpsc::Sender<hot::Event>,
}
/// The parent job Context, contains all worker child informations

@ -61,9 +61,9 @@ use notify::{
pub type Event = event::EventKind;
/// Max event backlog (not used if `unlimited_watcher` is set)
const GLOBAL_BACKLOG: usize = 100;
const GLOBAL_BACKLOG: usize = config::build::hot::BACKLOG; //100;
/// Timeout for hook dispatches in seconds. Only set if `watcher_timeout` feature is enabled.
const GLOBAL_TIMEOUT: u64 = 5;
const GLOBAL_TIMEOUT: u64 = config::build::hot::TIMEOUT;
/// Decontruct a notify event into event kind and full paths.
#[inline]

@ -361,7 +361,7 @@ impl Logger
let stdout = std::io::stdout();
let stdout = stdout.lock();
$crate::log::Logger::global().println(stdout, Status, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stdout, Status, $obj, $crate::get_trace!()).expect("i/o error");
}
};
($fmt:literal, $($args:expr),*) => {
@ -380,11 +380,11 @@ impl Logger
{
let stdout = std::io::stdout();
let stdout = stdout.lock();
$crate::log::Logger::global().println(stdout, $crate::log::Level::Info, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stdout, $crate::log::Level::Info, $obj, $crate::get_trace!()).expect("i/o error");
}
};
($fmt:literal, $($args:expr),*) => {
info!(format!($fmt, $($args,)*));
$crate::info!(format!($fmt, $($args,)*));
};
}
@ -415,11 +415,11 @@ impl Logger
let stdout = std::io::stdout();
let stdout = stdout.lock();
$crate::log::Logger::global().println(stdout, Important, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stdout, Important, $obj, $crate::get_trace!()).expect("i/o error");
}
};
($fmt:literal, $($args:expr),*) => {
important!(format!($fmt, $($args,)*));
$crate::important!(format!($fmt, $($args,)*));
};
}
@ -429,11 +429,11 @@ impl Logger
{
let stderr = std::io::stderr();
let stderr = stderr.lock();
$crate::log::Logger::global().println(stderr, $crate::log::Level::Warn, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stderr, $crate::log::Level::Warn, $obj, $crate::get_trace!()).expect("i/o error");
}
};
($fmt:literal, $($args:expr),*) => {
warn!(format!($fmt, $($args,)*));
$crate::warn!(format!($fmt, $($args,)*));
};
}
@ -465,11 +465,11 @@ impl Logger
let stderr = std::io::stderr();
let stderr = stderr.lock();
$crate::log::Logger::global().println(stderr, Dangerous, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stderr, Dangerous, $obj, $crate::get_trace!()).expect("i/o error");
}
};
($fmt:literal, $($args:expr),*) => {
dangerous!(format!($fmt, $($args,)*));
$crate::dangerous!(format!($fmt, $($args,)*));
};
}
@ -478,11 +478,11 @@ impl Logger
{
let stderr = std::io::stderr();
let stderr = stderr.lock();
$crate::log::Logger::global().println(stderr, $crate::log::Level::Error, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stderr, $crate::log::Level::Error, $obj, $crate::get_trace!()).expect("i/o error");
}
};
($fmt:literal, $($args:expr),*) => {
error!(format!($fmt, $($args,)*));
$crate::error!(format!($fmt, $($args,)*));
};
}
@ -491,13 +491,13 @@ impl Logger
{
let stdout = std::io::stdout();
let stdout = stdout.lock();
$crate::log::Logger::global().println(stdout, $crate::log::Level::Silent, $obj, get_trace!()).expect("i/o error");
$crate::log::Logger::global().println(stdout, $crate::log::Level::Silent, $obj, $crate::get_trace!()).expect("i/o error");
std::process::exit(-1)
}
};
($fmt:literal, $($args:expr),*) => {
fatal!(format!($fmt, $($args,)*));
$crate::fatal!(format!($fmt, $($args,)*));
};
}

@ -25,7 +25,7 @@ mod log;
mod interval;
mod config;
mod live;
mod hot;
mod context;
mod job;
@ -108,6 +108,9 @@ fn print_stats()
#[cfg(not(feature="watcher_timeout"))] status!(" -watcher_timeout".bright_blue());
status!("");
config::build::stat();
status!("GPl'd with <3");
status!("Please enjoy");
@ -124,10 +127,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature="watcher")]
{
let oneesan = live::watch(".");
let oneesan = hot::watch(".");
{
let mut recv = oneesan.hook("src/main.rs", live::filter::ALL).await;
let mut recv = oneesan.hook("src/main.rs", hot::filter::ALL).await;
while let Some(event) = recv.recv().await
{
important!("Got ev {:?}", event);

@ -223,3 +223,10 @@ impl<T> DerefMut for Opaque<T>
}
}
// static assert
#[macro_export] macro_rules! static_assert {
($ex:expr) => {
const _: &[bool; ((($ex) == true) as usize)] = &[true];
}
}

Loading…
Cancel
Save