Quellcode durchsuchen

Update MKit to v0.0.40

Alois Mahdal vor 6 Jahren
Ursprung
Commit
7292a6539f

+ 1
- 1
mkit.ini Datei anzeigen

@@ -61,4 +61,4 @@
61 61
     share   = src/help
62 62
     share   = src/complete
63 63
 
64
-#mkit version=0.0.35
64
+#mkit version=0.0.40

+ 1
- 1
packaging/debian/control Datei anzeigen

@@ -29,4 +29,4 @@ Depends:
29 29
  shellfu-bash-saturnin (<< __VDEP_SATURNIN_LT__),
30 30
 Description: __MKIT_PROJ_TAGLINE__
31 31
 
32
-# control file built with MKit __MKIT_SELF_VERSION__
32
+# control file built with MKit __MKIT_MKIT_VERSION__

+ 1
- 1
packaging/template.spec Datei anzeigen

@@ -43,4 +43,4 @@ make %{?_smp_mflags} PREFIX=/usr
43 43
 
44 44
 %changelog
45 45
 
46
-# specfile built with MKit __MKIT_SELF_VERSION__
46
+# specfile built with MKit __MKIT_MKIT_VERSION__

+ 30
- 9
utils/mkit/include/build.sh Datei anzeigen

@@ -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
 

+ 1
- 1
utils/mkit/include/deploy.sh Datei anzeigen

@@ -35,7 +35,7 @@ __deploy_item() {
35 35
         find "$src" -type f \
36 36
           | while read -r item; do
37 37
                 [[ $item =~ .skel$ ]] \
38
-                 && grep -q "${item%.skel}" "$MKIT_LOCAL/built.lst" \
38
+                 && grep -qe "${item%.skel}" "$MKIT_LOCAL/built.lst" \
39 39
                  && continue
40 40
                 __deploy_item "$item" "$dst${item#$src}" "$mode"
41 41
             done

+ 42
- 17
utils/mkit/include/facts.sh Datei anzeigen

@@ -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

+ 53
- 15
utils/mkit/include/ini.sh Datei anzeigen

@@ -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
 
@@ -126,10 +164,10 @@ __ini_body() {
126 164
     local inc                       # file to include
127 165
     local incre='\[INCLUDE:.*\]'    # include directive regex
128 166
     local iline                     # include directive line
129
-    if iline=$(grep -m1 -x "$incre" "$MKIT_INI"); then
167
+    if iline=$(grep -m1 -xe "$incre" "$MKIT_INI"); then
130 168
         inc=${iline#*:}; inc=${inc%]}
131
-        grep -vx "$incre" "$inc"
132
-        grep -vx "$incre" "$MKIT_INI"
169
+        grep -vxe "$incre" "$inc"
170
+        grep -vxe "$incre" "$MKIT_INI"
133 171
     else
134 172
         cat "$MKIT_INI"
135 173
     fi | __ini_grepcmt

+ 5
- 4
utils/mkit/include/release.sh Datei anzeigen

@@ -44,7 +44,7 @@ __relck() {
44 44
         at_relsrc)
45 45
             oracle=$(ini 1value project:relsrc)
46 46
             git_fact current_branch \
47
-              | grep -qFx "$oracle" \
47
+              | grep -qFxe "$oracle" \
48 48
              || die "you are not on release source branch: $oracle"
49 49
             ;;
50 50
         not_dirty)
@@ -70,7 +70,7 @@ __relck() {
70 70
         ini_version)
71 71
             oracle=$(git_fact latest_version | __bump_version "$rlevel")
72 72
             ini 1value project:version  \
73
-              | grep -qFx "$oracle" \
73
+              | grep -qFxe "$oracle" \
74 74
              || die "new version not in mkit.ini: $oracle"
75 75
             ;;
76 76
         *)
@@ -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 Datei anzeigen

@@ -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.35
89
+MKIT_VERSION=0.0.40

+ 3
- 3
utils/mkit/stub Datei anzeigen

@@ -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)
@@ -686,7 +686,7 @@ main() {
686 686
     esac
687 687
     updating && init_from_existing
688 688
     if test -n "$License"; then
689
-        known_licenses | grep -qxF "$License" \
689
+        known_licenses | grep -qxFe "$License" \
690 690
          || die "unknown license (use -L to get list): $License"
691 691
         MkLicense=true
692 692
     fi