all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-backup-qemu 1/3] include debian version and git rev in header file
Date: Thu,  5 Nov 2020 12:17:57 +0100	[thread overview]
Message-ID: <20201105111759.20569-2-s.reiter@proxmox.com> (raw)
In-Reply-To: <20201105111759.20569-1-s.reiter@proxmox.com>

...so we can get the library version a binary is currently running with.

Details are retrieved in build.rs by calling dpkg-parsechangelog and
git, then appended using 'with_after_include' to appear within the
include guard.

The version string in current-api.h is inconsequential, so ignore it in
diff. This way we only have to re-commit that file whenever the *actual*
API changes, not the version.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
 Makefile      |  4 ++--
 build.rs      | 26 ++++++++++++++++++++++++++
 current-api.h |  2 ++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 8761298..bc5f1f0 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ endif
 all:
 ifneq ($(BUILD_MODE), skip)
 	cargo build $(CARGO_BUILD_ARGS)
-	diff -up current-api.h proxmox-backup-qemu.h
+	diff -I 'PROXMOX_BACKUP_QEMU_VERSION' -up current-api.h proxmox-backup-qemu.h
 endif
 
 # always re-create this dir
@@ -29,7 +29,7 @@ endif
 build:
 	rm -rf build
 	cargo build --release
-	diff -up current-api.h proxmox-backup-qemu.h
+	diff -I 'PROXMOX_BACKUP_QEMU_VERSION' -up current-api.h proxmox-backup-qemu.h
 	rsync -a debian Makefile Cargo.toml Cargo.lock build.rs proxmox-backup-qemu.h src target current-api.h build/
 
 .PHONY: install
diff --git a/build.rs b/build.rs
index 46dbb7a..c49b2ab 100644
--- a/build.rs
+++ b/build.rs
@@ -2,16 +2,42 @@
 extern crate cbindgen;
 
 use std::env;
+use std::process::Command;
+
+fn capture_stdout(cmd: &str) -> String {
+    let args: Vec<&str> = cmd.split(' ').collect();
+    let (exe, args) = (args[0], &args[1..]);
+
+    let stdout = Command::new(exe)
+        .args(args)
+        .output()
+        .expect(&format!("failed to run program: {}", exe))
+        .stdout;
+
+    String::from_utf8(stdout)
+        .expect(&format!("program {} produced invalid UTF-8 output", exe))
+        .trim()
+        .to_owned()
+}
 
 fn main() {
     let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
     let header = std::fs::read_to_string("header-preamble.c").unwrap();
 
+    let debver = capture_stdout("dpkg-parsechangelog -l debian/changelog -SVersion");
+    let gitver = capture_stdout("git rev-parse --short=8 HEAD");
+    let version_define = format!(
+        "\n#define PROXMOX_BACKUP_QEMU_VERSION \"{} ({})\"",
+        debver,
+        gitver,
+    );
+
     cbindgen::Builder::new()
         .with_language(cbindgen::Language::C)
         .with_crate(&crate_dir)
         .with_header(header)
         .with_include_guard("PROXMOX_BACKUP_QEMU_H")
+        .with_after_include(version_define)
         .generate()
         .unwrap()
         .write_to_file("proxmox-backup-qemu.h");
diff --git a/current-api.h b/current-api.h
index 77e8c4b..97c185f 100644
--- a/current-api.h
+++ b/current-api.h
@@ -32,6 +32,8 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#define PROXMOX_BACKUP_QEMU_VERSION "0.7.1-1 (296da586)"
+
 #define PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE ((1024 * 1024) * 4)
 
 /**
-- 
2.20.1





  reply	other threads:[~2020-11-05 11:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 11:17 [pve-devel] [PATCH 0/3] Add PBS lib version to VM 'status' call Stefan Reiter
2020-11-05 11:17 ` Stefan Reiter [this message]
2020-11-11 14:26   ` [pve-devel] applied: [PATCH proxmox-backup-qemu 1/3] include debian version and git rev in header file Fabian Grünbichler
2020-11-05 11:17 ` [pve-devel] [PATCH pve-qemu 2/3] update patches with squashed in 'include library version' Stefan Reiter
2020-11-10 16:12   ` [pve-devel] [PATCH v2 " Stefan Reiter
2020-11-05 11:17 ` [pve-devel] [PATCH qemu-server 3/3] print query-proxmox-support result in 'full' status Stefan Reiter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201105111759.20569-2-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal