1
0
Fork 0
forked from wry/wry

logging: include version information

This commit is contained in:
Julian Orth 2024-04-10 11:22:17 +02:00
parent f35a7f691a
commit 14b344a1ae
5 changed files with 31 additions and 0 deletions

View file

@ -1,5 +1,30 @@
use {
crate::open,
std::{fmt::Write as _, io::Write as _, process::Command},
};
pub fn main() -> anyhow::Result<()> {
create_bridge()?;
create_version()?;
Ok(())
}
fn create_bridge() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=src/bridge.c");
cc::Build::new().file("src/bridge.c").compile("bridge");
Ok(())
}
fn create_version() -> anyhow::Result<()> {
let mut version_string = env!("CARGO_PKG_VERSION").to_string();
if let Ok(output) = Command::new("git").arg("rev-parse").arg("HEAD").output() {
if output.status.success() {
if let Ok(commit) = std::str::from_utf8(&output.stdout) {
write!(version_string, " ({})", commit.trim())?;
}
}
}
let mut f = open("version.rs")?;
writeln!(f, "pub const VERSION: &str = \"{}\";", version_string)?;
Ok(())
}

View file

@ -38,6 +38,7 @@ use {
oserror::OsError, queue::AsyncQueue, refcounted::RefCounted, run_toplevel::RunToplevel,
tri::Try,
},
version::VERSION,
video::drm::wait_for_sync_obj::WaitForSyncObj,
wheel::{Wheel, WheelError},
xkbcommon::XkbContext,
@ -122,6 +123,7 @@ fn start_compositor2(
test_future: Option<TestFuture>,
) -> Result<(), CompositorError> {
log::info!("pid = {}", uapi::getpid());
log::info!("version = {VERSION}");
init_fd_limit();
leaks::init();
clientmem::init()?;

View file

@ -87,6 +87,7 @@ mod tree;
mod udev;
mod user_session;
mod utils;
mod version;
mod video;
mod wheel;
mod wire;

View file

@ -31,6 +31,7 @@ use {
run_toplevel::RunToplevel,
xrd::xrd,
},
version::VERSION,
video::dmabuf::DmaBufIds,
wheel::Wheel,
wire_dbus::org,
@ -226,6 +227,7 @@ async fn init_dbus_session(dbus: &Dbus, logger: Arc<Logger>) -> Rc<DbusSocket> {
Ok(r) if r.get().rv == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER => {
log::info!("Acquired unique name {}", UNIQUE_NAME);
logger.redirect("portal");
log::info!("version = {VERSION}");
let fork = match fork_with_pidfd(false) {
Ok(f) => f,
Err(e) => fatal!("Could not fork: {}", ErrorFmt(e)),

1
src/version.rs Normal file
View file

@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/version.rs"));