diff --git a/deploy b/deploy new file mode 100644 index 0000000..bdcb6d3 --- /dev/null +++ b/deploy @@ -0,0 +1,23 @@ + +if [[ "$1" == "a" ]] +then + ssh acern mkdir -p /tmp/victorinix + rsync -rv --exclude="target" ./* acern:/tmp/victorinix/ + path=$(ssh acern nix build /tmp/victorinix#webfiles -L --print-out-paths) + + echo doneeeeeeeeeeeeeee + echo path: $path + + scp -r acern:$path/* ocih:host/webserver/webfiles +else + path=$(nix build .#webfiles -L -v --print-out-paths $@) + + echo doneeeeeeeeeeeeeee + echo path: $path + + scp -r $path/* ocih:host/webserver/webfiles +fi + + + + diff --git a/flake.nix b/flake.nix index 0817d9b..2698565 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,9 @@ let in { ############################## PACKAGES ############################## + + webfiles = pkgs.callPackage ./webfiles.nix { inherit inputs nixpkgs self; }; + packages.default = osCrane.buildPackage { src = "${self}"; cargoExtraArgs = "--bin mize --features os-binary"; diff --git a/modules b/modules index a605c0e..40062ee 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a605c0efb12529c7aa46a098b95138c924731128 +Subproject commit 40062ee4b1de0f5b0418edecd2509d884a8ee047 diff --git a/src/core/instance/mod.rs b/src/core/instance/mod.rs index 3eb51e8..eb02d9f 100644 --- a/src/core/instance/mod.rs +++ b/src/core/instance/mod.rs @@ -8,7 +8,7 @@ use tracing::{debug, error, info, trace, warn, Instrument}; use uuid::Uuid; use std::fs::File; use colored::Colorize; -use std::path::Path; +use std::path::{Path, PathBuf}; use interner::shared::{VecStringPool, StringPool}; @@ -290,7 +290,12 @@ impl Instance { pub fn load_module(&mut self, name: &str) -> MizeResult<()> { // platform specific init code - crate::platform::any::load_module(self, name) + crate::platform::any::load_module(self, name, None) + } + + pub fn load_module_at(&mut self, name: &str, path: PathBuf) -> MizeResult<()> { + // platform specific init code + crate::platform::any::load_module(self, name, Some(path)) } pub fn namespace_from_string(&self, ns_str: String) -> MizeResult { diff --git a/src/lib.rs b/src/lib.rs index 915d7dc..e35b16f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ pub use core::instance::module::Module; pub use core::instance::Instance; pub use core::error::MizeError; pub use core::error::MizeResult; +use std::path::PathBuf; // platform specific stuff pub mod platform { @@ -52,6 +53,6 @@ pub mod platform { pub fn instance_init(instance: &mut core::instance::Instance) {} -pub fn load_module(instance: &mut core::instance::Instance, name: &str) -> MizeResult<()> { Ok(()) } +pub fn load_module(instance: &mut core::instance::Instance, name: &str, path: Option) -> MizeResult<()> { Ok(()) } diff --git a/src/platform/os/cli.rs b/src/platform/os/cli.rs index b1d86ff..22638f5 100644 --- a/src/platform/os/cli.rs +++ b/src/platform/os/cli.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use clap::ArgMatches; use home::home_dir; +use crossbeam::channel::bounded; use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait}; use mize::instance::Instance; @@ -131,7 +132,11 @@ pub fn stop(sub_matches: &ArgMatches) -> MizeResult<()> { pub fn gui(sub_matches: &ArgMatches) -> MizeResult<()> { - let instance = Instance::with_config(config_from_cli_args(sub_matches)?)?; + let mut instance = Instance::with_config(config_from_cli_args(sub_matches)?)?; + + instance.load_module("mme")?; + + instance.wait(); Ok(()) } diff --git a/src/platform/os/main.rs b/src/platform/os/main.rs index cdd7c78..87fbe4c 100644 --- a/src/platform/os/main.rs +++ b/src/platform/os/main.rs @@ -166,7 +166,6 @@ fn cli_matches() -> clap::ArgMatches { ) .subcommand( Command::new("gui") - .aliases(["g"]) ) .arg_required_else_help(true); diff --git a/src/platform/os/mod.rs b/src/platform/os/mod.rs index e95828a..13dea17 100644 --- a/src/platform/os/mod.rs +++ b/src/platform/os/mod.rs @@ -4,7 +4,7 @@ use std::env::VarError; use std::fs; use tracing::{debug, error, info, trace, warn}; use clap::ArgMatches; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; use crate::id::MizeId; @@ -96,37 +96,49 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> { Ok(()) } -pub fn seconds_since_modification(path: &Path) -> u64 { - let metadata = match fs::metadata(path) { - Err(_) => { return u64::MAX; }, // we are the older file, if it fails - Ok(data) => data, - }; +pub fn seconds_since_modification(path: &Path) -> MizeResult { + let metadata = fs::metadata(path)?; - let modified = match metadata.modified() { - Err(_) => { return u64::MAX; }, // we are the older file, if it fails - Ok(data) => data, - }; + let modified = metadata.modified()?; - let duration = match modified.duration_since(UNIX_EPOCH) { - Err(_) => { return u64::MAX; }, // we are the older file, if it fails - Ok(data) => data, - }; + let duration = modified.duration_since(UNIX_EPOCH)?; - duration.as_secs() + Ok(duration.as_secs()) } -pub fn load_module(instance: &mut Instance, name: &str) -> MizeResult<()> { +fn get_correct_module_path(module_dir: &Path, name: &str) -> MizeResult { + let mut release_path = module_dir.join("modules").join(name).join("target").join("release").join(format!("libmize_module_{}.so", name)); + let mut debug_path = module_dir.join("modules").join(name).join("target").join("debug").join(format!("libmize_module_{}.so", name)); + + if !release_path.exists() && !debug_path.exists() { + release_path = module_dir.join("modules").join(name).join("target").join("release").join(format!("lib{}.so", name)); + debug_path = module_dir.join("modules").join(name).join("target").join("debug").join(format!("lib{}.so", name)); + } + + let release_modtime = match seconds_since_modification(&release_path) { + Ok(secs) => secs, + Err(e) => { return Ok(debug_path); }, + }; + + let debug_modtime = match seconds_since_modification(&debug_path) { + Ok(secs) => secs, + Err(e) => { return Ok(release_path); }, + }; + + if seconds_since_modification(&release_path)? > seconds_since_modification(&debug_path)? { + return Ok(debug_path); + } else { + return Ok(release_path); + }; + +} + +pub fn load_module(instance: &mut Instance, name: &str, path: Option) -> MizeResult<()> { let module_dir_str = instance.get("0/config/module_dir")?.value_string()?; let module_dir = Path::new(&module_dir_str); - let release_path = module_dir.join("modules").join(name).join("target").join("release").join(format!("libmize_module_{}.so", name)); - let debug_path = module_dir.join("modules").join(name).join("target").join("debug").join(format!("libmize_module_{}.so", name)); - - let module_path = match seconds_since_modification(&release_path) > seconds_since_modification(&debug_path) { - true => debug_path, - false => release_path, - }; + let module_path = get_correct_module_path(module_dir, name)?; let lib = unsafe { libloading::Library::new(module_path)? }; @@ -135,6 +147,7 @@ pub fn load_module(instance: &mut Instance, name: &str) -> MizeResult<()> { let mut module: Box = Box::new(EmptyModule {}); unsafe { func(&mut module) }; + println!("hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii load module"); let mut modules_inner = instance.modules.lock()?; diff --git a/webfiles.nix b/webfiles.nix new file mode 100644 index 0000000..5b075dc --- /dev/null +++ b/webfiles.nix @@ -0,0 +1,22 @@ +{ stdenv +, pkgs +, ... }: +let + +in + +stdenv.mkDerivation { + name = "mize-webfiles"; + dontUnpack = true; + + # so that /bin/sh does not get patched to a nix store path in victorinix-s + dontPatchShebangs = true; + + buildPhase = '' + mkdir -p $out + ''; + + nativeBuildInputs = [ + ]; +} +