mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-25 19:25:06 +00:00
Add status buildinfo
(#10896)
This can be used to get some information on how fish was built - the
version, the build system, the operating system and architecture, the
features.
(cherry picked from commit 6f9ca42a30
)
This commit is contained in:
parent
c0a2b55efd
commit
5f76fc3e41
5 changed files with 72 additions and 1 deletions
5
build.rs
5
build.rs
|
@ -29,6 +29,11 @@ fn main() {
|
|||
.unwrap(),
|
||||
);
|
||||
|
||||
// Some build info
|
||||
rsconf::set_env_value("BUILD_TARGET_TRIPLE", &env::var("TARGET").unwrap());
|
||||
rsconf::set_env_value("BUILD_HOST_TRIPLE", &env::var("HOST").unwrap());
|
||||
rsconf::set_env_value("BUILD_PROFILE", &env::var("PROFILE").unwrap());
|
||||
|
||||
let version = &get_version(&env::current_dir().unwrap());
|
||||
// Per https://doc.rust-lang.org/cargo/reference/build-scripts.html#inputs-to-the-build-script,
|
||||
// the source directory is the current working directory of the build script
|
||||
|
|
|
@ -49,6 +49,8 @@ set(VARS_FOR_CARGO
|
|||
"PREFIX=${CMAKE_INSTALL_PREFIX}"
|
||||
# Temporary hack to propogate CMake flags/options to build.rs.
|
||||
"CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}"
|
||||
# Cheesy so we can tell cmake was used to build
|
||||
"CMAKE=1"
|
||||
"DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}"
|
||||
"DATADIR=${CMAKE_INSTALL_FULL_DATADIR}"
|
||||
"SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}"
|
||||
|
|
|
@ -29,6 +29,7 @@ Synopsis
|
|||
status job-control CONTROL_TYPE
|
||||
status features
|
||||
status test-feature FEATURE
|
||||
status buildinfo
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
@ -97,6 +98,10 @@ The following operations (subcommands) are available:
|
|||
**test-feature** *FEATURE*
|
||||
Returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized.
|
||||
|
||||
**buildinfo**
|
||||
This prints information on how fish was build - which architecture, which build system or profile was used, etc.
|
||||
This is mainly useful for debugging.
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
|
|
|
@ -57,12 +57,14 @@ enum StatusCmd {
|
|||
STATUS_STACK_TRACE,
|
||||
STATUS_TEST_FEATURE,
|
||||
STATUS_CURRENT_COMMANDLINE,
|
||||
STATUS_BUILDINFO,
|
||||
}
|
||||
|
||||
str_enum!(
|
||||
StatusCmd,
|
||||
(STATUS_BASENAME, "basename"),
|
||||
(STATUS_BASENAME, "current-basename"),
|
||||
(STATUS_BUILDINFO, "buildinfo"),
|
||||
(STATUS_CURRENT_CMD, "current-command"),
|
||||
(STATUS_CURRENT_COMMANDLINE, "current-commandline"),
|
||||
(STATUS_DIRNAME, "current-dirname"),
|
||||
|
@ -420,6 +422,45 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O
|
|||
}
|
||||
return retval;
|
||||
}
|
||||
STATUS_BUILDINFO => {
|
||||
let version = str2wcstring(crate::BUILD_VERSION.as_bytes());
|
||||
let target = str2wcstring(env!("BUILD_TARGET_TRIPLE").as_bytes());
|
||||
let host = str2wcstring(env!("BUILD_HOST_TRIPLE").as_bytes());
|
||||
let profile = str2wcstring(env!("BUILD_PROFILE").as_bytes());
|
||||
streams.out.append(L!("Build system: "));
|
||||
let buildsystem = match option_env!("CMAKE") {
|
||||
Some("1") => "CMake",
|
||||
_ => "Cargo",
|
||||
};
|
||||
streams.out.appendln(str2wcstring(buildsystem.as_bytes()));
|
||||
streams.out.append(L!("Version: "));
|
||||
streams.out.appendln(version);
|
||||
if target == host {
|
||||
streams.out.append(L!("Target (and host): "));
|
||||
streams.out.appendln(target);
|
||||
} else {
|
||||
streams.out.append(L!("Target: "));
|
||||
streams.out.appendln(target);
|
||||
streams.out.append(L!("Host: "));
|
||||
streams.out.appendln(host);
|
||||
}
|
||||
streams.out.append(L!("Profile: "));
|
||||
streams.out.appendln(profile);
|
||||
streams.out.append(L!("Features: "));
|
||||
let features: &[&str] = &[
|
||||
#[cfg(gettext)]
|
||||
"gettext",
|
||||
#[cfg(feature = "installable")]
|
||||
"installable",
|
||||
#[cfg(target_feature = "crt-static")]
|
||||
"crt-static",
|
||||
];
|
||||
streams
|
||||
.out
|
||||
.appendln(str2wcstring(features.join(" ").as_bytes()));
|
||||
streams.out.appendln("");
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
ref s => {
|
||||
if !args.is_empty() {
|
||||
streams.err.append(wgettext_fmt!(
|
||||
|
@ -558,7 +599,10 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O
|
|||
streams.out.appendln(path);
|
||||
}
|
||||
}
|
||||
STATUS_SET_JOB_CONTROL | STATUS_FEATURES | STATUS_TEST_FEATURE => {
|
||||
STATUS_BUILDINFO
|
||||
| STATUS_SET_JOB_CONTROL
|
||||
| STATUS_FEATURES
|
||||
| STATUS_TEST_FEATURE => {
|
||||
unreachable!("")
|
||||
}
|
||||
}
|
||||
|
|
15
tests/checks/buildinfo.fish
Normal file
15
tests/checks/buildinfo.fish
Normal file
|
@ -0,0 +1,15 @@
|
|||
#RUN: %fish %s
|
||||
# Example output:
|
||||
# Build system: CMake
|
||||
# Version: 3.7.1-2573-gea8301631-dirty
|
||||
# Target (and host): x86_64-unknown-linux-gnu
|
||||
# Profile: release
|
||||
# Features: gettext
|
||||
|
||||
status buildinfo | grep -v 'Host:'
|
||||
# CHECK: Build system: {{CMake|Cargo}}
|
||||
# CHECK: Version: {{.+}}
|
||||
# (this could be "Target (and Host)" or "Target:" and a separate line "Host:")
|
||||
# CHECK: Target{{.*}}: {{.+}}
|
||||
# CHECK: Profile: {{release|debug}}
|
||||
# CHECK: Features:{{.*}}
|
Loading…
Reference in a new issue