From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A016066233 for ; Thu, 5 Nov 2020 12:18:39 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 417E61764E for ; Thu, 5 Nov 2020 12:18:09 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 843121761C for ; Thu, 5 Nov 2020 12:18:08 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4B91845E61 for ; Thu, 5 Nov 2020 12:18:08 +0100 (CET) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Thu, 5 Nov 2020 12:17:57 +0100 Message-Id: <20201105111759.20569-2-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201105111759.20569-1-s.reiter@proxmox.com> References: <20201105111759.20569-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.037 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [build.rs] Subject: [pve-devel] [PATCH proxmox-backup-qemu 1/3] include debian version and git rev in header file X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Nov 2020 11:18:39 -0000 ...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 --- 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 #include +#define PROXMOX_BACKUP_QEMU_VERSION "0.7.1-1 (296da586)" + #define PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE ((1024 * 1024) * 4) /** -- 2.20.1