Browse Source

Update MKit to v0.0.40

Alois Mahdal 7 years ago
parent
commit
08bb345c8e

+ 1
- 1
mkit.ini View File

@@ -41,4 +41,4 @@
41 41
     share   = src/imapdomo.lua
42 42
     share   = src/main.lua
43 43
 
44
-#mkit version=0.0.34
44
+#mkit version=0.0.40

+ 1
- 1
packaging/debian/control View File

@@ -19,4 +19,4 @@ Description: __MKIT_PROJ_TAGLINE__
19 19
  adds few more Lua functions and suggests some system to way how you can
20 20
  organize your mail filtering and/or migrations, etc.
21 21
 
22
-# control file built with MKit __MKIT_SELF_VERSION__
22
+# control file built with MKit __MKIT_MKIT_VERSION__

+ 1
- 1
packaging/template.spec View File

@@ -34,4 +34,4 @@ make %{?_smp_mflags}
34 34
 
35 35
 %changelog
36 36
 
37
-# specfile built with MKit __MKIT_SELF_VERSION__
37
+# specfile built with MKit __MKIT_MKIT_VERSION__

+ 30
- 9
utils/mkit/include/build.sh View File

@@ -71,6 +71,7 @@ __expand_macros() {
71 71
     local line          # each line on stdin
72 72
     local mname         # each macro name
73 73
     local -A MacroMap   # macro value map
74
+    MacroMap[__MKIT_MKIT_VERSION__]=$MKIT_VERSION
74 75
     MacroMap[__MKIT_PROJ_NAME__]=$(ini 1value project:name)
75 76
     MacroMap[__MKIT_PROJ_CODENAME__]=$(ini 1value project:codename)
76 77
     MacroMap[__MKIT_PROJ_LICENSE__]=$(ini 1value project:license)
@@ -79,8 +80,8 @@ __expand_macros() {
79 80
     MacroMap[__MKIT_PROJ_MAINTAINER__]=$(ini 1value project:maintainer)
80 81
     MacroMap[__MKIT_PROJ_VCS_BROWSER__]=$(ini 1value project:vcs_browser)
81 82
     MacroMap[__MKIT_PROJ_GIT_LASTHASH__]=$(__cached git_lasthash)
83
+    MacroMap[__MKIT_PROJ_GIT_LASTSUMMARY__]=$(__cached git_lastsummary)
82 84
     MacroMap[__MKIT_PROJ_VERSION__]=$(__cached semver)
83
-    MacroMap[__MKIT_SELF_VERSION__]=$MKIT_VERSION
84 85
     for section in "$@"; do
85 86
         for mname in $(ini lskeys "$section"); do
86 87
             MacroMap[$mname]=$(ini values "$section:$mname")
@@ -161,7 +162,7 @@ __rec_built() {
161 162
     #
162 163
     local file=$1
163 164
     mkdir -p "$MKIT_LOCAL"
164
-    echo "$file" >> "$MKIT_LOCAL/built.lst"
165
+    echo "1:$file" >> "$MKIT_LOCAL/built.lst"
165 166
 }
166 167
 
167 168
 _mkit_data() {
@@ -176,6 +177,7 @@ _mkit_data() {
176 177
     sections+=( $(ini lssect | grep ':macros$') )
177 178
     {
178 179
         echo "(builtin):"
180
+        echo "  x_MKIT_MKIT_VERSION__ => '__MKIT_MKIT_VERSION__'"
179 181
         echo "  x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
180 182
         echo "  x_MKIT_PROJ_CODENAME__ => '__MKIT_PROJ_CODENAME__'"
181 183
         echo "  x_MKIT_PROJ_LICENSE__ => '__MKIT_PROJ_LICENSE__'"
@@ -184,8 +186,8 @@ _mkit_data() {
184 186
         echo "  x_MKIT_PROJ_MAINTAINER__ => '__MKIT_PROJ_MAINTAINER__'"
185 187
         echo "  x_MKIT_PROJ_VCS_BROWSER__ => '__MKIT_PROJ_VCS_BROWSER__'"
186 188
         echo "  x_MKIT_PROJ_GIT_LASTHASH__ => '__MKIT_PROJ_GIT_LASTHASH__'"
189
+        echo "  x_MKIT_PROJ_GIT_LASTSUMMARY__ => '__MKIT_PROJ_GIT_LASTSUMMARY__'"
187 190
         echo "  x_MKIT_PROJ_VERSION__ => '__MKIT_PROJ_VERSION__'"
188
-        echo "  x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
189 191
         for section in "${sections[@]}"; do
190 192
             echo "$section:"
191 193
             for macro in $(ini lskeys "$section"); do
@@ -212,12 +214,31 @@ clean() {
212 214
     #
213 215
     # Clean up tree after building
214 216
     #
215
-    test -f "$MKIT_LOCAL/built.lst" && {
216
-        <"$MKIT_LOCAL/built.lst" grep -v -e '\.\.' -e ^/ \
217
-          | xargs -r rm -rf
218
-        rm -f "$MKIT_LOCAL/built.lst"
219
-        rmdir --ignore-fail-on-non-empty "$MKIT_LOCAL"
220
-    }
217
+    local path
218
+    local line
219
+    local depth
220
+    test -f "$MKIT_LOCAL/built.lst" || return 0
221
+    {
222
+        cat "$MKIT_LOCAL/built.lst"
223
+        echo "1:$MKIT_LOCAL/built.lst"
224
+        echo "1:$MKIT_LOCAL"
225
+    } \
226
+      | grep -v -e '\.\.' -e ^/ -e '^~' \
227
+      | while IFS=: read -r depth path; do
228
+            test -e "$path" || continue
229
+            case $depth in
230
+                1)  warn "removing: $path"
231
+                    test -d "$path" \
232
+                     && rmdir -p --ignore-fail-on-non-empty "$path"
233
+                    test -f "$path" && rm "$path"
234
+                    ;;
235
+                r)  warn "removing recursively: $path"
236
+                    rm -r "$path"
237
+                    ;;
238
+                *)  warn "invalid built.lst format!"
239
+                    ;;
240
+            esac
241
+        done
221 242
     true
222 243
 }
223 244
 

+ 42
- 17
utils/mkit/include/facts.sh View File

@@ -103,6 +103,27 @@ git_lasthash() {
103 103
     git_bool dirty && echo -n ".dirty"
104 104
 }
105 105
 
106
+git_lastsummary() {
107
+    #
108
+    # Show last commit summary
109
+    #
110
+    # We can't do it outside git repo (or without git) but we should
111
+    # not be asked to; targets that don't require git should make use
112
+    # of cache built by dist target.
113
+    #
114
+    git_present || {
115
+        echo UNKNOWN_SUMMARY
116
+        warn "no git present; could not determine last summary"
117
+        return 3
118
+    }
119
+    git_bool dirty && {
120
+        echo "(index is dirty)"
121
+        return
122
+    }
123
+    git log -1 --format=oneline HEAD \
124
+      | cut -d' ' -f2-
125
+}
126
+
106 127
 semver() {
107 128
     #
108 129
     # Build proper SemVer version string
@@ -141,15 +162,17 @@ semver() {
141 162
     local xyz           # base version string
142 163
     local prerl         # pre-release keyword (from mkit.ini, eg. 'beta')
143 164
     local latest_tag    # latest git tag
144
-    local commit        # commit indicator (CURRENT_BRANCH.gHASH)
145
-    local dirty=F       # F if dirty, T if clean
146
-    local btime         # timestamp or nothing (see $MKIT_TTAG)
165
+    local brname        # current branch name
166
+    local ghash         # current commit short hash
167
+    local is_tagged=T   # T if tagged (clean, no metadata), F if devel
168
+    local is_dirty=F    # F if dirty, T if clean
169
+    local stamp         # timestamp or nothing (see $MKIT_TSTAMP)
147 170
     local suffix        # version suffix
148 171
     prerl=$(ini 1value project:prerl)
149
-    case $MKIT_TTAG in
150
-        none)   btime= ;;
151
-        btime)  btime=$(date -u +%Y%m%d%H%M%S) ;;
152
-        ctime)  btime=$(date -d @"$(git_fact latest_cdate)" -u +%Y%m%d%H%M%S) ;;
172
+    case $MKIT_TSTAMP in
173
+        none)   stamp= ;;
174
+        btime)  stamp=$(date -u +%Y%m%d%H%M%S) ;;
175
+        ctime)  stamp=$(date -d @"$(git_fact latest_cdate)" -u +%Y%m%d%H%M%S) ;;
153 176
     esac
154 177
     grep ":" <<<"$prerl" \
155 178
      && warn "colon in project:prerl may corrupt version data: $prerl"
@@ -168,17 +191,19 @@ semver() {
168 191
     esac
169 192
     if ! git describe --tags --exact-match HEAD >&/dev/null;
170 193
     then    # we are at a later commit than the last tag
171
-        commit="$(git_fact current_branch).g$(git_fact latest_sha)"
194
+        is_tagged=F
195
+        brname=$(git_fact current_branch | sed 's/[^[:alnum:]]/_/g')
196
+        ghash=$(git_fact latest_sha)
172 197
     fi
173
-    git_bool dirty && dirty=T
174
-    case "$dirty:$btime:$commit" in
175
-        F:*:)   suffix=""                       ;;
176
-        T::)    suffix="+dirty"                 ;;
177
-        T:*:)   suffix="+t$btime.dirty"           ;;
178
-        F::*)   suffix="+$commit"               ;;
179
-        F:*:*)  suffix="+t$btime.$commit"         ;;
180
-        T::*)   suffix="+$commit.dirty"         ;;
181
-        T:*:*)  suffix="+t$btime.$commit.dirty"   ;;
198
+    git_bool dirty && is_dirty=T
199
+    case "$is_dirty:$is_tagged:$stamp" in
200
+        F:T:*)  suffix=""                                 ;;
201
+        T:T:)   suffix="+dirty"                           ;;
202
+        T:T:*)  suffix="+t$stamp.dirty"                   ;;
203
+        F:F:)   suffix="+$brname.g$ghash"                 ;;
204
+        F:F:*)  suffix="+t$stamp.$brname.g$ghash"         ;;
205
+        T:F:)   suffix="+$brname.g$ghash.dirty"           ;;
206
+        T:F:*)  suffix="+t$stamp.$brname.g$ghash.dirty"   ;;
182 207
         *)      suffix=MKIT_BUG
183 208
                 warn "MKIT_BUG: bad dirt/commit detection" ;;
184 209
     esac

+ 50
- 12
utils/mkit/include/ini.sh View File

@@ -8,7 +8,7 @@ __ini_cat() {
8 8
     #
9 9
     local line      # each line
10 10
     while read -r line; do
11
-        printf -- "%s\n" "$line"
11
+        printf -- '%s\n' "$line"
12 12
     done
13 13
 }
14 14
 
@@ -17,19 +17,58 @@ __ini_expand() {
17 17
     # Expand reference value (prefix only)
18 18
     #
19 19
     local line      # each input line
20
-    local suffix    # tail of the line
21
-    local ref       # reference
22
-    local value     # value if reference
23 20
     while read -r line; do                  # [foo:bar]/path
24
-        suffix="${line#\[*\]}"              # /path
25
-        ref="${line%$suffix}"               # [foo:bar]
26
-        ref="${ref%\]}"                     # [foo:bar
27
-        ref="${ref#\[}"                     # foo:bar
28
-        value="$(ini 1value "$ref")"        # foo_bar_value
29
-        printf -- "%s\n" "$value$suffix"    # foo_bar_value/path
21
+        __ini_expandln "$line"
30 22
     done
31 23
 }
32 24
 
25
+__ini_expandln() {
26
+    #
27
+    # Fully expand references in line $1
28
+    #
29
+    local line_orig=$1          # original line
30
+    local line_todo=$line_orig  # current state
31
+    local line_done             # next state
32
+    local Depth=0               # current depth
33
+    local MaxDepth=10           # maximum depth
34
+    while true; do
35
+        ((Depth++))
36
+        debug_var line_todo
37
+        test "$Depth" -le "$MaxDepth" || {
38
+            warn "expansion error: reached maximum depth: $Depth > $MaxDepth"
39
+            warn "    original line: $line_orig"
40
+            warn "    expanded line: $line_todo"
41
+            return 3
42
+        }
43
+        line_done=$(__ini_expandln_once "$line_todo")
44
+        debug_var line_done
45
+        test "$line_done" == "$line_todo" && break
46
+        line_todo=$line_done
47
+    done
48
+    echo "$line_done"
49
+}
50
+
51
+__ini_expandln_once() {
52
+    #
53
+    # Run through line $1 once and replace all references
54
+    #
55
+    local line=$1   # line to expand
56
+    local ref       # full reference (incl. brackets)
57
+    local ipath     # just ini path from ^^ (stripped brackets)
58
+    local value     # value of reference
59
+    local refs=()   # all references found in line
60
+    mapfile -t refs <<<"$(grep -Eo '[[][^]]+[]]' <<< "$line_todo")"
61
+    debug_var refs
62
+    for ref in "${refs[@]}"; do
63
+        test -n "$ref" || continue
64
+        ipath=${ref#[}; ipath=${ipath%]}
65
+        value=$(ini 1value "$ipath")
66
+        debug_var line ref ipath value
67
+        line=$(sed "s|\\[$ipath\\]|$value|" <<<"$line")
68
+    done
69
+    echo "$line"
70
+}
71
+
33 72
 __ini_grepcmt() {
34 73
     #
35 74
     # Remove comments from INI file on stdin
@@ -85,7 +124,7 @@ __ini_grepsec() {
85 124
                 \[*\])    ok=false; continue ;;
86 125
             esac
87 126
             $ok || continue
88
-            printf -- "%s\n" "$line"
127
+            printf -- '%s\n' "$line"
89 128
         done \
90 129
       | sed -e 's/ *= */=/; s/ +$//; s/^//;'
91 130
 }
@@ -102,7 +141,6 @@ __ini_lssect() {
102 141
     #
103 142
     # List all section names
104 143
     #
105
-    local arg=$1    # unused argument
106 144
     grep -x '\[.*\]' | sed 's/^.//; s/.$//'
107 145
 }
108 146
 

+ 3
- 2
utils/mkit/include/release.sh View File

@@ -154,7 +154,7 @@ __vbump() {
154 154
     git add mkit.ini \
155 155
       || die "failed to add mkit.ini to the index"
156 156
     cache=$(mktemp -t "mkit._vbump_gitmsg.XXXXXXXX")
157
-    _vbump_gitmsg > "$cache"
157
+    _vbump_gitmsg "$nextver" > "$cache"
158 158
     git commit -e -F "$cache"   # note: reading from stdin will break vim
159 159
     rm "$cache"
160 160
 }
@@ -163,7 +163,8 @@ _vbump_gitmsg() {
163 163
     #
164 164
     # Compose git message template for 'Bump version' commit
165 165
     #
166
-    echo "Bump version"
166
+    local nextver=$1
167
+    echo "Bump version to $nextver"
167 168
     echo ""
168 169
     echo "Overview of changes:"
169 170
     echo ""

+ 3
- 3
utils/mkit/include/vars.sh View File

@@ -71,7 +71,7 @@ MKIT_PROJ_PKGNAME=""
71 71
 # For example, old yum version (as of RHEL-6) will not let you install
72 72
 # version that it deems older than is installed, making it hard to
73 73
 # continually upgrade during active development.  While packaging
74
-# systems have their own rukes (and SemVer says both versions should be
74
+# systems have their own rules (and SemVer says both versions should be
75 75
 # considered same) this tag will make it more likely to "win" the build
76 76
 # you made later.
77 77
 #
@@ -81,9 +81,9 @@ MKIT_PROJ_PKGNAME=""
81 81
 # Also note that 'btime' makes the version non-deterministic: merely
82 82
 # initiating the build a second later will result in different version.
83 83
 #
84
-MKIT_TTAG=${MKIT_TTAG:-ctime}
84
+MKIT_TSTAMP=${MKIT_TSTAMP:-ctime}
85 85
 
86 86
 #
87 87
 # This MKit version
88 88
 #
89
-MKIT_VERSION=0.0.36
89
+MKIT_VERSION=0.0.40

+ 2
- 2
utils/mkit/stub View File

@@ -162,7 +162,7 @@ deploy() {
162 162
             echo ''
163 163
             echo '%changelog'
164 164
             echo ''
165
-            echo '# specfile built with MKit __MKIT_SELF_VERSION__'
165
+            echo '# specfile built with MKit __MKIT_MKIT_VERSION__'
166 166
             ;;
167 167
 
168 168
         packaging/debian/copyright)
@@ -185,7 +185,7 @@ deploy() {
185 185
             echo 'Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
186 186
             echo ' MKIT_STUB_DESCRIPTION'
187 187
             echo ''
188
-            echo '# control file built with MKit __MKIT_SELF_VERSION__'
188
+            echo '# control file built with MKit __MKIT_MKIT_VERSION__'
189 189
             ;;
190 190
 
191 191
         packaging/debian/changelog)