Browse Source

Update MKit to v0.0.8

Alois Mahdal 8 years ago
parent
commit
5dde43e97e

+ 71
- 19
utils/mkit/include/build.sh View File

@@ -19,17 +19,41 @@ build1() {
19 19
     #
20 20
     # Process one skeleton
21 21
     #
22
-    local srcpath dstpath
23
-    srcpath=$1
24
-    dstpath=${srcpath%.skel}
25
-    case $dstpath in
26
-        *.md) <"$srcpath" expand_includes | expand_variables >"$dstpath" ;;
27
-        *)    <"$srcpath"                   expand_variables >"$dstpath" ;;
28
-    esac
22
+    local srcpath="$1"
23
+    local dstpath="$2"
24
+    local ftype="$3"
25
+    test -n "$dstpath"  || dstpath=${srcpath%.skel}
26
+    test -n "$ftype"    || ftype=$(guess_ftype "$dstpath")
27
+    debug_var srcpath dstpath ftype
28
+    <"$srcpath" build1_ftype "$ftype" >"$dstpath"
29 29
     mkdir -p "$MKIT_LOCAL"
30 30
     echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
31 31
 }
32 32
 
33
+guess_ftype() {
34
+    #
35
+    # Guess file type from destination path $1
36
+    #
37
+    local dstpath="$1"
38
+    case $dstpath in
39
+        *.md) echo markdown    ;;
40
+        *)    echo MKIT_COMMON ;;
41
+    esac
42
+}
43
+
44
+build1_ftype() {
45
+    #
46
+    # Build a file of type $1
47
+    #
48
+    local ftype="$1"
49
+    case $ftype in
50
+        MKIT_COMMON)    expand_variables "vars" ;;
51
+        markdown)       expand_includes | expand_variables "vars" ;;
52
+        rpmstuff)       expand_variables "vars" "rpmstuff:vars" ;;
53
+        *)              die "unknown file type: $ftype" ;;
54
+    esac
55
+}
56
+
33 57
 build_manpages() {
34 58
     local manfile mdfile
35 59
     if command -v ronn >/dev/null;
@@ -64,16 +88,32 @@ dist() {
64 88
     #
65 89
     # Create distributable tarball
66 90
     #
91
+    #FIXME: lacking Makefile skills, we do this step twice fot
92
+    #       rpmstuff, hence -f hack for gzip
93
+    #
67 94
     local version=$(get_version)
68 95
     local dirname=$MKIT_PKGNAME-$version
69 96
     mkdir -p "$dirname"
70 97
     ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
71 98
     sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
72 99
     tar -cf "$dirname.tar" "$dirname"
73
-    gzip "$dirname.tar"
100
+    gzip -f "$dirname.tar"      # see above FIXME
101
+    mkdir -p "$MKIT_LOCAL"
102
+    echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
74 103
     rm -rf "$dirname"
75 104
 }
76 105
 
106
+rpmstuff() {
107
+    #
108
+    # Build specfile
109
+    #
110
+    local specname="$(ini 1value ENV:PKGNAME).spec"
111
+    local specsrc="$(ini 1value "rpmstuff:spec_skel")"
112
+    test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
113
+    test -f "$specsrc" || die "specfile template not found: $specsrc"
114
+    build1 "$specsrc" "$specname"
115
+}
116
+
77 117
 expand_includes() {
78 118
     #
79 119
     # Expand include directives
@@ -101,19 +141,24 @@ expand_includes() {
101 141
 
102 142
 expand_variables() {
103 143
     #
104
-    # Expand variable values
144
+    # Expand variables from sections $@
105 145
     #
106 146
     local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
107
-    local varname varvalue
108
-    ini lskeys "vars" \
109
-      | while read varname;
110
-        do
111
-            varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
112
-            echo "s|$varname|$varvalue|;" >> "$script"
113
-        done
147
+    local section varname varvalue
148
+    for section in "$@";
149
+    do
150
+        debug_var section
151
+        ini lskeys "$section" \
152
+          | while read varname;
153
+            do
154
+                varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
155
+                echo "s|$varname|$varvalue|;" >> "$script"
156
+                debug_var varname varvalue
157
+            done
158
+    done
114 159
     echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
115 160
     echo "s|__VERSION__|$(get_version)|;" >> "$script"
116
-    perl -wp "$script"
161
+    perl -wp "$script" || die "expand_variables failed"
117 162
     rm "$script"
118 163
 }
119 164
 
@@ -167,7 +212,14 @@ get_version() {
167 212
     grep ":" <<<"$prerl" && warn "colon in PRERELEASE may corrupt version data: $prerl"
168 213
     if git rev-parse HEAD >&/dev/null;
169 214
     then    # we are in git repo... so we can get smart
170
-        local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
215
+        local latest_tag=$(
216
+            git log --format="%D" \
217
+              | sed 's/,/\n/g' \
218
+              | sed 's/^[[:blank:]]*//; ' \
219
+              | grep -E '^tag: v[[:digit:]]+\.' \
220
+              | cut -d' ' -f2 \
221
+              | head -1
222
+        )
171 223
         if ! git describe --tags --exact-match HEAD >&/dev/null;
172 224
         then    # we are at a later commit than the last tag
173 225
             local sha=g$(git log -1 --pretty=format:%h HEAD)
@@ -178,7 +230,7 @@ get_version() {
178 230
         then    # the tree is "dirty", i.e. has been edited
179 231
             local dirty=dirty
180 232
         fi
181
-        test -n "$lasttag" && version=${lasttag:1}
233
+        test -n "$latest_tag" && version=${latest_tag:1}
182 234
         local suffix=""
183 235
         case "$commit:$dirty" in
184 236
             :)       suffix=""                ;;

+ 22
- 14
utils/mkit/include/deploy.sh View File

@@ -1,12 +1,17 @@
1 1
 #!/bin/bash
2 2
 
3
-
4
-check_env() {
5
-    #
6
-    # Check that environment variables have been set properly
7
-    #
8
-    PREFIX="$(readlink -m "$PREFIX")"
9
-    test -d "$PREFIX" || die "PREFIX points to non-existent directory: $PREFIX"
3
+_maybe() {
4
+    #
5
+    # Call the deploy command $1 $@ unless in dry mode
6
+    #
7
+    debug "$@"
8
+    local cmd="$1"; shift
9
+    $MKIT_DRY && return
10
+    case "$cmd" in
11
+        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
12
+        install)                 command -p install "$@" ;;
13
+        *)                       die "bad command called";;
14
+    esac
10 15
 }
11 16
 
12 17
 deploy_item() {
@@ -37,10 +42,15 @@ deploy_item() {
37 42
     local mode="${3:-$MKIT_DEFAULT_MODE}"
38 43
     if test -d "$src";
39 44
     then
40
-        cp -Tvr "$src" "$dst"
41
-        find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
45
+        _maybe mkdir -vp "$(dirname "$dst")"
46
+        _maybe cp -Tvr "$src" "$dst"
47
+        find "$dst" -type f \
48
+          | while read chmod_item;
49
+            do
50
+                _maybe chmod "$mode" "$chmod_item"
51
+            done
42 52
     else
43
-        command -p install -DTvm "$mode" "$src" "$dst"
53
+        _maybe install -DTvm "$mode" "$src" "$dst"
44 54
     fi
45 55
 }
46 56
 
@@ -60,14 +70,13 @@ get_root() {
60 70
     local grp="$1"
61 71
     local root=$(ini 1value "roots:$grp")
62 72
     test -n "$root" || die "missing in config.ini: roots:$grp"
63
-    echo "$root"
73
+    echo "$(ini 1value ENV:DESTDIR)$root"
64 74
 }
65 75
 
66 76
 install() {
67 77
     #
68 78
     # Install product
69 79
     #
70
-    check_env
71 80
     local dst group mode src
72 81
     ini values "lists:group" \
73 82
       | while read group;
@@ -88,7 +97,6 @@ uninstall() {
88 97
     #
89 98
     # Uninstall product
90 99
     #
91
-    check_env
92 100
     local dst group src
93 101
     ini values "lists:group" \
94 102
       | while read group;
@@ -97,7 +105,7 @@ uninstall() {
97 105
               | while read src;
98 106
                 do
99 107
                     dst=$(get_dst "$group" "$src")
100
-                    rm -vrf "$dst"
108
+                    _maybe rm -vrf "$dst"
101 109
                 done
102 110
         done
103 111
 }

+ 1
- 0
utils/mkit/include/ini.sh View File

@@ -8,6 +8,7 @@ ini() {
8 8
     local arg=$2
9 9
     local fn
10 10
     local limit=_ini_cat
11
+    debug_var op arg
11 12
     case $op in
12 13
         lskeys) fn=_ini_lskeys   ;;
13 14
         sec)    fn=_ini_grepsec  ;;

+ 27
- 2
utils/mkit/include/mkit.sh View File

@@ -5,6 +5,31 @@
5 5
 . "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
6 6
 . "$MKIT_DIR/include/ini.sh"    || die "cannot import ini.sh"
7 7
 
8
+debug() {
9
+    #
10
+    # Print debug message
11
+    #
12
+    $MKIT_DEBUG || return 0
13
+    echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
14
+}
15
+
16
+debug_var() {
17
+    #
18
+    # Print debug message
19
+    #
20
+    $MKIT_DEBUG || return 0
21
+    local __mkit_debug_var_name__
22
+    for __mkit_debug_var_name__ in "$@";
23
+    do
24
+        {
25
+            echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
26
+            echo -n " $__mkit_debug_var_name__"
27
+            echo -n "='${!__mkit_debug_var_name__}'"
28
+            echo
29
+        } >&2
30
+    done
31
+}
32
+
8 33
 MKIT_INI=${MKIT_INI:-mkit.ini}
9 34
 MKIT_INI_EXPAND=2
10 35
 MKIT_PKGNAME=$(ini 1value "ENV:PKGNAME")
@@ -46,10 +71,10 @@ route() {
46 71
     # Call correct function based on $1
47 72
     #
48 73
     case $1 in
49
-        build|build_manpages|clean|dist|install|release_?|uninstall)
74
+        build|build_manpages|clean|dist|rpmstuff|install|release_?|uninstall|vbump_?)
50 75
             $1
51 76
             ;;
52 77
         *)
53
-            echo "usage: $(basename "$0") build|clean|dist|install|uninstall" >&2
78
+            echo "usage: $(basename "$0") build|clean|dist|rpmstuff|install|uninstall" >&2
54 79
     esac
55 80
 }

+ 116
- 30
utils/mkit/include/release.sh View File

@@ -1,5 +1,76 @@
1 1
 #!/bin/bash
2 2
 
3
+__die_if() {
4
+    #
5
+    # Die if blocking condition $1 is detected
6
+    #
7
+    local condition="$1"
8
+    local x
9
+    case "$condition" in
10
+        nogit)
11
+            git rev-parse HEAD >&/dev/null\
12
+             || die "cannot do this outside git repo"
13
+            ;;
14
+        norelbr)
15
+            __git_info curbranch \
16
+              | grep -qFx "$RELSRC" \
17
+             || die "you are not on RELSRC branch: $RELSRC"
18
+            ;;
19
+        dirty)
20
+            git diff --shortstat 2>/dev/null \
21
+              | grep -q . \
22
+             && die "tree is dirty: $dirt"
23
+            ;;
24
+        novertag)
25
+            __git_info lasttag \
26
+              | grep -q . \
27
+             || die "cannot find last tag"
28
+            ;;
29
+        nobump)
30
+            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"
33
+            ;;
34
+        wip)
35
+            __git_info reldiff \
36
+              | grep '^....... WIP ' \
37
+             && die "WIP commit since $(__git_info lasttag)"
38
+            ;;
39
+        old_c)
40
+            x=$(__ver_info nextver_g)
41
+            __ver_info currver_c \
42
+              | grep -qFx "$x" \
43
+             || die "new version not in config.mk: $x"
44
+            ;;
45
+    esac
46
+}
47
+
48
+__git_info() {
49
+    #
50
+    # Get git info $1
51
+    #
52
+    local info="$1"
53
+    case "$info" in
54
+        lasttag)    git tag | grep ^v | sort -V | tail -n1  ;;
55
+        curbranch)  git rev-parse --abbrev-ref HEAD         ;;
56
+        reldiff)    git log --oneline "$(__git_info lasttag)..HEAD" ;;
57
+    esac
58
+}
59
+
60
+__ver_info() {
61
+    #
62
+    # Get git info $1
63
+    #
64
+    local info="$1"
65
+    case "$info" in
66
+        lastver_g)  __git_info lasttag | sed s/^v// ;;
67
+        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 ;;
70
+        nextver_c)  __make_ver "$level" "$(__ver_info currver_c)" ;;
71
+    esac
72
+}
73
+
3 74
 __make_ver() {
4 75
     local level=$1
5 76
     local old=$2
@@ -27,43 +98,58 @@ __release() {
27 98
     #        compatible with this release strategy
28 99
     #
29 100
     local level=$1
30
-    git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
31
-    local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
32
-    local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
33
-    local changelog="$(git log --oneline "$lasttag..HEAD")"
34
-    local curbranch=$(git rev-parse --abbrev-ref HEAD)
35
-    local dirt="$(git diff --shortstat 2>/dev/null)"
101
+    local newtag
36 102
 
37
-    local newver=$(__make_ver "$level" "${lasttag#v}")
38
-    local newtag=v$newver
39
-    local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
103
+    __die_if nogit
104
+    __die_if norelbr
105
+    __die_if dirty
106
+    __die_if novertag
107
+    __die_if nobump
108
+    __die_if wip
109
+    __die_if old_c
40 110
 
41
-    test "$lastfile" = config.mk \
42
-     || die "last change must be version bump in config.mk"
43
-
44
-    test -n "$lasttag" \
45
-     || die "cannot find last tag"
46
-
47
-    test "$newtag" = "$higher" \
48
-     || die "generated tag looks older: $oldtag<$newtag"
49
-
50
-    grep -qw "$newver" config.mk \
51
-     || die "new version not in config.mk: $newver"
111
+    newtag=v$(__ver_info nextver_g)
112
+    set -e
113
+    debug_var newtag
114
+    $MKIT_DRY && return
115
+    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
116
+    git branch -f "$RELDST" "$newtag"
117
+}
52 118
 
53
-    grep '^....... WIP ' <<<"$changelog" \
54
-     && die "WIP commit since $lasttag"
119
+__git_msg_vbump() {
120
+    echo "Bump version"
121
+    echo ""
122
+    __git_info reldiff | sed 's/^/ *  /'
123
+}
55 124
 
56
-    grep -qw "$curbranch" <<<"$RELSRC" \
57
-     || die "you are not on RELSRC branch: $RELSRC"
125
+__vbump() {
126
+    local level="$1"
127
+    local lastver   # current from config.mk
128
+    local nextver   # after the bump
129
+    __die_if nogit
130
+    __die_if norelbr
131
+    __die_if dirty
132
+    lastver=$(__ver_info currver_c)
133
+    nextver=$(__ver_info nextver_c)
134
+    debug_var lastver nextver
135
+    $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"
140
+    git commit -e -m "$(__git_msg_vbump)"
141
+}
58 142
 
59
-    test -z "$dirt" \
60
-     || die "tree is dirty: $dirt"
143
+vbump_x() {
144
+    __vbump x
145
+}
61 146
 
62
-    # FIXME: Have user prepare proper message with changelog
147
+vbump_y() {
148
+    __vbump y
149
+}
63 150
 
64
-    set -e
65
-    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
66
-    git branch -f "$RELDST" "$newtag"
151
+vbump_z() {
152
+    __vbump z
67 153
 }
68 154
 
69 155
 release_x() {

+ 3
- 1
utils/mkit/make View File

@@ -6,10 +6,12 @@ die() {
6 6
     echo "$@" && exit 9
7 7
 }
8 8
 
9
-export MKIT_VERSION=0.0.3
9
+export MKIT_VERSION=0.0.8
10 10
 
11 11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
12 12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
13
+export MKIT_DRY=${MKIT_DRY:-false}
14
+export MKIT_DEBUG=${MKIT_DEBUG:-false}
13 15
 
14 16
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
15 17
 

+ 14
- 1
utils/mkit/mkit.mk View File

@@ -9,6 +9,7 @@ options:
9 9
 	@echo build options:
10 10
 	@echo "VERSION  = ${VERSION}"
11 11
 	@echo "PRERELEASE = ${PRERELEASE}"
12
+	@echo "DESTDIR   = ${DESTDIR}"
12 13
 	@echo "PREFIX   = ${PREFIX}"
13 14
 
14 15
 build:
@@ -23,6 +24,9 @@ clean:
23 24
 dist: clean
24 25
 	@$(MKIT_DIR)/make dist
25 26
 
27
+rpmstuff: dist
28
+	@$(MKIT_DIR)/make rpmstuff
29
+
26 30
 install: all
27 31
 	@$(MKIT_DIR)/make install
28 32
 
@@ -38,4 +42,13 @@ release_z:
38 42
 uninstall:
39 43
 	@$(MKIT_DIR)/make uninstall
40 44
 
41
-.PHONY: all options clean dist install uninstall release_x release_y release_z
45
+vbump_x:
46
+	@$(MKIT_DIR)/make vbump_x
47
+
48
+vbump_y:
49
+	@$(MKIT_DIR)/make vbump_y
50
+
51
+vbump_z:
52
+	@$(MKIT_DIR)/make vbump_z
53
+
54
+.PHONY: all options clean dist rpmstuff install uninstall release_x release_y release_z vbump_x vbump_y vbump_z