]> Sergey Matveev's repositories - public-inbox.git/commitdiff
build: generate PublicInbox.pm with $VERSION
authorEric Wong <e@80x24.org>
Thu, 1 Apr 2021 09:32:37 +0000 (02:32 -0700)
committerEric Wong <e@80x24.org>
Thu, 1 Apr 2021 18:25:15 +0000 (18:25 +0000)
Thanks to git-describe, we can generate and update this
file to aid users in bug reporting.

.gitignore
MANIFEST
Makefile.PL
t/config.t
version-gen.perl [new file with mode: 0644]

index f7e4c5953e68b7f36866cb3e96f1a3f926070ceb..f0370ccac1c0b8cac7c0460c84dd920422a08966 100644 (file)
@@ -21,3 +21,4 @@
 /NEWS.atom
 /NEWS
 *.log
+/lib/PublicInbox.pm
index 49d273fc91c62ce13fbd48f065a5c1069d007be3..5e3b4aec48e53b556708578eacc9d2013a4431a1 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -482,6 +482,7 @@ t/www_listing.t
 t/www_static.t
 t/x-unknown-alpine.eml
 t/xcpdb-reshard.t
+version-gen.perl
 xt/cmp-msgstr.t
 xt/cmp-msgview.t
 xt/create-many-inboxes.t
index feb89ec102c2334a6485701340d9047a75b323e5..129b082d82f36a26bb7c4d1a11cc6ae3627df3d8 100644 (file)
@@ -5,6 +5,7 @@ use strict;
 use ExtUtils::MakeMaker;
 open my $m, '<', 'MANIFEST' or die "open(MANIFEST): $!\n";
 chomp(my @manifest = (<$m>));
+push @manifest, 'lib/PublicInbox.pm'; # generated
 my @EXE_FILES = grep(m!^script/!, @manifest);
 my $v = {};
 my $t = {};
@@ -139,7 +140,7 @@ WriteMakefile(
        NAME => 'PublicInbox', # n.b. camel-case is not our choice
 
        # XXX drop "PENDING" in .pod before updating this!
-       VERSION => '1.6.1',
+       VERSION => '1.7.0.PENDING',
 
        AUTHOR => 'Eric Wong <e@80x24.org>',
        ABSTRACT => 'public-inbox server infrastructure',
@@ -242,13 +243,17 @@ Makefile.PL : MANIFEST
 # prefix + bindir matches git.git Makefile:
 prefix = \$(HOME)
 bindir = \$(prefix)/bin
-symlink-install :
+symlink-install : lib/PublicInbox.pm
        mkdir -p \$(bindir)
        lei=\$\$(realpath lei.sh) && cd \$(bindir) && \\
        for x in \$(EXE_FILES); do \\
                ln -sf "\$\$lei" \$\$(basename "\$\$x"); \\
        done
 
+pure_all :: lib/PublicInbox.pm
+lib/PublicInbox.pm : FORCE
+       VERSION=\$(VERSION) \$(PERL) -w ./version-gen.perl
+
 update-copyrights :
        \@case '\$(GNULIB_PATH)' in '') echo >&2 GNULIB_PATH unset; false;; esac
        git ls-files | UPDATE_COPYRIGHT_HOLDER='all contributors' \\
index 73527ec2699bc84efe567d595ed121ece23216e8..877e5d5d45f7fbb1a9edfbe49c5b8fc98f17682a 100644 (file)
@@ -1,11 +1,12 @@
 # Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
-use PublicInbox::Config;
+use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Import;
+use_ok 'PublicInbox';
+ok(defined(eval('$PublicInbox::VERSION')), 'VERSION defined');
+use_ok 'PublicInbox::Config';
 my ($tmpdir, $for_destroy) = tmpdir();
 
 {
diff --git a/version-gen.perl b/version-gen.perl
new file mode 100644 (file)
index 0000000..e9964e3
--- /dev/null
@@ -0,0 +1,29 @@
+#!perl -w
+use v5.10.1;
+my $v = $ENV{VERSION} // die 'VERSION unset';
+my $f = './lib/PublicInbox.pm';
+if (-d ($ENV{GIT_DIR} // '.git') || -f '.git') {
+       chomp(my $gv = `git describe --match "v[0-9]*" HEAD`);
+       if ($? == 0) {
+               substr($gv, 0, 1, ''); # remove "v"
+               system(qw(git update-index -q --refresh));
+               if (my @n = `git diff-index --name-only HEAD --`) {
+                       $gv .= '-dirty';
+               }
+               $v = $gv;
+       }
+}
+$v =~ tr/-/./;
+if (-f $f && do $f && (eval('$PublicInbox::VERSION') // 'undef') eq $v) {
+       exit
+}
+my $tmp = "$f.tmp.$$";
+open my $fh, '>', $tmp  or die "open($tmp): $!";
+print $fh <<EOM or die "print($tmp): $!";
+# this file is generated by $0
+package PublicInbox;
+our \$VERSION = '$v';
+1;
+EOM
+close $fh or die "close($tmp): $!";
+rename($tmp, $f) or die "rename($tmp, $f): $!";