From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 875D41F601; Sat, 3 Sep 2022 09:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662197261; bh=OxdNiqqJH3ZDboLussGvnyBYGGI17fV991r3YBZhriQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWx0O7MfgzkwV4s16UerLx45eNJNGV/uEOsY/Ctk0lgmwdmsI7liD3ojNk5Qm6eC1 w0ZM4Ob+OSl47iaxH1JdI3qXrKsiz7eHKlwuzqFOUMdaIfd42fKA8HuXjum8sucKi0 TdXr0lBzbUOKmDC57qhYbKlhYwarzN+iHH0uKwN4= From: Eric Wong To: mwrap-public@80x24.org Cc: Sam Saffron Subject: [PATCH 2/3] add --version and --help args Date: Sat, 3 Sep 2022 09:27:40 +0000 Message-Id: <20220903092741.2284559-3-e@80x24.org> In-Reply-To: <20220903092741.2284559-1-e@80x24.org> References: <20220903092741.2284559-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: These may make things easier for new users, and we'll also with help text if given no args. We'll programmatically generate version based on `git describe', but fallback to a hardcoded version if outside of git. We'll also start appending `-dirty' to the version string to match git.git conventions. --- MANIFEST | 3 +++ VERSION-GEN | 36 ++++++++++++++++++++++++++++++++++++ bin/mwrap | 19 +++++++++++++++++++ lib/mwrap/.gitignore | 1 + mwrap.gemspec | 9 ++++++--- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100755 VERSION-GEN create mode 100644 lib/mwrap/.gitignore diff --git a/MANIFEST b/MANIFEST index e6d8964..e8ace8b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5,10 +5,13 @@ COPYING MANIFEST README Rakefile +VERSION-GEN bin/mwrap ext/mwrap/extconf.rb ext/mwrap/jhash.h ext/mwrap/mwrap.c +lib/mwrap/.gitignore lib/mwrap_rack.rb mwrap.gemspec test/test_mwrap.rb +lib/mwrap/version.rb diff --git a/VERSION-GEN b/VERSION-GEN new file mode 100755 index 0000000..161a04f --- /dev/null +++ b/VERSION-GEN @@ -0,0 +1,36 @@ +#!/bin/sh +VF=lib/mwrap/version.rb +DEF_VER=v2.2.0 +VN=$(git describe HEAD 2>/dev/null) +if test $? -eq 0 +then + case "$VN" in + v[0-9]*) + set -e + git update-index -q --refresh + set +e + git diff-index --quiet HEAD -- || VN="$VN-dirty" + set -e + VN=$(echo $VN | tr '-' '.') + ;; + esac +fi +set -e + +case $VN in +'') VN="$DEF_VER" ;; +esac + +VN=$(expr "$VN" : v*'\(.*\)') +VC=unset +if test -r $VF +then + VC="$(cat $VF)" +fi + +new="module Mwrap; VERSION = '$VN'.freeze; end" +if test x"$new" != x"$VC" +then + echo "$new" >$VF +fi +echo $VN diff --git a/bin/mwrap b/bin/mwrap index 212078c..054b3a3 100755 --- a/bin/mwrap +++ b/bin/mwrap @@ -2,6 +2,25 @@ # frozen_string_literal: true # Copyright (C) mwrap hackers # License: GPL-2.0+ +help = </dev/null`.split("\n") +git_ok = $?.success? +git_manifest << 'lib/mwrap/version.rb'.freeze # generated by ./VERSION-GEN manifest = File.exist?('MANIFEST') ? File.readlines('MANIFEST').map!(&:chomp).delete_if(&:empty?) : git_manifest -if git_manifest[0] && manifest != git_manifest +if git_ok && manifest != git_manifest tmp = "MANIFEST.#$$.tmp" File.open(tmp, 'w') { |fp| fp.puts(git_manifest.join("\n")) } File.rename(tmp, 'MANIFEST') system('git add MANIFEST') end -desc = `git describe --abbrev=4 HEAD`.strip.tr('-', '.').delete_prefix('v') +version = `./VERSION-GEN`.chomp +$?.success? or abort './VERSION-GEN failed' Gem::Specification.new do |s| s.name = 'mwrap' - s.version = desc.empty? ? '2.2.0' : desc + s.version = version s.homepage = 'https://80x24.org/mwrap/' s.authors = ["mwrap hackers"] s.summary = 'LD_PRELOAD malloc wrapper for Ruby'