From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2D5171F855 for ; Thu, 28 Jul 2016 00:16:17 +0000 (UTC) From: Eric Wong To: olddoc-public@80x24.org Subject: [PATCH] build: dynamically generate version number Date: Thu, 28 Jul 2016 00:16:17 +0000 Message-Id: <20160728001617.29409-1-e@80x24.org> List-Id: This should make development a bit easier --- .gitignore | 1 + GIT-VERSION-GEN | 42 ++++++++++++++++++++++++++++++++++++++++++ GNUmakefile | 4 +++- lib/olddoc.rb | 2 -- olddoc.gemspec | 1 + 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100755 GIT-VERSION-GEN diff --git a/.gitignore b/.gitignore index 2a6e67a..d873717 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ LATEST .gem-manifest .tgz-manifest /doc +/lib/olddoc/version.rb diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN new file mode 100755 index 0000000..7199e19 --- /dev/null +++ b/GIT-VERSION-GEN @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +# Copyright (C) 2016 all contributors +# License: GPL-3.0+ +# frozen_string_literal: true +CONSTANT = "Olddoc::VERSION" +RVF = "lib/olddoc/version.rb" +GVF = "GIT-VERSION-FILE" +DEF_VER = "v1.3.0.GIT" +vn = DEF_VER.dup + +# First see if there is a version file (included in release tarballs), +# then try git-describe, then default. +if File.exist?(".git") + describe = `git describe --abbrev=4 HEAD 2>/dev/null`.strip + case describe + when /\Av[0-9]*/ + vn = describe + system(*%w(git update-index -q --refresh)) + unless `git diff-index --name-only HEAD --`.chomp.empty? + vn << "-dirty" + end + vn.tr!('-', '.') + end +end + +vn = vn.sub!(/\Av/, "") +new_ruby_version = "#{CONSTANT} = '#{vn}'.freeze # :nodoc:\n" +cur_ruby_version = File.read(RVF) rescue nil +if new_ruby_version != cur_ruby_version + File.open(RVF, "w") { |fp| fp.write(new_ruby_version) } +end +File.chmod(0644, RVF) + +# generate the makefile snippet +new_make_version = "VERSION = #{vn}\n" +cur_make_version = File.read(GVF) rescue nil +if new_make_version != cur_make_version + File.open(GVF, "w") { |fp| fp.write(new_make_version) } +end +File.chmod(0644, GVF) + +puts vn if $0 == __FILE__ diff --git a/GNUmakefile b/GNUmakefile index f67cab6..1e07a44 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -3,7 +3,9 @@ all:: pkg = olddoc RUBY = ruby -VERSION := $(shell $(RUBY) -Ilib -rolddoc -e 'puts Olddoc::VERSION') +GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE + @./GIT-VERSION-GEN +-include GIT-VERSION-FILE check-warnings: @(for i in $$(git ls-files '*.rb'| grep -v '^setup\.rb$$'); \ diff --git a/lib/olddoc.rb b/lib/olddoc.rb index 5a70577..3061e73 100644 --- a/lib/olddoc.rb +++ b/lib/olddoc.rb @@ -1,8 +1,6 @@ # Copyright (C) 2015-2016 all contributors # License: GPL-3.0+ module Olddoc # :nodoc: - VERSION = '1.2.0' # :nodoc: - autoload :Gemspec, 'olddoc/gemspec' autoload :History, 'olddoc/history' autoload :Merge, 'olddoc/merge' diff --git a/olddoc.gemspec b/olddoc.gemspec index def2265..d059955 100644 --- a/olddoc.gemspec +++ b/olddoc.gemspec @@ -2,6 +2,7 @@ # License: GPL-3.0+ $LOAD_PATH << 'lib' require 'olddoc' +require 'olddoc/version' extend Olddoc::Gemspec name, summary, title = readme_metadata Gem::Specification.new do |s| -- EW