Skip to content

Commit 2921240

Browse files
Create a Perl script that properly creates tags
The previous part of the Makefile didn't work properly. Instead of using the contents of the VERSION file, it updated the file right before the tagging and always for the next minor release. Instead, move everything to a Perl script that updates the VERSION file only after the tagging and sets up for a patch release (which are more frequent). Updating of the dev branch is left as an exercise for the reader. As a bonus, this will work on Windows too without Unix shell tools. Signed-off-by: Thiago Macieira <[email protected]>
1 parent e248db9 commit 2921240

File tree

3 files changed

+73
-23
lines changed

3 files changed

+73
-23
lines changed

Makefile

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,8 @@ distcheck: .git
177177
cd $${TMPDIR-/tmp}/tinycbor-distcheck && $(MAKE) silentcheck
178178
$(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck
179179

180-
release: .git
181-
$(MAKE) -f $(MAKEFILE) distcheck
182-
ifeq ($(VERSION),)
183-
git -C $(SRCDIR). show HEAD:VERSION | \
184-
perl -l -n -e '@_ = split /\./; print "$$_[0]." . ($$_[1] + 1)' > $(SRCDIR)VERSION
185-
else
186-
echo "$(VERSION)" > VERSION
187-
endif
188-
if test -n "`git diff VERSION`"; then \
189-
git -C $(SRCDIR). commit -s -m "Update version number" VERSION; \
190-
fi
191-
{ echo "TinyCBOR release `cat $(SRCDIR)VERSION`"; \
192-
echo; \
193-
echo '# Write something nice about this release here'; \
194-
tmpl=`git -C $(SRCDIR). config --get commit.template` && \
195-
cat "$$tmpl"; \
196-
echo '# Commit log:'; \
197-
git -C $(SRCDIR). shortlog -e --no-merges HEAD --not `git -C $(SRCDIR). tag` | sed 's,^,# ,'; \
198-
echo '# Header diff:'; \
199-
git -C $(SRCDIR). diff HEAD --not `git -C $(SRCDIR). tag` -- 'src/*.h' ':!*_p.h' | sed 's,^,# ,'; \
200-
} > $(SRCDIR).git/TAG_EDITMSG
201-
@`git -C $(SRCDIR). var GIT_EDITOR` $(SRCDIR).git/TAG_EDITMSG
202-
git -C $(SRCDIR). tag -a -F $(SRCDIR).git/TAG_EDITMSG $(GITTAGFLAGS) v`cat $(SRCDIR)VERSION`
180+
tag: distcheck
181+
@cd $(SRCDIR). && perl maketag.pl
203182

204183
.PHONY: all check silentcheck configure install uninstall
205184
.PHONY: mostlyclean clean distclean

Makefile.nmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ clean: mostlyclean
3434
if exist tests\Makefile (cd tests & $(MAKE) clean)
3535
distclean: clean
3636
if exist tests\Makefile (cd tests & $(MAKE) distclean)
37+
tag:
38+
@perl maketag.pl
3739

3840
{src\}.c{src\}.obj:
3941
$(CC) -nologo $(CFLAGS) -Isrc -DTINYCBOR_VERSION="" -c -Fo$@ $<

maketag.pl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!perl
2+
use strict;
3+
sub run(@) {
4+
open PROC, "-|", @_ or die("Cannot run $_[0]: $!");
5+
my @out;
6+
while (<PROC>) {
7+
chomp;
8+
push @out, $_;
9+
}
10+
close PROC;
11+
return @out;
12+
}
13+
14+
my @tags = run("git", "tag");
15+
my @v = run("git", "show", "HEAD:VERSION");
16+
my $v = $v[0];
17+
18+
my $tagfile = ".git/TAG_EDITMSG";
19+
open TAGFILE, ">", $tagfile
20+
or die("Cannot create file for editing tag message: $!");
21+
select TAGFILE;
22+
print "TinyCBOR release $v\n";
23+
print "\n";
24+
print "# Write something nice about this release here\n";
25+
26+
# Do we have a commit template?
27+
my @result = run("git", "config", "--get", "commit.template");
28+
if (scalar @result) {
29+
open TEMPLATE, "<", $result[0];
30+
map { print $_; } <TEMPLATE>;
31+
close TEMPLATE;
32+
}
33+
34+
print "\n";
35+
print "# Commit log\n";
36+
open LOG, "-|", "git", "shortlog", "-e", "--no-merges", "--not", @tags;
37+
map { print "# $_"; } <LOG>;
38+
close LOG;
39+
40+
print "# Header diff:\n";
41+
open DIFF, "-|", "git", "diff", "HEAD", "--not", @tags, "--", 'src/*.h', ':!*_p.h';
42+
map { print "# $_"; } <DIFF>;
43+
close DIFF;
44+
45+
select STDOUT;
46+
close TAGFILE;
47+
48+
# Run the editor.
49+
# We use system so that stdin, stdout and stderr are forwarded.
50+
@result = run("git", "var", "GIT_EDITOR");
51+
@result = ($result[0], $tagfile);
52+
system @result;
53+
exit ($? >> 8) if $?;
54+
55+
# Create the tag
56+
# Also using system so that hte user can see the output.
57+
system("git", "tag", "-a", "-F", $tagfile, split(' ', $ENV{GITTAGFLAGS}), "v$v");
58+
exit ($? >> 8) if $?;
59+
60+
# Update the version file for the next patch release
61+
@v = split(/\./, $v);
62+
if (scalar @v < 3) {
63+
push @v, '1';
64+
} else {
65+
++$v[-1];
66+
}
67+
$v = join('.', @v);
68+
open VERSION, ">", "VERSION" or die("Cannot open VERSION file: $!");
69+
print VERSION "$v\n";

0 commit comments

Comments
 (0)