diff options
| author | Brooks Rady <b.j.rady@gmail.com> | 2021-04-14 19:36:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-14 19:36:11 +0100 |
| commit | 126a4b1d33502b6e371cca4101dbb7a0c7fe28bc (patch) | |
| tree | 907c865bc81d907077bb0c2ce7bf7d81f4b08c92 /src | |
| parent | fix(compatibility): bash reverse search (#271) (diff) | |
| parent | fix(build): tweak the publishing process (diff) | |
| download | sl0ppij-126a4b1d33502b6e371cca4101dbb7a0c7fe28bc.tar.gz sl0ppij-126a4b1d33502b6e371cca4101dbb7a0c7fe28bc.tar.xz sl0ppij-126a4b1d33502b6e371cca4101dbb7a0c7fe28bc.zip | |
feat(build): overhaul build system
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli.rs | 4 | ||||
| -rw-r--r-- | src/client/layout.rs | 9 | ||||
| -rw-r--r-- | src/common/install.rs | 31 | ||||
| -rw-r--r-- | src/common/mod.rs | 17 | ||||
| -rw-r--r-- | src/main.rs | 46 |
5 files changed, 60 insertions, 47 deletions
@@ -20,6 +20,10 @@ pub struct CliArgs { #[structopt(long)] pub max_panes: Option<usize>, + /// Change where zellij looks for layouts and plugins + #[structopt(long)] + pub data_dir: Option<PathBuf>, + /// Path to a layout yaml file #[structopt(short, long)] pub layout: Option<PathBuf>, diff --git a/src/client/layout.rs b/src/client/layout.rs index 2524f894..e82f9045 100644 --- a/src/client/layout.rs +++ b/src/client/layout.rs @@ -1,6 +1,5 @@ -use directories_next::ProjectDirs; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::{fs::File, io::prelude::*}; use crate::panes::PositionAndSize; @@ -180,11 +179,9 @@ pub struct Layout { } impl Layout { - pub fn new(layout_path: PathBuf) -> Self { - let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); - let layout_dir = project_dirs.data_dir().join("layouts/"); + pub fn new(layout_path: &Path, data_dir: &Path) -> Self { + let layout_dir = data_dir.join("layouts/"); let mut layout_file = File::open(&layout_path) - .or_else(|_| File::open(&layout_path.with_extension("yaml"))) .or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml"))) .unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display())); diff --git a/src/common/install.rs b/src/common/install.rs index 8b070848..86fdd269 100644 --- a/src/common/install.rs +++ b/src/common/install.rs @@ -1,12 +1,41 @@ +use std::{fs, path::Path}; + +const VERSION: &str = env!("CARGO_PKG_VERSION"); + #[macro_export] macro_rules! asset_map { ($($src:literal => $dst:literal),+ $(,)?) => { { let mut assets = std::collections::HashMap::new(); $( - assets.insert($dst, include_bytes!(concat!("../", $src)).to_vec()); + assets.insert($dst, include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $src)).to_vec()); )+ assets } } } + +pub fn populate_data_dir(data_dir: &Path) { + // First run installation of default plugins & layouts + let mut assets = asset_map! { + "assets/layouts/default.yaml" => "layouts/default.yaml", + "assets/layouts/strider.yaml" => "layouts/strider.yaml", + }; + assets.extend(asset_map! { + "assets/plugins/status-bar.wasm" => "plugins/status-bar.wasm", + "assets/plugins/tab-bar.wasm" => "plugins/tab-bar.wasm", + "assets/plugins/strider.wasm" => "plugins/strider.wasm", + }); + assets.insert("VERSION", VERSION.as_bytes().to_vec()); + + let last_version = fs::read_to_string(data_dir.join("VERSION")).unwrap_or_default(); + let out_of_date = VERSION != last_version; + + for (path, bytes) in assets { + let path = data_dir.join(path); + fs::create_dir_all(path.parent().unwrap()).unwrap(); + if out_of_date || !path.exists() { + fs::write(path, bytes).expect("Failed to install default assets!"); + } + } +} diff --git a/src/common/mod.rs b/src/common/mod.rs index 88eb7214..860d12db 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -33,6 +33,7 @@ use errors::{ ScreenContext, }; use input::handler::input_loop; +use install::populate_data_dir; use os_input_output::OsApi; use pty_bus::{PtyBus, PtyInstruction}; use screen::{Screen, ScreenInstruction}; @@ -167,12 +168,22 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { opts.debug, ); + // Determine and initialize the data directory + let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); + let data_dir = opts + .data_dir + .unwrap_or_else(|| project_dirs.data_dir().to_path_buf()); + populate_data_dir(&data_dir); + // Don't use default layouts in tests, but do everywhere else #[cfg(not(test))] let default_layout = Some(PathBuf::from("default")); #[cfg(test)] let default_layout = None; - let maybe_layout = opts.layout.or(default_layout).map(Layout::new); + let maybe_layout = opts + .layout + .or(default_layout) + .map(|p| Layout::new(&p, &data_dir)); #[cfg(not(test))] std::panic::set_hook({ @@ -443,9 +454,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) { err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event))); match event { PluginInstruction::Load(pid_tx, path) => { - let project_dirs = - ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); - let plugin_dir = project_dirs.data_dir().join("plugins/"); + let plugin_dir = data_dir.join("plugins/"); let wasm_bytes = fs::read(&path) .or_else(|_| fs::read(&path.with_extension("wasm"))) .or_else(|_| fs::read(&plugin_dir.join(&path).with_extension("wasm"))) diff --git a/src/main.rs b/src/main.rs index d6cbb05d..ec249e8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,23 +1,10 @@ -#[cfg(test)] -mod tests; - mod cli; mod common; +#[cfg(test)] +mod tests; // TODO mod server; mod client; -use client::{boundaries, layout, panes, tab}; -use common::{ - command_is_executing, errors, os_input_output, pty_bus, screen, start, utils, wasm_vm, - ApiCommand, -}; -use directories_next::ProjectDirs; - -use std::os::unix::net::UnixStream; -use std::{fs, io::Write}; - -use structopt::StructOpt; - use crate::cli::CliArgs; use crate::command_is_executing::CommandIsExecuting; use crate::os_input_output::get_os_input; @@ -25,29 +12,16 @@ use crate::utils::{ consts::{ZELLIJ_IPC_PIPE, ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, logging::*, }; +use client::{boundaries, layout, panes, tab}; +use common::{ + command_is_executing, errors, os_input_output, pty_bus, screen, start, utils, wasm_vm, + ApiCommand, +}; +use std::io::Write; +use std::os::unix::net::UnixStream; +use structopt::StructOpt; pub fn main() { - // First run installation of default plugins & layouts - let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap(); - let data_dir = project_dirs.data_dir(); - let mut assets = asset_map! { - "assets/layouts/default.yaml" => "layouts/default.yaml", - "assets/layouts/strider.yaml" => "layouts/strider.yaml", - }; - assets.extend(asset_map! { - "assets/plugins/status-bar.wasm" => "plugins/status-bar.wasm", - "assets/plugins/tab-bar.wasm" => "plugins/tab-bar.wasm", - "assets/plugins/strider.wasm" => "plugins/strider.wasm", - }); - - for (path, bytes) in assets { - let path = data_dir.join(path); - fs::create_dir_all(path.parent().unwrap()).unwrap(); - if !path.exists() { - fs::write(path, bytes).expect("Failed to install default assets!"); - } - } - let opts = CliArgs::from_args(); if let Some(split_dir) = opts.split { match split_dir { |
