diff options
author | Eric Wong <e@80x24.org> | 2022-09-03 09:27:40 +0000 |
---|---|---|
committer | Eric Wong <mwrap-public@80x24.org> | 2022-09-03 09:53:12 +0000 |
commit | 3d210d3fffafca348945500a53fba1d3a2072327 (patch) | |
tree | fdd4707276cd9c6568dfc77f00c92220564bff54 | |
parent | 7524237b2de98f7e407ea227fb6ca6904153c0a5 (diff) | |
download | mwrap-3d210d3fffafca348945500a53fba1d3a2072327.tar.gz |
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.
-rw-r--r-- | MANIFEST | 3 | ||||
-rwxr-xr-x | VERSION-GEN | 36 | ||||
-rwxr-xr-x | bin/mwrap | 19 | ||||
-rw-r--r-- | lib/mwrap/.gitignore | 1 | ||||
-rw-r--r-- | mwrap.gemspec | 9 |
5 files changed, 65 insertions, 3 deletions
@@ -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 @@ -2,6 +2,25 @@ # frozen_string_literal: true # Copyright (C) mwrap hackers <mwrap-public@80x24.org> # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt> +help = <<EOM +usage: mwrap COMMAND [ARGS] +see https://80x24.org/mwrap/README.html for more info +EOM +ARGV.empty? and abort help +ARGV.each do |x| + case x + when '--version', '-v' + require 'mwrap/version' + puts "mwrap #{Mwrap::VERSION} - #{RUBY_DESCRIPTION}" + exit 0 + when '--help', '-h' + puts help + exit 0 + else # don't intercept --version/--help intended for commands we wrap + break + end +end + require 'mwrap' mwrap_so = $".grep(%r{/mwrap\.so\z})[0] or abort "mwrap.so not loaded" cur = ENV['LD_PRELOAD'] diff --git a/lib/mwrap/.gitignore b/lib/mwrap/.gitignore new file mode 100644 index 0000000..07c0394 --- /dev/null +++ b/lib/mwrap/.gitignore @@ -0,0 +1 @@ +version.rb diff --git a/mwrap.gemspec b/mwrap.gemspec index 48a32b2..cb541e3 100644 --- a/mwrap.gemspec +++ b/mwrap.gemspec @@ -1,18 +1,21 @@ git_manifest = `git ls-files 2>/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' |