mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 17:31:14 -03:00
Remove embed-data feature flag
This mode still has some problems (see the next commit) but having it behind a feature flag doesn't serve us. Let's commit to the parts we want to keep and drop anything that we don't want. To reduce diff noise, use "if false" in the code paths used by man pages; a following commit will use them.
This commit is contained in:
@@ -86,7 +86,7 @@ bitflags.workspace = true
|
|||||||
cfg-if.workspace = true
|
cfg-if.workspace = true
|
||||||
errno.workspace = true
|
errno.workspace = true
|
||||||
fish-build-helper.workspace = true
|
fish-build-helper.workspace = true
|
||||||
fish-build-man-pages = { workspace = true, optional = true }
|
fish-build-man-pages.workspace = true
|
||||||
fish-gettext-extraction = { workspace = true, optional = true }
|
fish-gettext-extraction = { workspace = true, optional = true }
|
||||||
fish-gettext-maps = { workspace = true, optional = true }
|
fish-gettext-maps = { workspace = true, optional = true }
|
||||||
fish-printf.workspace = true
|
fish-printf.workspace = true
|
||||||
@@ -107,14 +107,14 @@ widestring.workspace = true
|
|||||||
portable-atomic.workspace = true
|
portable-atomic.workspace = true
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
rust-embed = { workspace = true, optional = true, features = [
|
rust-embed = { workspace = true, features = [
|
||||||
"deterministic-timestamps",
|
"deterministic-timestamps",
|
||||||
"debug-embed",
|
"debug-embed",
|
||||||
"include-exclude",
|
"include-exclude",
|
||||||
"interpolate-folder-path",
|
"interpolate-folder-path",
|
||||||
] }
|
] }
|
||||||
[target.'cfg(not(windows))'.dependencies]
|
[target.'cfg(not(windows))'.dependencies]
|
||||||
rust-embed = { workspace = true, optional = true, features = [
|
rust-embed = { workspace = true, features = [
|
||||||
"deterministic-timestamps",
|
"deterministic-timestamps",
|
||||||
"include-exclude",
|
"include-exclude",
|
||||||
"interpolate-folder-path",
|
"interpolate-folder-path",
|
||||||
@@ -150,9 +150,8 @@ name = "fish_key_reader"
|
|||||||
path = "src/bin/fish_key_reader.rs"
|
path = "src/bin/fish_key_reader.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["embed-data", "localize-messages"]
|
default = ["localize-messages"]
|
||||||
benchmark = []
|
benchmark = []
|
||||||
embed-data = ["dep:rust-embed", "dep:fish-build-man-pages"]
|
|
||||||
# Enable gettext localization at runtime. Requires the `msgfmt` tool to generate catalog data at
|
# Enable gettext localization at runtime. Requires the `msgfmt` tool to generate catalog data at
|
||||||
# build time.
|
# build time.
|
||||||
localize-messages = ["dep:phf", "dep:fish-gettext-maps"]
|
localize-messages = ["dep:phf", "dep:fish-gettext-maps"]
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ You can also install Sphinx another way and drop the ``uv run --no-managed-pytho
|
|||||||
|
|
||||||
This will place standalone binaries in ``~/.cargo/bin/``, but you can move them wherever you want.
|
This will place standalone binaries in ``~/.cargo/bin/``, but you can move them wherever you want.
|
||||||
|
|
||||||
To disable translations, disable the ``localize-messages`` feature by passing ``--no-default-features --features=embed-data`` to cargo.
|
To disable translations, disable the ``localize-messages`` feature by passing ``--no-default-features`` to cargo.
|
||||||
|
|
||||||
You can also link this build statically (but not against glibc) and move it to other computers.
|
You can also link this build statically (but not against glibc) and move it to other computers.
|
||||||
|
|
||||||
|
|||||||
23
build.rs
23
build.rs
@@ -42,7 +42,6 @@ fn main() {
|
|||||||
|
|
||||||
// These are necessary if built with embedded functions,
|
// These are necessary if built with embedded functions,
|
||||||
// but only in release builds (because rust-embed in debug builds reads from the filesystem).
|
// but only in release builds (because rust-embed in debug builds reads from the filesystem).
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
#[cfg(any(windows, not(debug_assertions)))]
|
#[cfg(any(windows, not(debug_assertions)))]
|
||||||
rsconf::rebuild_if_path_changed("share");
|
rsconf::rebuild_if_path_changed("share");
|
||||||
|
|
||||||
@@ -215,32 +214,18 @@ fn join_if_relative(parent_if_relative: &Path, path: String) -> PathBuf {
|
|||||||
overridable_path("SYSCONFDIR", |env_sysconfdir| {
|
overridable_path("SYSCONFDIR", |env_sysconfdir| {
|
||||||
Some(join_if_relative(
|
Some(join_if_relative(
|
||||||
&prefix,
|
&prefix,
|
||||||
env_sysconfdir.unwrap_or(
|
env_sysconfdir.unwrap_or("/etc/".to_string()),
|
||||||
// Embedded builds use "/etc," not "$PREFIX/etc".
|
|
||||||
if cfg!(feature = "embed-data") {
|
|
||||||
"/etc/"
|
|
||||||
} else {
|
|
||||||
"etc/"
|
|
||||||
}
|
|
||||||
.to_string(),
|
|
||||||
),
|
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|
||||||
let default_ok = !cfg!(feature = "embed-data");
|
|
||||||
let datadir = overridable_path("DATADIR", |env_datadir| {
|
let datadir = overridable_path("DATADIR", |env_datadir| {
|
||||||
let default = default_ok.then_some("share/".to_string());
|
env_datadir.map(|p| join_if_relative(&prefix, p))
|
||||||
env_datadir
|
|
||||||
.or(default)
|
|
||||||
.map(|p| join_if_relative(&prefix, p))
|
|
||||||
});
|
});
|
||||||
overridable_path("BINDIR", |env_bindir| {
|
overridable_path("BINDIR", |env_bindir| {
|
||||||
let default = default_ok.then_some("bin/".to_string());
|
env_bindir.map(|p| join_if_relative(&prefix, p))
|
||||||
env_bindir.or(default).map(|p| join_if_relative(&prefix, p))
|
|
||||||
});
|
});
|
||||||
overridable_path("DOCDIR", |env_docdir| {
|
overridable_path("DOCDIR", |env_docdir| {
|
||||||
let default = default_ok.then_some("doc/fish".to_string());
|
env_docdir.map(|p| {
|
||||||
env_docdir.or(default).map(|p| {
|
|
||||||
join_if_relative(
|
join_if_relative(
|
||||||
&datadir
|
&datadir
|
||||||
.expect("Setting DOCDIR without setting DATADIR is not currently supported"),
|
.expect("Setting DOCDIR without setting DATADIR is not currently supported"),
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ find_package(Rust REQUIRED)
|
|||||||
|
|
||||||
set(FISH_RUST_BUILD_DIR "${CMAKE_BINARY_DIR}/cargo/build")
|
set(FISH_RUST_BUILD_DIR "${CMAKE_BINARY_DIR}/cargo/build")
|
||||||
|
|
||||||
list(APPEND FISH_CARGO_FEATURES_LIST "embed-data")
|
|
||||||
|
|
||||||
if(DEFINED ASAN)
|
if(DEFINED ASAN)
|
||||||
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
||||||
list(APPEND FISH_CARGO_FEATURES_LIST "asan")
|
list(APPEND FISH_CARGO_FEATURES_LIST "asan")
|
||||||
|
|||||||
@@ -22,16 +22,6 @@ if not status --is-interactive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# N.B. can't load __fish_is_standalone.fish this early in non-embedded builds, so reimplement it.
|
|
||||||
# We still want it as a separate file for --no-config.
|
|
||||||
set -l is_standalone (
|
|
||||||
if status get-file config.fish &>/dev/null
|
|
||||||
echo true
|
|
||||||
else
|
|
||||||
echo false
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set default search paths for completions and shellscript functions
|
# Set default search paths for completions and shellscript functions
|
||||||
# unless they already exist
|
# unless they already exist
|
||||||
@@ -42,12 +32,7 @@ set -l is_standalone (
|
|||||||
set -l __extra_completionsdir
|
set -l __extra_completionsdir
|
||||||
set -l __extra_functionsdir
|
set -l __extra_functionsdir
|
||||||
set -l __extra_confdir
|
set -l __extra_confdir
|
||||||
# N.B. can't load __fish_data_with_file this early in non-embedded builds, so reimplement it.
|
__fish_data_with_file __fish_build_paths.fish source
|
||||||
if $is_standalone
|
|
||||||
status get-file __fish_build_paths.fish | source
|
|
||||||
else if path is -f -- $__fish_data_dir/__fish_build_paths.fish
|
|
||||||
source $__fish_data_dir/__fish_build_paths.fish
|
|
||||||
end
|
|
||||||
|
|
||||||
# Compute the directories for vendor configuration. We want to include
|
# Compute the directories for vendor configuration. We want to include
|
||||||
# all of XDG_DATA_DIRS, as well as the __extra_* dirs defined above.
|
# all of XDG_DATA_DIRS, as well as the __extra_* dirs defined above.
|
||||||
@@ -55,8 +40,6 @@ set -l xdg_data_dirs
|
|||||||
if set -q XDG_DATA_DIRS
|
if set -q XDG_DATA_DIRS
|
||||||
set --path xdg_data_dirs $XDG_DATA_DIRS
|
set --path xdg_data_dirs $XDG_DATA_DIRS
|
||||||
set xdg_data_dirs (string replace -r '([^/])/$' '$1' -- $xdg_data_dirs)/fish
|
set xdg_data_dirs (string replace -r '([^/])/$' '$1' -- $xdg_data_dirs)/fish
|
||||||
else if not $is_standalone
|
|
||||||
set xdg_data_dirs $__fish_data_dir
|
|
||||||
end
|
end
|
||||||
|
|
||||||
set -g __fish_vendor_completionsdirs
|
set -g __fish_vendor_completionsdirs
|
||||||
@@ -85,21 +68,11 @@ end
|
|||||||
|
|
||||||
if not set -q fish_function_path
|
if not set -q fish_function_path
|
||||||
set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $__fish_vendor_functionsdirs
|
set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $__fish_vendor_functionsdirs
|
||||||
if not $is_standalone
|
|
||||||
set -a fish_function_path $__fish_data_dir/functions
|
|
||||||
end
|
|
||||||
else if not $is_standalone; and not contains -- $__fish_data_dir/functions $fish_function_path
|
|
||||||
set -a fish_function_path $__fish_data_dir/functions
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not set -q fish_complete_path
|
if not set -q fish_complete_path
|
||||||
set fish_complete_path $__fish_config_dir/completions $__fish_sysconf_dir/completions $__fish_vendor_completionsdirs
|
set fish_complete_path $__fish_config_dir/completions $__fish_sysconf_dir/completions $__fish_vendor_completionsdirs
|
||||||
if not $is_standalone
|
|
||||||
set -a fish_complete_path $__fish_data_dir/completions
|
|
||||||
end
|
|
||||||
set -a fish_complete_path $__fish_cache_dir/generated_completions
|
set -a fish_complete_path $__fish_cache_dir/generated_completions
|
||||||
else if not $is_standalone; and not contains -- $__fish_data_dir/completions $fish_complete_path
|
|
||||||
set -a fish_complete_path $__fish_data_dir/completions
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
|
# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
# localization: skip(private)
|
|
||||||
function __fish_data_list_files
|
|
||||||
set -l dir $argv[1]
|
|
||||||
if not __fish_is_standalone
|
|
||||||
# Construct a directory prefix without trailing slash.
|
|
||||||
if test -n "$dir"
|
|
||||||
set dir $__fish_data_dir/$dir
|
|
||||||
else
|
|
||||||
set dir $__fish_data_dir
|
|
||||||
end
|
|
||||||
set -l files $dir/**
|
|
||||||
string replace -- $__fish_data_dir/ '' $files
|
|
||||||
else
|
|
||||||
status list-files $dir
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -5,7 +5,7 @@ function __fish_data_with_directory
|
|||||||
set -l cmd $argv[3..]
|
set -l cmd $argv[3..]
|
||||||
set -l temp
|
set -l temp
|
||||||
set -l directory_ref
|
set -l directory_ref
|
||||||
if not __fish_is_standalone
|
if false
|
||||||
set directory_ref $__fish_data_dir/$relative_directory
|
set directory_ref $__fish_data_dir/$relative_directory
|
||||||
else
|
else
|
||||||
set temp (__fish_mktemp_relative -d fish-data)
|
set temp (__fish_mktemp_relative -d fish-data)
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
function __fish_data_with_file
|
function __fish_data_with_file
|
||||||
set -l path $argv[1]
|
set -l path $argv[1]
|
||||||
set -l cmd $argv[2..]
|
set -l cmd $argv[2..]
|
||||||
if string match -rq -- ^/ $path; or begin
|
if string match -rq -- ^/ $path
|
||||||
not __fish_is_standalone
|
|
||||||
and set path $__fish_data_dir/$path
|
|
||||||
end
|
|
||||||
$cmd $path
|
$cmd $path
|
||||||
else
|
else
|
||||||
status get-file $path | $cmd
|
status get-file $path | $cmd
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
# localization: skip(private)
|
|
||||||
set -l is_standalone (
|
|
||||||
if status get-file config.fish &>/dev/null
|
|
||||||
echo true
|
|
||||||
else
|
|
||||||
echo false
|
|
||||||
end
|
|
||||||
)
|
|
||||||
function __fish_is_standalone -V is_standalone
|
|
||||||
$is_standalone
|
|
||||||
end
|
|
||||||
@@ -286,11 +286,7 @@ fish_pager_color_secondary_description
|
|||||||
set -l theme_path (__fish_config_list_themes $argv[1])[1]
|
set -l theme_path (__fish_config_list_themes $argv[1])[1]
|
||||||
if not set -q theme_path[1]
|
if not set -q theme_path[1]
|
||||||
echo >&2 "No such theme: $argv[1]"
|
echo >&2 "No such theme: $argv[1]"
|
||||||
echo >&2 Searched (__fish_config_theme_dirs) (
|
echo >&2 Searched (__fish_config_theme_dir) "and `status list-files tools/web_config/themes`"
|
||||||
if __fish_is_standalone
|
|
||||||
echo "and `status list-files tools/web_config/themes`"
|
|
||||||
end
|
|
||||||
)
|
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -332,10 +328,7 @@ fish_pager_color_secondary_description
|
|||||||
end
|
end
|
||||||
|
|
||||||
function __fish_config_list_prompts
|
function __fish_config_list_prompts
|
||||||
set -lx dirs
|
set -lx dir
|
||||||
if not __fish_is_standalone
|
|
||||||
set dirs $__fish_data_dir/tools/web_config/sample_prompts
|
|
||||||
end
|
|
||||||
set -l prompt_paths (__fish_config_matching tools/web_config/sample_prompts .fish $argv)
|
set -l prompt_paths (__fish_config_matching tools/web_config/sample_prompts .fish $argv)
|
||||||
if [ (count $argv) = 1 ] && set -q prompt_paths[2]
|
if [ (count $argv) = 1 ] && set -q prompt_paths[2]
|
||||||
echo >&2 "fish_config: internal error: multiple prompts matching '$argv' ??"
|
echo >&2 "fish_config: internal error: multiple prompts matching '$argv' ??"
|
||||||
@@ -345,15 +338,12 @@ function __fish_config_list_prompts
|
|||||||
end
|
end
|
||||||
|
|
||||||
function __fish_config_list_themes
|
function __fish_config_list_themes
|
||||||
set -lx dirs (__fish_config_theme_dirs)
|
set -lx dir (__fish_config_theme_dir)
|
||||||
__fish_config_matching tools/web_config/themes .theme $argv
|
__fish_config_matching tools/web_config/themes .theme $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_config_theme_dirs
|
function __fish_config_theme_dir
|
||||||
printf %s\n $__fish_config_dir/themes
|
echo $__fish_config_dir/themes
|
||||||
if not __fish_is_standalone
|
|
||||||
printf %s\n $__fish_data_dir/tools/web_config/themes
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_config_list_theme_names
|
function __fish_config_list_theme_names
|
||||||
@@ -368,16 +358,14 @@ function __fish_config_matching
|
|||||||
set -e argv[1..2]
|
set -e argv[1..2]
|
||||||
set -l paths
|
set -l paths
|
||||||
if not set -q argv[1]
|
if not set -q argv[1]
|
||||||
set paths $dirs/*$suffix
|
set paths $dir/*$suffix
|
||||||
else
|
else
|
||||||
set paths (path filter $dirs/$argv$suffix)
|
set paths (path filter $dir/$argv$suffix)
|
||||||
end
|
end
|
||||||
if __fish_is_standalone
|
if not set -q argv[1]
|
||||||
if not set -q argv[1]
|
set -a paths (status list-files $prefix)
|
||||||
set -a paths (status list-files $prefix)
|
else
|
||||||
else
|
set -a paths (status list-files "$prefix/"$argv$suffix)
|
||||||
set -a paths (status list-files "$prefix/"$argv$suffix)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
string join \n $paths
|
string join \n $paths
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,15 +21,9 @@ function fish_delta
|
|||||||
|
|
||||||
# TODO: Do we want to keep the vendor dirs in here?
|
# TODO: Do we want to keep the vendor dirs in here?
|
||||||
set -l default_function_path
|
set -l default_function_path
|
||||||
if not __fish_is_standalone
|
|
||||||
set default_function_path $__fish_data_dir/functions
|
|
||||||
end
|
|
||||||
test "$vendormode" = default && set -a default_function_path $__fish_vendor_functionsdirs
|
test "$vendormode" = default && set -a default_function_path $__fish_vendor_functionsdirs
|
||||||
|
|
||||||
set -l default_complete_path
|
set -l default_complete_path
|
||||||
if not __fish_is_standalone
|
|
||||||
set default_complete_path $__fish_data_dir/completions
|
|
||||||
end
|
|
||||||
test "$vendormode" = default && set -a default_complete_path $__fish_vendor_completionsdirs
|
test "$vendormode" = default && set -a default_complete_path $__fish_vendor_completionsdirs
|
||||||
|
|
||||||
set -l default_conf_path
|
set -l default_conf_path
|
||||||
@@ -117,7 +111,7 @@ function fish_delta
|
|||||||
for file in $files
|
for file in $files
|
||||||
set -l bn (path basename -- $file)
|
set -l bn (path basename -- $file)
|
||||||
set -l default_exists false
|
set -l default_exists false
|
||||||
if set -q dir[1]; and contains $dir/$bn (__fish_data_list_files $dir)
|
if set -q dir[1]; and contains $dir/$bn (status list-files $dir)
|
||||||
set default_exists true
|
set default_exists true
|
||||||
else if test $all_changed = 0
|
else if test $all_changed = 0
|
||||||
set -ql _flag_n
|
set -ql _flag_n
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function man
|
|||||||
end
|
end
|
||||||
|
|
||||||
set -l manpath
|
set -l manpath
|
||||||
if not __fish_is_standalone
|
if false
|
||||||
and set -l fish_manpath (path filter -d $__fish_data_dir/man)
|
and set -l fish_manpath (path filter -d $__fish_data_dir/man)
|
||||||
# Prepend fish's man directory if available.
|
# Prepend fish's man directory if available.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//! The classes responsible for autoloading functions and completions.
|
//! The classes responsible for autoloading functions and completions.
|
||||||
|
|
||||||
use crate::FLOGF;
|
use crate::FLOGF;
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
use crate::common::wcs2bytes;
|
use crate::common::wcs2bytes;
|
||||||
use crate::common::{ScopeGuard, escape};
|
use crate::common::{ScopeGuard, escape};
|
||||||
use crate::env::Environment;
|
use crate::env::Environment;
|
||||||
@@ -10,9 +9,7 @@
|
|||||||
use crate::wchar::{L, WString, wstr};
|
use crate::wchar::{L, WString, wstr};
|
||||||
use crate::wchar_ext::WExt;
|
use crate::wchar_ext::WExt;
|
||||||
use crate::wutil::{FileId, INVALID_FILE_ID, file_id_for_path};
|
use crate::wutil::{FileId, INVALID_FILE_ID, file_id_for_path};
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use lru::LruCache;
|
use lru::LruCache;
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
@@ -40,23 +37,14 @@ pub struct Autoload {
|
|||||||
cache: AutoloadFileCache,
|
cache: AutoloadFileCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "share"]
|
#[folder = "share"]
|
||||||
#[exclude = "__fish_build_paths.fish.in"]
|
#[exclude = "__fish_build_paths.fish.in"]
|
||||||
pub struct Asset;
|
pub struct Asset;
|
||||||
|
|
||||||
cfg_if!(
|
pub fn has_asset(cmd: &str) -> bool {
|
||||||
if #[cfg(feature = "embed-data")] {
|
Asset::get(cmd).is_some()
|
||||||
pub fn has_asset(cmd: &str) -> bool {
|
}
|
||||||
Asset::get(cmd).is_some()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pub fn has_asset(_cmd: &str) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
enum AssetDir {
|
enum AssetDir {
|
||||||
@@ -65,7 +53,6 @@ enum AssetDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum AutoloadPath {
|
pub enum AutoloadPath {
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
Embedded(String),
|
Embedded(String),
|
||||||
Path(WString),
|
Path(WString),
|
||||||
}
|
}
|
||||||
@@ -114,7 +101,6 @@ pub fn resolve_command(&mut self, cmd: &wstr, env: &dyn Environment) -> Option<A
|
|||||||
) {
|
) {
|
||||||
AutoloadResult::Path(path) => {
|
AutoloadResult::Path(path) => {
|
||||||
match &path {
|
match &path {
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
AutoloadPath::Embedded(_) => {
|
AutoloadPath::Embedded(_) => {
|
||||||
FLOGF!(autoload, "Embedded: %s", cmd);
|
FLOGF!(autoload, "Embedded: %s", cmd);
|
||||||
}
|
}
|
||||||
@@ -148,7 +134,6 @@ pub fn perform_autoload(path: &AutoloadPath, parser: &Parser) {
|
|||||||
let script_source = L!("source ").to_owned() + &escape(p)[..];
|
let script_source = L!("source ").to_owned() + &escape(p)[..];
|
||||||
parser.eval(&script_source, &IoChain::new());
|
parser.eval(&script_source, &IoChain::new());
|
||||||
}
|
}
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
AutoloadPath::Embedded(name) => {
|
AutoloadPath::Embedded(name) => {
|
||||||
use crate::common::bytes2wcstring;
|
use crate::common::bytes2wcstring;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -236,7 +221,6 @@ fn resolve_command_impl(&mut self, cmd: &wstr, paths: &[WString]) -> AutoloadRes
|
|||||||
|
|
||||||
let file_id = match &file {
|
let file_id = match &file {
|
||||||
AutoloadableFileInfo::FileInfo(file) => &file.file_id,
|
AutoloadableFileInfo::FileInfo(file) => &file.file_id,
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
AutoloadableFileInfo::EmbeddedPath(_) => &INVALID_FILE_ID,
|
AutoloadableFileInfo::EmbeddedPath(_) => &INVALID_FILE_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -254,7 +238,6 @@ fn resolve_command_impl(&mut self, cmd: &wstr, paths: &[WString]) -> AutoloadRes
|
|||||||
.insert(cmd.to_owned(), file_id.clone());
|
.insert(cmd.to_owned(), file_id.clone());
|
||||||
AutoloadResult::Path(match file {
|
AutoloadResult::Path(match file {
|
||||||
AutoloadableFileInfo::FileInfo(path) => AutoloadPath::Path(path.path),
|
AutoloadableFileInfo::FileInfo(path) => AutoloadPath::Path(path.path),
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
AutoloadableFileInfo::EmbeddedPath(path) => AutoloadPath::Embedded(path),
|
AutoloadableFileInfo::EmbeddedPath(path) => AutoloadPath::Embedded(path),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -277,7 +260,6 @@ enum AutoloadableFileInfo {
|
|||||||
/// An on-disk file.
|
/// An on-disk file.
|
||||||
FileInfo(FileInfo),
|
FileInfo(FileInfo),
|
||||||
/// An embedded file.
|
/// An embedded file.
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
EmbeddedPath(String),
|
EmbeddedPath(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,24 +322,15 @@ fn check(
|
|||||||
cmd: &wstr,
|
cmd: &wstr,
|
||||||
allow_stale: bool,
|
allow_stale: bool,
|
||||||
) -> Option<AutoloadableFileInfo> {
|
) -> Option<AutoloadableFileInfo> {
|
||||||
let asset_dir =
|
let asset_dir = match env_var_name {
|
||||||
cfg!(feature = "embed-data")
|
s if s == "fish_function_path" => Some(AssetDir::Functions),
|
||||||
.then_some(())
|
s if s == "fish_complete_path" => Some(AssetDir::Completions),
|
||||||
.and_then(|()| match env_var_name {
|
_ => None,
|
||||||
s if s == "fish_function_path" => Some(AssetDir::Functions),
|
};
|
||||||
s if s == "fish_complete_path" => Some(AssetDir::Completions),
|
|
||||||
_ => None,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check hits.
|
// Check hits.
|
||||||
if let Some(value) = self.known_files.get(cmd) {
|
if let Some(value) = self.known_files.get(cmd) {
|
||||||
cfg_if!(
|
let embedded = matches!(value.file, AutoloadableFileInfo::EmbeddedPath(_));
|
||||||
if #[cfg(feature = "embed-data")] {
|
|
||||||
let embedded = matches!(value.file, AutoloadableFileInfo::EmbeddedPath(_));
|
|
||||||
} else {
|
|
||||||
let embedded = false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if allow_stale
|
if allow_stale
|
||||||
|| embedded
|
|| embedded
|
||||||
|| Self::is_fresh(value.last_checked, Self::current_timestamp())
|
|| Self::is_fresh(value.last_checked, Self::current_timestamp())
|
||||||
@@ -465,11 +438,6 @@ fn locate_file(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "embed-data"))]
|
|
||||||
fn locate_asset(&self, _cmd: &wstr, _asset_dir: AssetDir) -> Option<AutoloadableFileInfo> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
fn locate_asset(&self, cmd: &wstr, asset_dir: AssetDir) -> Option<AutoloadableFileInfo> {
|
fn locate_asset(&self, cmd: &wstr, asset_dir: AssetDir) -> Option<AutoloadableFileInfo> {
|
||||||
// HACK: In cargo tests, this used to never load functions
|
// HACK: In cargo tests, this used to never load functions
|
||||||
// It will hang for reasons unrelated to this.
|
// It will hang for reasons unrelated to this.
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use fish::{
|
use fish::{
|
||||||
ast,
|
ast,
|
||||||
builtins::{
|
builtins::{
|
||||||
@@ -164,36 +163,16 @@ fn source_config_in_directory(parser: &Parser, dir: &wstr) -> bool {
|
|||||||
|
|
||||||
/// Parse init files. exec_path is the path of fish executable as determined by argv[0].
|
/// Parse init files. exec_path is the path of fish executable as determined by argv[0].
|
||||||
fn read_init(parser: &Parser, paths: &ConfigPaths) {
|
fn read_init(parser: &Parser, paths: &ConfigPaths) {
|
||||||
cfg_if!(
|
use fish::autoload::Asset;
|
||||||
if #[cfg(feature = "embed-data")] {
|
let emfile = Asset::get("config.fish").expect("Embedded file not found");
|
||||||
use fish::autoload::Asset;
|
let src = bytes2wcstring(&emfile.data);
|
||||||
let emfile = Asset::get("config.fish").expect("Embedded file not found");
|
parser.libdata_mut().within_fish_init = true;
|
||||||
let src = bytes2wcstring(&emfile.data);
|
let fname: Arc<WString> = Arc::new(L!("embedded:config.fish").into());
|
||||||
parser.libdata_mut().within_fish_init = true;
|
let ret = parser.eval_file_wstr(src, fname, &IoChain::new(), None);
|
||||||
let fname: Arc<WString> = Arc::new(L!("embedded:config.fish").into());
|
parser.libdata_mut().within_fish_init = false;
|
||||||
let ret = parser.eval_file_wstr(src, fname, &IoChain::new(), None);
|
if let Err(msg) = ret {
|
||||||
parser.libdata_mut().within_fish_init = false;
|
eprintf!("%s", msg);
|
||||||
if let Err(msg) = ret {
|
}
|
||||||
eprintf!("%s", msg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let datapath = bytes2wcstring(paths.data.as_ref().unwrap().as_os_str().as_bytes());
|
|
||||||
if !source_config_in_directory(parser, &datapath) {
|
|
||||||
// If we cannot read share/config.fish, our internal configuration,
|
|
||||||
// something is wrong.
|
|
||||||
// That also means that our functions won't be found,
|
|
||||||
// and so any config we get would almost certainly be broken.
|
|
||||||
let escaped_pathname = escape(&datapath);
|
|
||||||
FLOGF!(
|
|
||||||
error,
|
|
||||||
"Fish cannot find its asset files in '%s'.\n\
|
|
||||||
Refusing to read configuration because of this.",
|
|
||||||
escaped_pathname,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
source_config_in_directory(
|
source_config_in_directory(
|
||||||
parser,
|
parser,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
use crate::wutil::{Error, waccess, wbasename, wdirname, wrealpath};
|
use crate::wutil::{Error, waccess, wbasename, wdirname, wrealpath};
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use libc::F_OK;
|
use libc::F_OK;
|
||||||
|
use rust_embed::RustEmbed;
|
||||||
|
|
||||||
macro_rules! str_enum {
|
macro_rules! str_enum {
|
||||||
($name:ident, $(($val:ident, $str:expr)),* $(,)?) => {
|
($name:ident, $(($val:ident, $str:expr)),* $(,)?) => {
|
||||||
@@ -332,10 +333,6 @@ fn parse_cmd_opts(
|
|||||||
return Ok(SUCCESS);
|
return Ok(SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
use rust_embed::RustEmbed;
|
|
||||||
|
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
cfg_if!(
|
cfg_if!(
|
||||||
if #[cfg(use_prebuilt_docs)] {
|
if #[cfg(use_prebuilt_docs)] {
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
@@ -350,7 +347,7 @@ fn parse_cmd_opts(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(all(using_cmake, feature = "embed-data"))]
|
#[cfg(using_cmake)]
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "$FISH_CMAKE_BINARY_DIR/share"]
|
#[folder = "$FISH_CMAKE_BINARY_DIR/share"]
|
||||||
#[include = "__fish_build_paths.fish"]
|
#[include = "__fish_build_paths.fish"]
|
||||||
@@ -491,76 +488,58 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
|||||||
));
|
));
|
||||||
return Err(STATUS_INVALID_ARGS);
|
return Err(STATUS_INVALID_ARGS);
|
||||||
}
|
}
|
||||||
|
let arg = crate::common::wcs2bytes(args[0]);
|
||||||
|
let arg = std::str::from_utf8(&arg).unwrap();
|
||||||
cfg_if!(
|
cfg_if!(
|
||||||
if #[cfg(not(feature = "embed-data"))] {
|
if #[cfg(using_cmake)] {
|
||||||
streams
|
let emfile = CMakeBinaryDir::get(arg);
|
||||||
.err
|
|
||||||
.appendln(sprintf!(NO_EMBEDDED_FILES_MSG.localize(), cmd));
|
|
||||||
return Err(STATUS_CMD_ERROR);
|
|
||||||
} else {
|
} else {
|
||||||
let arg = crate::common::wcs2bytes(args[0]);
|
let emfile = None;
|
||||||
let arg = std::str::from_utf8(&arg).unwrap();
|
|
||||||
cfg_if!(
|
|
||||||
if #[cfg(using_cmake)] {
|
|
||||||
let emfile = CMakeBinaryDir::get(arg);
|
|
||||||
} else {
|
|
||||||
let emfile = None;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let Some(emfile) = emfile
|
|
||||||
.or_else(|| crate::autoload::Asset::get(arg))
|
|
||||||
.or_else(|| Docs::get(arg))
|
|
||||||
else {
|
|
||||||
return Err(STATUS_CMD_ERROR);
|
|
||||||
};
|
|
||||||
let src = bytes2wcstring(&emfile.data);
|
|
||||||
streams.out.append(src);
|
|
||||||
return Ok(SUCCESS);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
let Some(emfile) = emfile
|
||||||
|
.or_else(|| crate::autoload::Asset::get(arg))
|
||||||
|
.or_else(|| Docs::get(arg))
|
||||||
|
else {
|
||||||
|
return Err(STATUS_CMD_ERROR);
|
||||||
|
};
|
||||||
|
let src = bytes2wcstring(&emfile.data);
|
||||||
|
streams.out.append(src);
|
||||||
|
return Ok(SUCCESS);
|
||||||
}
|
}
|
||||||
STATUS_LIST_FILES => {
|
STATUS_LIST_FILES => {
|
||||||
cfg_if!(
|
use crate::util::wcsfilecmp_glob;
|
||||||
if #[cfg(not(feature = "embed-data"))] {
|
let mut paths = vec![];
|
||||||
streams
|
let mut add = |arg| {
|
||||||
.err
|
let arg = crate::common::wcs2bytes(arg);
|
||||||
.appendln(sprintf!(NO_EMBEDDED_FILES_MSG.localize(), cmd));
|
let arg = std::str::from_utf8(&arg).unwrap();
|
||||||
return Err(STATUS_CMD_ERROR);
|
let embedded_files = crate::autoload::Asset::iter().chain(Docs::iter());
|
||||||
} else {
|
#[cfg(using_cmake)]
|
||||||
use crate::util::wcsfilecmp_glob;
|
let embedded_files = embedded_files.chain(CMakeBinaryDir::iter());
|
||||||
let mut paths = vec![];
|
for path in embedded_files {
|
||||||
let mut add = |arg| {
|
if arg.is_empty() || path.starts_with(arg) {
|
||||||
let arg = crate::common::wcs2bytes(arg);
|
paths.push(bytes2wcstring(path.as_bytes()));
|
||||||
let arg = std::str::from_utf8(&arg).unwrap();
|
|
||||||
let embedded_files = crate::autoload::Asset::iter().chain(Docs::iter());
|
|
||||||
#[cfg(using_cmake)]
|
|
||||||
let embedded_files = embedded_files.chain(CMakeBinaryDir::iter());
|
|
||||||
for path in embedded_files {
|
|
||||||
if arg.is_empty() || path.starts_with(arg) {
|
|
||||||
paths.push(bytes2wcstring(path.as_bytes()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if args.is_empty() {
|
|
||||||
add(L!(""));
|
|
||||||
} else {
|
|
||||||
for arg in args {
|
|
||||||
add(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
paths.sort_by(|a, b| wcsfilecmp_glob(a, b));
|
|
||||||
for path in &paths {
|
|
||||||
streams.out.appendln(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !paths.is_empty() {
|
|
||||||
return Ok(SUCCESS);
|
|
||||||
} else {
|
|
||||||
return Err(STATUS_CMD_ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
};
|
||||||
|
if args.is_empty() {
|
||||||
|
add(L!(""));
|
||||||
|
} else {
|
||||||
|
for arg in args {
|
||||||
|
add(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paths.sort_by(|a, b| wcsfilecmp_glob(a, b));
|
||||||
|
for path in &paths {
|
||||||
|
streams.out.appendln(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !paths.is_empty() {
|
||||||
|
return Ok(SUCCESS);
|
||||||
|
} else {
|
||||||
|
return Err(STATUS_CMD_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c @ STATUS_TEST_TERMINAL_FEATURE => {
|
c @ STATUS_TEST_TERMINAL_FEATURE => {
|
||||||
if args.len() != 1 {
|
if args.len() != 1 {
|
||||||
@@ -624,8 +603,6 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
|||||||
streams.out.appendln(profile);
|
streams.out.appendln(profile);
|
||||||
streams.out.append(L!("Features: "));
|
streams.out.append(L!("Features: "));
|
||||||
let features: &[&str] = &[
|
let features: &[&str] = &[
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
"embed-data",
|
|
||||||
#[cfg(feature = "localize-messages")]
|
#[cfg(feature = "localize-messages")]
|
||||||
"localize-messages",
|
"localize-messages",
|
||||||
#[cfg(target_feature = "crt-static")]
|
#[cfg(target_feature = "crt-static")]
|
||||||
@@ -758,7 +735,6 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> B
|
|||||||
streams.out.appendln(result);
|
streams.out.appendln(result);
|
||||||
}
|
}
|
||||||
STATUS_HELP_SECTIONS => {
|
STATUS_HELP_SECTIONS => {
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
streams
|
streams
|
||||||
.out
|
.out
|
||||||
.append_narrow(fish_build_man_pages::HELP_SECTIONS);
|
.append_narrow(fish_build_man_pages::HELP_SECTIONS);
|
||||||
|
|||||||
8
src/env/config_paths.rs
vendored
8
src/env/config_paths.rs
vendored
@@ -9,12 +9,10 @@
|
|||||||
/// A struct of configuration directories, determined in main() that fish will optionally pass to
|
/// A struct of configuration directories, determined in main() that fish will optionally pass to
|
||||||
/// env_init.
|
/// env_init.
|
||||||
pub struct ConfigPaths {
|
pub struct ConfigPaths {
|
||||||
pub sysconf: PathBuf, // e.g., /usr/local/etc
|
pub sysconf: PathBuf, // e.g., /usr/local/etc
|
||||||
pub bin: Option<PathBuf>, // e.g., /usr/local/bin
|
pub bin: Option<PathBuf>, // e.g., /usr/local/bin
|
||||||
/// Always present if "embed-data" is disabled.
|
|
||||||
pub data: Option<PathBuf>, // e.g., /usr/local/share
|
pub data: Option<PathBuf>, // e.g., /usr/local/share
|
||||||
/// Always present if "embed-data" is disabled.
|
pub doc: Option<PathBuf>, // e.g., /usr/local/share/doc/fish
|
||||||
pub doc: Option<PathBuf>, // e.g., /usr/local/share/doc/fish
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SYSCONF_DIR: &str = env!("SYSCONFDIR");
|
const SYSCONF_DIR: &str = env!("SYSCONFDIR");
|
||||||
|
|||||||
8
src/env/environment.rs
vendored
8
src/env/environment.rs
vendored
@@ -646,13 +646,7 @@ pub fn env_init(paths: Option<&ConfigPaths>, do_uvars: bool, default_paths: bool
|
|||||||
set_path(FISH_SYSCONFDIR_VAR, Some(&paths.sysconf));
|
set_path(FISH_SYSCONFDIR_VAR, Some(&paths.sysconf));
|
||||||
set_path(FISH_BIN_DIR, paths.bin.as_ref());
|
set_path(FISH_BIN_DIR, paths.bin.as_ref());
|
||||||
|
|
||||||
let datadir = paths.data.as_ref();
|
set_path(FISH_DATADIR_VAR, paths.data.as_ref());
|
||||||
set_path(FISH_DATADIR_VAR, datadir);
|
|
||||||
if !cfg!(feature = "embed-data") && default_paths {
|
|
||||||
let mut scstr = datadir.unwrap().clone();
|
|
||||||
scstr.push("functions");
|
|
||||||
set_path(L!("fish_function_path"), Some(&scstr));
|
|
||||||
}
|
|
||||||
set_path(FISH_HELPDIR_VAR, paths.doc.as_ref());
|
set_path(FISH_HELPDIR_VAR, paths.doc.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -336,7 +336,6 @@ pub fn get_names(get_hidden: bool, vars: &dyn Environment) -> Vec<WString> {
|
|||||||
names.insert(name.clone());
|
names.insert(name.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "embed-data")]
|
|
||||||
for name in crate::autoload::Asset::iter() {
|
for name in crate::autoload::Asset::iter() {
|
||||||
let Some(bname) = name.strip_prefix("functions/") else {
|
let Some(bname) = name.strip_prefix("functions/") else {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
# Test all completions where the command exists
|
# Test all completions where the command exists
|
||||||
|
|
||||||
# No output is good output
|
# No output is good output
|
||||||
for f in (__fish_data_list_files completions | string match 'completions/*.fish')
|
for f in (status list-files completions | string match 'completions/*.fish')
|
||||||
if type -q (string replace -r '.*/([^/]+).fish' '$1' $f)
|
if type -q (string replace -r '.*/([^/]+).fish' '$1' $f)
|
||||||
set -l out (__fish_data_with_file $f source 2>&1 | string collect)
|
set -l out (__fish_data_with_file $f source 2>&1 | string collect)
|
||||||
test -n "$out"
|
test -n "$out"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# RUN: %fish -d config | grep -v ^Debug.enabled.for.category
|
# RUN: %fish -d config | grep -v ^Debug.enabled.for.category
|
||||||
# REQUIRES: %fish -c 'status build-info' | grep '^Features:.*embed-data'
|
|
||||||
# REQUIRES: %fish -d config -c '' 2>| grep 'Running out of build directory'
|
# REQUIRES: %fish -d config -c '' 2>| grep 'Running out of build directory'
|
||||||
|
|
||||||
# CHECKERR: config: executable path: {{.*}}/fish
|
# CHECKERR: config: executable path: {{.*}}/fish
|
||||||
@@ -6,7 +6,6 @@ __fish_data_with_file functions/__fish_print_help.fish source
|
|||||||
# REQUIRES: command -v sphinx-build
|
# REQUIRES: command -v sphinx-build
|
||||||
# REQUIRES: command -v man
|
# REQUIRES: command -v man
|
||||||
# REQUIRES: test "$FISH_BUILD_DOCS" != "0"
|
# REQUIRES: test "$FISH_BUILD_DOCS" != "0"
|
||||||
# REQUIRES: %fish -c 'status build-info' | grep '^Features:.*embed-data'
|
|
||||||
|
|
||||||
set -l deroff col -b -p -x
|
set -l deroff col -b -p -x
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user