Add status buildinfo (#10896)
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run

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:
Fabian Boehm 2024-12-29 13:37:28 +01:00
parent c0a2b55efd
commit 5f76fc3e41
5 changed files with 72 additions and 1 deletions

View File

@ -29,6 +29,11 @@ fn main() {
.unwrap(), .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()); let version = &get_version(&env::current_dir().unwrap());
// Per https://doc.rust-lang.org/cargo/reference/build-scripts.html#inputs-to-the-build-script, // 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 // the source directory is the current working directory of the build script

View File

@ -49,6 +49,8 @@ set(VARS_FOR_CARGO
"PREFIX=${CMAKE_INSTALL_PREFIX}" "PREFIX=${CMAKE_INSTALL_PREFIX}"
# Temporary hack to propogate CMake flags/options to build.rs. # Temporary hack to propogate CMake flags/options to build.rs.
"CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}" "CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}"
# Cheesy so we can tell cmake was used to build
"CMAKE=1"
"DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}" "DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}"
"DATADIR=${CMAKE_INSTALL_FULL_DATADIR}" "DATADIR=${CMAKE_INSTALL_FULL_DATADIR}"
"SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}" "SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}"

View File

@ -29,6 +29,7 @@ Synopsis
status job-control CONTROL_TYPE status job-control CONTROL_TYPE
status features status features
status test-feature FEATURE status test-feature FEATURE
status buildinfo
Description Description
----------- -----------
@ -97,6 +98,10 @@ The following operations (subcommands) are available:
**test-feature** *FEATURE* **test-feature** *FEATURE*
Returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized. 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 Notes
----- -----

View File

@ -57,12 +57,14 @@ enum StatusCmd {
STATUS_STACK_TRACE, STATUS_STACK_TRACE,
STATUS_TEST_FEATURE, STATUS_TEST_FEATURE,
STATUS_CURRENT_COMMANDLINE, STATUS_CURRENT_COMMANDLINE,
STATUS_BUILDINFO,
} }
str_enum!( str_enum!(
StatusCmd, StatusCmd,
(STATUS_BASENAME, "basename"), (STATUS_BASENAME, "basename"),
(STATUS_BASENAME, "current-basename"), (STATUS_BASENAME, "current-basename"),
(STATUS_BUILDINFO, "buildinfo"),
(STATUS_CURRENT_CMD, "current-command"), (STATUS_CURRENT_CMD, "current-command"),
(STATUS_CURRENT_COMMANDLINE, "current-commandline"), (STATUS_CURRENT_COMMANDLINE, "current-commandline"),
(STATUS_DIRNAME, "current-dirname"), (STATUS_DIRNAME, "current-dirname"),
@ -420,6 +422,45 @@ pub fn status(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O
} }
return retval; 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 => { ref s => {
if !args.is_empty() { if !args.is_empty() {
streams.err.append(wgettext_fmt!( 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); 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!("") unreachable!("")
} }
} }

View 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:{{.*}}