mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	env: try find library dir (like /usr[/local]/lib/nvim) and add it to &rtp
This commit is contained in:
		@@ -3,5 +3,6 @@
 | 
			
		||||
#include "${PROJECT_SOURCE_DIR}/src/nvim/vim.h"
 | 
			
		||||
char *default_vim_dir = "${CMAKE_INSTALL_FULL_DATAROOTDIR}/nvim";
 | 
			
		||||
char *default_vimruntime_dir = "";
 | 
			
		||||
char *default_lib_dir = "${CMAKE_INSTALL_FULL_LIBDIR}/nvim";
 | 
			
		||||
char_u *compiled_user = (char_u *)"${USERNAME}";
 | 
			
		||||
char_u *compiled_sys = (char_u *)"${HOSTNAME}";
 | 
			
		||||
 
 | 
			
		||||
@@ -833,6 +833,7 @@ enum {
 | 
			
		||||
#ifdef HAVE_PATHDEF
 | 
			
		||||
extern char *default_vim_dir;
 | 
			
		||||
extern char *default_vimruntime_dir;
 | 
			
		||||
extern char *default_lib_dir;
 | 
			
		||||
extern char_u *compiled_user;
 | 
			
		||||
extern char_u *compiled_sys;
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -498,6 +498,24 @@ static inline char *add_dir(char *dest, const char *const dir,
 | 
			
		||||
  return dest;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char *get_lib_dir(void)
 | 
			
		||||
{
 | 
			
		||||
  // TODO(bfredl): too fragile? Ideally default_lib_dir would be made empty
 | 
			
		||||
  // in an appimage build
 | 
			
		||||
  if (strlen(default_lib_dir) != 0
 | 
			
		||||
      && os_isdir((const char_u *)default_lib_dir)) {
 | 
			
		||||
    return xstrdup(default_lib_dir);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Find library path relative to the nvim binary: ../lib/nvim/
 | 
			
		||||
  char exe_name[MAXPATHL];
 | 
			
		||||
  vim_get_prefix_from_exepath(exe_name);
 | 
			
		||||
  if (append_path(exe_name, "lib" _PATHSEPSTR "nvim", MAXPATHL) == OK) {
 | 
			
		||||
    return xstrdup(exe_name);
 | 
			
		||||
  }
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Sets &runtimepath to default value.
 | 
			
		||||
///
 | 
			
		||||
/// Windows: Uses "…/nvim-data" for kXDGDataHome to avoid storing
 | 
			
		||||
@@ -508,6 +526,7 @@ static void set_runtimepath_default(void)
 | 
			
		||||
  char *const data_home = stdpaths_get_xdg_var(kXDGDataHome);
 | 
			
		||||
  char *const config_home = stdpaths_get_xdg_var(kXDGConfigHome);
 | 
			
		||||
  char *const vimruntime = vim_getenv("VIMRUNTIME");
 | 
			
		||||
  char *const libdir = get_lib_dir();
 | 
			
		||||
  char *const data_dirs = stdpaths_get_xdg_var(kXDGDataDirs);
 | 
			
		||||
  char *const config_dirs = stdpaths_get_xdg_var(kXDGConfigDirs);
 | 
			
		||||
#define SITE_SIZE (sizeof("site") - 1)
 | 
			
		||||
@@ -515,6 +534,7 @@ static void set_runtimepath_default(void)
 | 
			
		||||
  size_t data_len = 0;
 | 
			
		||||
  size_t config_len = 0;
 | 
			
		||||
  size_t vimruntime_len = 0;
 | 
			
		||||
  size_t libdir_len = 0;
 | 
			
		||||
  if (data_home != NULL) {
 | 
			
		||||
    data_len = strlen(data_home);
 | 
			
		||||
    if (data_len != 0) {
 | 
			
		||||
@@ -544,6 +564,12 @@ static void set_runtimepath_default(void)
 | 
			
		||||
      rtp_size += vimruntime_len + memcnt(vimruntime, ',', vimruntime_len) + 1;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (libdir != NULL) {
 | 
			
		||||
    libdir_len = strlen(libdir);
 | 
			
		||||
    if (libdir_len != 0) {
 | 
			
		||||
      rtp_size += libdir_len + memcnt(libdir, ',', libdir_len) + 1;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  rtp_size += compute_double_colon_len(data_dirs, NVIM_SIZE + 1 + SITE_SIZE + 1,
 | 
			
		||||
                                       AFTER_SIZE + 1);
 | 
			
		||||
  rtp_size += compute_double_colon_len(config_dirs, NVIM_SIZE + 1,
 | 
			
		||||
@@ -562,6 +588,7 @@ static void set_runtimepath_default(void)
 | 
			
		||||
                           true);
 | 
			
		||||
  rtp_cur = add_dir(rtp_cur, vimruntime, vimruntime_len, kXDGNone,
 | 
			
		||||
                    NULL, 0, NULL, 0);
 | 
			
		||||
  rtp_cur = add_dir(rtp_cur, libdir, libdir_len, kXDGNone, NULL, 0, NULL, 0);
 | 
			
		||||
  rtp_cur = add_colon_dirs(rtp_cur, data_dirs, "site", SITE_SIZE,
 | 
			
		||||
                           "after", AFTER_SIZE, false);
 | 
			
		||||
  rtp_cur = add_dir(rtp_cur, data_home, data_len, kXDGDataHome,
 | 
			
		||||
@@ -583,6 +610,7 @@ static void set_runtimepath_default(void)
 | 
			
		||||
  xfree(data_home);
 | 
			
		||||
  xfree(config_home);
 | 
			
		||||
  xfree(vimruntime);
 | 
			
		||||
  xfree(libdir);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#undef NVIM_SIZE
 | 
			
		||||
 
 | 
			
		||||
@@ -847,6 +847,20 @@ const void *vim_env_iter_rev(const char delim,
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/// @param[out] exe_name should be at least MAXPATHL in size
 | 
			
		||||
void vim_get_prefix_from_exepath(char *exe_name)
 | 
			
		||||
{
 | 
			
		||||
  // TODO(bfredl): param could have been written as "char exe_name[MAXPATHL]"
 | 
			
		||||
  // but c_grammar.lua does not recognize it (yet).
 | 
			
		||||
  xstrlcpy(exe_name, (char *)get_vim_var_str(VV_PROGPATH),
 | 
			
		||||
           MAXPATHL * sizeof(*exe_name));
 | 
			
		||||
  char *path_end = (char *)path_tail_with_sep((char_u *)exe_name);
 | 
			
		||||
  *path_end = '\0';  // remove the trailing "nvim.exe"
 | 
			
		||||
  path_end = (char *)path_tail((char_u *)exe_name);
 | 
			
		||||
  *path_end = '\0';  // remove the trailing "bin/"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Vim getenv() wrapper with special handling of $HOME, $VIM, $VIMRUNTIME,
 | 
			
		||||
/// allowing the user to override the Nvim runtime directory at runtime.
 | 
			
		||||
/// Result must be freed by the caller.
 | 
			
		||||
@@ -902,12 +916,7 @@ char *vim_getenv(const char *name)
 | 
			
		||||
    char exe_name[MAXPATHL];
 | 
			
		||||
    // Find runtime path relative to the nvim binary: ../share/nvim/runtime
 | 
			
		||||
    if (vim_path == NULL) {
 | 
			
		||||
      xstrlcpy(exe_name, (char *)get_vim_var_str(VV_PROGPATH),
 | 
			
		||||
               sizeof(exe_name));
 | 
			
		||||
      char *path_end = (char *)path_tail_with_sep((char_u *)exe_name);
 | 
			
		||||
      *path_end = '\0';  // remove the trailing "nvim.exe"
 | 
			
		||||
      path_end = (char *)path_tail((char_u *)exe_name);
 | 
			
		||||
      *path_end = '\0';  // remove the trailing "bin/"
 | 
			
		||||
      vim_get_prefix_from_exepath(exe_name);
 | 
			
		||||
      if (append_path(
 | 
			
		||||
          exe_name,
 | 
			
		||||
          "share" _PATHSEPSTR "nvim" _PATHSEPSTR "runtime" _PATHSEPSTR,
 | 
			
		||||
 
 | 
			
		||||
@@ -293,6 +293,12 @@ describe('XDG-based defaults', function()
 | 
			
		||||
  -- TODO(jkeyes): tests below fail on win32 because of path separator.
 | 
			
		||||
  if helpers.pending_win32(pending) then return end
 | 
			
		||||
 | 
			
		||||
  local function vimruntime_and_libdir()
 | 
			
		||||
    local vimruntime = eval('$VIMRUNTIME')
 | 
			
		||||
    local libdir = string.gsub(vimruntime, "share/nvim/runtime$", "lib/nvim")
 | 
			
		||||
    return vimruntime, libdir
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe('with too long XDG variables', function()
 | 
			
		||||
    before_each(function()
 | 
			
		||||
      clear({env={
 | 
			
		||||
@@ -308,6 +314,8 @@ describe('XDG-based defaults', function()
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('are correctly set', function()
 | 
			
		||||
      local vimruntime, libdir = vimruntime_and_libdir()
 | 
			
		||||
 | 
			
		||||
      eq((('/x'):rep(4096) .. '/nvim'
 | 
			
		||||
          .. ',' .. ('/a'):rep(2048) .. '/nvim'
 | 
			
		||||
          .. ',' .. ('/b'):rep(2048) .. '/nvim'
 | 
			
		||||
@@ -316,7 +324,8 @@ describe('XDG-based defaults', function()
 | 
			
		||||
          .. ',' .. ('/A'):rep(2048) .. '/nvim/site'
 | 
			
		||||
          .. ',' .. ('/B'):rep(2048) .. '/nvim/site'
 | 
			
		||||
          .. (',' .. '/C/nvim/site'):rep(512)
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. (',' .. '/C/nvim/site/after'):rep(512)
 | 
			
		||||
          .. ',' .. ('/B'):rep(2048) .. '/nvim/site/after'
 | 
			
		||||
          .. ',' .. ('/A'):rep(2048) .. '/nvim/site/after'
 | 
			
		||||
@@ -339,7 +348,8 @@ describe('XDG-based defaults', function()
 | 
			
		||||
          .. ',' .. ('/A'):rep(2048) .. '/nvim/site'
 | 
			
		||||
          .. ',' .. ('/B'):rep(2048) .. '/nvim/site'
 | 
			
		||||
          .. (',' .. '/C/nvim/site'):rep(512)
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. (',' .. '/C/nvim/site/after'):rep(512)
 | 
			
		||||
          .. ',' .. ('/B'):rep(2048) .. '/nvim/site/after'
 | 
			
		||||
          .. ',' .. ('/A'):rep(2048) .. '/nvim/site/after'
 | 
			
		||||
@@ -368,11 +378,13 @@ describe('XDG-based defaults', function()
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('are not expanded', function()
 | 
			
		||||
      local vimruntime, libdir = vimruntime_and_libdir()
 | 
			
		||||
      eq(('$XDG_DATA_HOME/nvim'
 | 
			
		||||
          .. ',$XDG_DATA_DIRS/nvim'
 | 
			
		||||
          .. ',$XDG_CONFIG_HOME/nvim/site'
 | 
			
		||||
          .. ',$XDG_CONFIG_DIRS/nvim/site'
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. ',$XDG_CONFIG_DIRS/nvim/site/after'
 | 
			
		||||
          .. ',$XDG_CONFIG_HOME/nvim/site/after'
 | 
			
		||||
          .. ',$XDG_DATA_DIRS/nvim/after'
 | 
			
		||||
@@ -387,7 +399,8 @@ describe('XDG-based defaults', function()
 | 
			
		||||
          .. ',$XDG_DATA_DIRS/nvim'
 | 
			
		||||
          .. ',$XDG_CONFIG_HOME/nvim/site'
 | 
			
		||||
          .. ',$XDG_CONFIG_DIRS/nvim/site'
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. ',$XDG_CONFIG_DIRS/nvim/site/after'
 | 
			
		||||
          .. ',$XDG_CONFIG_HOME/nvim/site/after'
 | 
			
		||||
          .. ',$XDG_DATA_DIRS/nvim/after'
 | 
			
		||||
@@ -402,7 +415,8 @@ describe('XDG-based defaults', function()
 | 
			
		||||
          .. ',$XDG_DATA_DIRS/nvim'
 | 
			
		||||
          .. ',$XDG_CONFIG_HOME/nvim/site'
 | 
			
		||||
          .. ',$XDG_CONFIG_DIRS/nvim/site'
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. ',$XDG_CONFIG_DIRS/nvim/site/after'
 | 
			
		||||
          .. ',$XDG_CONFIG_HOME/nvim/site/after'
 | 
			
		||||
          .. ',$XDG_DATA_DIRS/nvim/after'
 | 
			
		||||
@@ -426,13 +440,15 @@ describe('XDG-based defaults', function()
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('are escaped properly', function()
 | 
			
		||||
      local vimruntime, libdir = vimruntime_and_libdir()
 | 
			
		||||
      eq(('\\, \\, \\,/nvim'
 | 
			
		||||
          .. ',\\,-\\,-\\,/nvim'
 | 
			
		||||
          .. ',-\\,-\\,-/nvim'
 | 
			
		||||
          .. ',\\,=\\,=\\,/nvim/site'
 | 
			
		||||
          .. ',\\,≡\\,≡\\,/nvim/site'
 | 
			
		||||
          .. ',≡\\,≡\\,≡/nvim/site'
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. ',≡\\,≡\\,≡/nvim/site/after'
 | 
			
		||||
          .. ',\\,≡\\,≡\\,/nvim/site/after'
 | 
			
		||||
          .. ',\\,=\\,=\\,/nvim/site/after'
 | 
			
		||||
@@ -451,7 +467,8 @@ describe('XDG-based defaults', function()
 | 
			
		||||
          .. ',\\,=\\,=\\,/nvim/site'
 | 
			
		||||
          .. ',\\,≡\\,≡\\,/nvim/site'
 | 
			
		||||
          .. ',≡\\,≡\\,≡/nvim/site'
 | 
			
		||||
          .. ',' .. eval('$VIMRUNTIME')
 | 
			
		||||
          .. ',' .. vimruntime
 | 
			
		||||
          .. ',' .. libdir
 | 
			
		||||
          .. ',≡\\,≡\\,≡/nvim/site/after'
 | 
			
		||||
          .. ',\\,≡\\,≡\\,/nvim/site/after'
 | 
			
		||||
          .. ',\\,=\\,=\\,/nvim/site/after'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user