Skip to content

Commit c29cfb8

Browse files
committed
lbnl-nhc.spec.in: Special-case tagged release
If the current version being built (as specified in `configure.ac` and assigned to `%{version}`) exactly matches the tag for that same version in the Git repository, swap out the normal Git-based `%{rel}` string for simply "1" if the working directory is clean or "1.1" if it's dirty. (The disttag is, of course, appended in all cases.) Additionally, since the Git-fu that generates all this stuff isn't exactly obvious, I added several detailed comments to describe what each macro is doing and why.
1 parent 7c80bc8 commit c29cfb8

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lbnl-nhc.spec.in

+28-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,38 @@
22
%global version @VERSION@
33
%global release %{rel}%{?dist}
44

5+
### Macros to populate RPM %{RELEASE} field with useful info
6+
# {gitrelease} holds the ./configure-generated version of the same
7+
# info that's calculated for {spec_rel} below. This allows us to
8+
# build out-of-tree with the same Git info.
59
%global gitrelease @GITRELEASE@
10+
# {gd_rel_delta} uses "git describe" to return a string in the form
11+
# "<commits>.g<hash>[.1]?" to be used in {spec_rel} below.
612
%{expand:%%global gd_rel_delta %(GD1=`git describe --abbrev=4 --always --tags --long --match '[[:digit:]][[:alnum:].]*[[:alnum:]]' --dirty=.1 2>/dev/null` ; test -n "${GD1}" && echo "${GD1}" | cut -d- -f 2- | tr '-' '.')%%{nil}}
13+
# {rel_pre_post} gets set to either "1." or "0." based on whether the
14+
# source was built from a commit before ("0.") or after ("1.") the
15+
# tagged release specified by {version} above.
716
%{expand:%%global rel_pre_post %(GD2=`git describe --tags HEAD 2>/dev/null` ; if test -n "${GD2}" ; then echo "${GD2}" | grep -Eq '^%{version}' >&/dev/null && echo 1. || echo 0. ; fi)%%{nil}}
17+
# {spec_rel} combines the two values above into a single string for
18+
# use in the "Release:" field. The resulting string, when used at the
19+
# beginning of the "Release:" header value, not only guarantees
20+
# correct RPM NEVR ordering (i.e., newer packages will always upgrade
21+
# older ones) but also shows how many <commits> were made since the
22+
# last tagged release, the Git commit <hash> from which the source
23+
# tarball ("Source:" below) was built, and whether the tarball also
24+
# contains some uncommitted changes from a "dirty" working tree (".1"
25+
# on the end).
826
%{expand:%%global spec_rel %{?rel_pre_post}%{?gd_rel_delta}%%{nil}}
9-
%{!?rel:%{expand:%%global rel %(if test -z "%{spec_rel}" ; then echo "%{gitrelease}" ; else echo "%{spec_rel}" ; fi)}}
27+
# {rel} ultimately determines what the release string will be; only
28+
# the disttag gets appended to it. If the user specifies their own
29+
# value (e.g., "rpmbuild --define 'rel 1'"), that value is used
30+
# instead. If not, the string described above is pulled either from
31+
# {spec_rel} (if building from Git repo) or {gitrelease} (if building
32+
# from SRPM or source tarball).
33+
# As a special case, if the commit being built exactly matches the Git
34+
# tag for the specified version, {rel} is set to either "1" (clean
35+
# working directory) or "1.1" (dirty working directory).
36+
%{!?rel:%{expand:%%global rel %(REL="%{?spec_rel}%{!?spec_rel:%{gitrelease}}" ; if (echo "${REL:-nope}" | grep -Fq "1.0.g" 2>/dev/null) ; then if (echo "${REL:-nope}" | grep -q '\.1$' 2>/dev/null) ; then echo "1.1" ; else echo 1 ; fi ; elif test -z "%{spec_rel}" ; then echo "%{gitrelease}" ; else echo "%{spec_rel}" ; fi)%{nil}}}
1037

1138
%{!?sname:%global sname nhc}
1239
%{!?nhc_script_dir:%global nhc_script_dir %{_sysconfdir}/%{sname}/scripts}

0 commit comments

Comments
 (0)