[pve-devel] applied: [PATCH proxmox-backup-qemu 1/3] include debian version and git rev in header file

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Nov 11 15:26:52 CET 2020


a slightly simplified version

On November 5, 2020 12:17 pm, Stefan Reiter wrote:
> ...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 at 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
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 





More information about the pve-devel mailing list