From 0f77f543e5a7a6be0eabd2d4b72591cdafc7ec71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 10 May 2021 01:02:53 +0900 Subject: [PATCH] Determine runtime dir based on executable location or env override. --- helix-core/src/lib.rs | 12 ++++++++++++ helix-core/src/syntax.rs | 3 ++- shell.nix | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index dda9863b5..e68dc186b 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -44,6 +44,18 @@ pub(crate) fn find_first_non_whitespace_char(text: RopeSlice, line_num: usize) - None } +pub fn runtime_dir() -> std::path::PathBuf { + // runtime env var || dir where binary is located + std::env::var("HELIX_RUNTIME") + .map(|path| path.into()) + .unwrap_or_else(|_| { + std::env::current_exe() + .ok() + .and_then(|path| path.parent().map(|path| path.to_path_buf())) + .unwrap() + }) +} + pub fn config_dir() -> std::path::PathBuf { // TODO: allow env var override let xdg_dirs = diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index dbeed45cc..aaf22edcc 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -63,7 +63,8 @@ fn read_query(language: &str, filename: &str) -> String { static INHERITS_REGEX: Lazy = Lazy::new(|| Regex::new(r";+\s*inherits\s*:?\s*([a-z_,()]+)\s*").unwrap()); - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let root = crate::runtime_dir(); + // let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let path = root .join("../runtime/queries") diff --git a/shell.nix b/shell.nix index 82af46d40..0a26b6ad6 100644 --- a/shell.nix +++ b/shell.nix @@ -11,5 +11,7 @@ pkgs.mkShell { RUST_BACKTRACE = "1"; # https://github.com/rust-lang/rust/issues/55979 LD_LIBRARY_PATH="${stdenv.cc.cc.lib}/lib64:$LD_LIBRARY_PATH"; + + HELIX_RUNTIME=./runtime; }