Browse Source

Update MKit to version v0.0.9

Alois Mahdal 8 years ago
parent
commit
157847710c
5 changed files with 64 additions and 46 deletions
  1. 13
    12
      utils/mkit/include/build.sh
  2. 24
    7
      utils/mkit/include/mkit.sh
  3. 24
    17
      utils/mkit/include/release.sh
  4. 1
    1
      utils/mkit/make
  5. 2
    9
      utils/mkit/mkit.mk

+ 13
- 12
utils/mkit/include/build.sh View File

@@ -92,10 +92,10 @@ dist() {
92 92
     #       rpmstuff, hence -f hack for gzip
93 93
     #
94 94
     local version=$(get_version)
95
-    local dirname=$MKIT_PKGNAME-$version
95
+    local dirname=$MKIT_PROJ_PKGNAME-$version
96 96
     mkdir -p "$dirname"
97 97
     ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
98
-    sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
98
+    update_version "$version" "$dirname/mkit.ini"
99 99
     tar -cf "$dirname.tar" "$dirname"
100 100
     gzip -f "$dirname.tar"      # see above FIXME
101 101
     mkdir -p "$MKIT_LOCAL"
@@ -107,7 +107,7 @@ rpmstuff() {
107 107
     #
108 108
     # Build specfile
109 109
     #
110
-    local specname="$(ini 1value ENV:PKGNAME).spec"
110
+    local specname="$MKIT_PROJ_PKGNAME.spec"
111 111
     local specsrc="$(ini 1value "rpmstuff:spec_skel")"
112 112
     test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
113 113
     test -f "$specsrc" || die "specfile template not found: $specsrc"
@@ -156,8 +156,9 @@ expand_variables() {
156 156
                 debug_var varname varvalue
157 157
             done
158 158
     done
159
-    echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
160
-    echo "s|__VERSION__|$(get_version)|;" >> "$script"
159
+    echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename)|;" >> "$script"
160
+    echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline)|;" >> "$script"
161
+    echo "s|__MKIT_PROJ_VERSION__|$(get_version)|;" >> "$script"
161 162
     perl -wp "$script" || die "expand_variables failed"
162 163
     rm "$script"
163 164
 }
@@ -169,9 +170,9 @@ get_version() {
169 170
     # Build version string from available info using following
170 171
     # logic:
171 172
     #
172
-    #  1. use VERSION (from config.mk)
173
+    #  1. use project.version (from mkit.ini)
173 174
     #  2. if we are in git, override the version with last tag
174
-    #  3. if set, add PRERELEASE (from config.mk) as pre-release ID
175
+    #  3. if set, add project:prerl (from mkit.ini) as pre-release ID
175 176
     #     (afer dash)
176 177
     #  4. if we are at a later commit than the last tag, add branch
177 178
     #     name and commit sha1 to build metadata (after plus sign)
@@ -183,7 +184,7 @@ get_version() {
183 184
     # Examples:
184 185
     #
185 186
     #     myprog v1.0.7                         # all clear
186
-    #     myprog v1.0.7-alpha                   # PRERELEASE="alpha"
187
+    #     myprog v1.0.7-alpha                   # mkit.ini: project:prerl="alpha"
187 188
     #     myprog v1.0.7-alpha+g1aef811.master   # ^^ + some commits after
188 189
     #     myprog v1.0.7-alpha+gf14fc4f.api2     # ^^ + on a feature branch
189 190
     #     myprog v1.0.7-alpha+gf14fc4f.api2.dirty  # ^^ + tree edited
@@ -204,12 +205,12 @@ get_version() {
204 205
     # meta-data is to *identify* the code, and provide safe path back
205 206
     # to tree; commit refs are already perfect for that.
206 207
     #
207
-    # FIXME:  Using PRERELEASE for release IDs may not be compatible with
208
+    # FIXME:  Using project:prerl for release IDs may not be compatible with
208 209
     #         release strategy implemented in release.sh
209 210
     #
210
-    local version=$VERSION
211
-    local prerl=$PRERELEASE
212
-    grep ":" <<<"$prerl" && warn "colon in PRERELEASE may corrupt version data: $prerl"
211
+    local version=$(ini 1value project:version)
212
+    local prerl=$(ini 1value project:prerl)
213
+    grep ":" <<<"$prerl" && warn "colon in project:prerl may corrupt version data: $prerl"
213 214
     if git rev-parse HEAD >&/dev/null;
214 215
     then    # we are in git repo... so we can get smart
215 216
         local latest_tag=$(

+ 24
- 7
utils/mkit/include/mkit.sh View File

@@ -32,21 +32,17 @@ debug_var() {
32 32
 
33 33
 MKIT_INI=${MKIT_INI:-mkit.ini}
34 34
 MKIT_INI_EXPAND=2
35
-MKIT_PKGNAME=$(ini 1value "ENV:PKGNAME")
36
-MKIT_PROJNAME=$(ini 1value "ENV:PROJNAME")
35
+MKIT_PROJ_NAME=$(ini 1value "project:name")
36
+MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
37 37
 MKIT_DEFAULT_MODE="644"
38 38
 
39 39
 mkit_init() {
40 40
     #
41 41
     # Do basic initialization
42 42
     #
43
-    # Check for ini file, load variables from config.mk
43
+    # Check for ini file and some variables
44 44
     #
45 45
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
46
-    tmp=$(mktemp)
47
-    sed -e 's/ = /=/' < config.mk > "$tmp"
48
-    . "$tmp"
49
-    rm -f "$tmp"
50 46
     test -n "$(tr -d '[:space:]' <<<"$MKIT_LOCAL")" \
51 47
      || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
52 48
 }
@@ -66,6 +62,27 @@ warn() {
66 62
     echo "$@" >&2
67 63
 }
68 64
 
65
+update_version() {
66
+    #
67
+    # Change project.version in mkit.ini at path $2 to version $1
68
+    #
69
+    local version="$1"
70
+    local inifile="$2"
71
+    local tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
72
+    <"$inifile" perl -e '
73
+        my $hit = 0;
74
+        my $done = 0;
75
+        foreach (<STDIN>) {
76
+            if      ($done) { print; next; }
77
+            elsif   (m/\[project\]/) { $hit++; print; next; }
78
+            elsif   (m/\[/) { $hit = 0; print; next; }
79
+            elsif   ($hit) { s/\bversion\b *=.*/version = $ARGV[0]/ and $done++; print; }
80
+            else { print; next; }
81
+        }
82
+    ' "$version" >"$tmp" || die "failed to update version in mkit.ini"
83
+    mv "$tmp" "$inifile"
84
+}
85
+
69 86
 route() {
70 87
     #
71 88
     # Call correct function based on $1

+ 24
- 17
utils/mkit/include/release.sh View File

@@ -12,9 +12,10 @@ __die_if() {
12 12
              || die "cannot do this outside git repo"
13 13
             ;;
14 14
         norelbr)
15
+            local relsrc=$(ini 1value project:relsrc)
15 16
             __git_info curbranch \
16
-              | grep -qFx "$RELSRC" \
17
-             || die "you are not on RELSRC branch: $RELSRC"
17
+              | grep -qFx "$relsrc" \
18
+             || die "you are not on release source branch: $relsrc"
18 19
             ;;
19 20
         dirty)
20 21
             git diff --shortstat 2>/dev/null \
@@ -28,8 +29,8 @@ __die_if() {
28 29
             ;;
29 30
         nobump)
30 31
             git diff-tree --no-commit-id --name-only -r HEAD \
31
-              | grep -qFx config.mk \
32
-             || die "last change must be version bump in config.mk"
32
+              | grep -qFx mkit.ini \
33
+             || die "last change must be version bump in mkit.ini"
33 34
             ;;
34 35
         wip)
35 36
             __git_info reldiff \
@@ -40,7 +41,7 @@ __die_if() {
40 41
             x=$(__ver_info nextver_g)
41 42
             __ver_info currver_c \
42 43
               | grep -qFx "$x" \
43
-             || die "new version not in config.mk: $x"
44
+             || die "new version not in mkit.ini: $x"
44 45
             ;;
45 46
     esac
46 47
 }
@@ -53,7 +54,7 @@ __git_info() {
53 54
     case "$info" in
54 55
         lasttag)    git tag | grep ^v | sort -V | tail -n1  ;;
55 56
         curbranch)  git rev-parse --abbrev-ref HEAD         ;;
56
-        reldiff)    git log --oneline "$(__git_info lasttag)..HEAD" ;;
57
+        reldiff)    git log --oneline "$(__git_info lasttag)..HEAD" --name-only ;;
57 58
     esac
58 59
 }
59 60
 
@@ -65,8 +66,7 @@ __ver_info() {
65 66
     case "$info" in
66 67
         lastver_g)  __git_info lasttag | sed s/^v// ;;
67 68
         nextver_g)  __make_ver "$level" "$(__ver_info lastver_g)" ;;
68
-        currver_c)  grep -m 1 -w VERSION config.mk \
69
-                     | sed 's/ *= */=/' | cut -d = -f 2 | xargs echo ;;
69
+        currver_c)  ini 1value project:version ;;
70 70
         nextver_c)  __make_ver "$level" "$(__ver_info currver_c)" ;;
71 71
     esac
72 72
 }
@@ -94,7 +94,7 @@ __release() {
94 94
     # Span release routines: make a signed tag, check branch
95 95
     # and update release branch
96 96
     #
97
-    # FIXME: Using PRERELEASE as build.sh:get_version() does may not be
97
+    # FIXME: Using project:prerl as build.sh:get_version() does may not be
98 98
     #        compatible with this release strategy
99 99
     #
100 100
     local level=$1
@@ -112,19 +112,26 @@ __release() {
112 112
     set -e
113 113
     debug_var newtag
114 114
     $MKIT_DRY && return
115
-    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
116
-    git branch -f "$RELDST" "$newtag"
115
+    git tag -m "$MKIT_PROJ_NAME $newtag - $CODENAME" "$newtag"
116
+    git branch -f "$(ini 1value project:reldst)" "$newtag"
117 117
 }
118 118
 
119 119
 __git_msg_vbump() {
120 120
     echo "Bump version"
121 121
     echo ""
122
-    __git_info reldiff | sed 's/^/ *  /'
122
+    echo "Overview of changes:"
123
+    echo ""
124
+    __git_info reldiff \
125
+      | sed '
126
+            s/^[a-f0-9]\{7\} / *  &/; t PATHS
127
+            s/^/        /
128
+            :PATHS
129
+        '
123 130
 }
124 131
 
125 132
 __vbump() {
126 133
     local level="$1"
127
-    local lastver   # current from config.mk
134
+    local lastver   # current from mkit.ini
128 135
     local nextver   # after the bump
129 136
     __die_if nogit
130 137
     __die_if norelbr
@@ -133,10 +140,10 @@ __vbump() {
133 140
     nextver=$(__ver_info nextver_c)
134 141
     debug_var lastver nextver
135 142
     $MKIT_DRY && return
136
-    sed -i "s/$lastver/$nextver/" config.mk \
137
-      || die "failed to update config.mk"
138
-    git add config.mk \
139
-      || die "failed to add config.mk to the index"
143
+    update_version "$nextver" mkit.ini \
144
+      || die "failed to update version in mkit.ini"
145
+    git add mkit.ini \
146
+      || die "failed to add mkit.ini to the index"
140 147
     git commit -e -m "$(__git_msg_vbump)"
141 148
 }
142 149
 

+ 1
- 1
utils/mkit/make View File

@@ -6,7 +6,7 @@ die() {
6 6
     echo "$@" && exit 9
7 7
 }
8 8
 
9
-export MKIT_VERSION=0.0.8
9
+export MKIT_VERSION=0.0.9
10 10
 
11 11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
12 12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}

+ 2
- 9
utils/mkit/mkit.mk View File

@@ -3,14 +3,7 @@
3 3
 
4 4
 export MKIT_DIR
5 5
 
6
-all: options build
7
-
8
-options:
9
-	@echo build options:
10
-	@echo "VERSION  = ${VERSION}"
11
-	@echo "PRERELEASE = ${PRERELEASE}"
12
-	@echo "DESTDIR   = ${DESTDIR}"
13
-	@echo "PREFIX   = ${PREFIX}"
6
+all: build
14 7
 
15 8
 build:
16 9
 	@$(MKIT_DIR)/make build
@@ -51,4 +44,4 @@ vbump_y:
51 44
 vbump_z:
52 45
 	@$(MKIT_DIR)/make vbump_z
53 46
 
54
-.PHONY: all options clean dist rpmstuff install uninstall release_x release_y release_z vbump_x vbump_y vbump_z
47
+.PHONY: all clean dist rpmstuff install uninstall release_x release_y release_z vbump_x vbump_y vbump_z