Przeglądaj źródła

Update own dogfood

Alois Mahdal 6 lat temu
rodzic
commit
77bfff14f0

+ 60
- 9
utils/mkit/include/build.sh Wyświetl plik

@@ -17,7 +17,7 @@ __build1() {
17 17
     test -n "$ftype"    || ftype=$(__guess_ftype "$dstpath")
18 18
     debug_var srcpath dstpath ftype
19 19
     <"$srcpath" __build1_ftype "$ftype" >"$dstpath"
20
-    rec_built "$dstpath"
20
+    __rec_built "$dstpath"
21 21
 }
22 22
 
23 23
 __build1_ftype() {
@@ -59,8 +59,8 @@ __expand_tokens() {
59 59
         echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | __qfs)|g;"
60 60
         echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | __qfs)|g;"
61 61
         echo "s|__MKIT_PROJ_VCS_BROWSER__|$(ini 1value project:vcs_browser | __qfs)|g;"
62
-        echo "s|__MKIT_PROJ_GIT_LASTHASH__|$(git_lasthash | __qfs)|g;"
63
-        echo "s|__MKIT_PROJ_VERSION__|$(semver | __qfs)|g;"
62
+        echo "s|__MKIT_PROJ_GIT_LASTHASH__|$(__cached git_lasthash | __qfs)|g;"
63
+        echo "s|__MKIT_PROJ_VERSION__|$(__cached semver | __qfs)|g;"
64 64
         echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
65 65
     } >> "$script"
66 66
     sed -f "$script" || die "__expand_tokens failed"
@@ -87,6 +87,58 @@ __qfs() {
87 87
     '
88 88
 }
89 89
 
90
+__cached() {
91
+    #
92
+    # Cached value $1 of function $1()
93
+    #
94
+    # In order to support git-less builds, some values might be cached
95
+    # in $MKIT_LOCAL.  This function gets file $1 from that cache (cache
96
+    # hit) or re-creates it (cache miss), but prints its body in either
97
+    # case.
98
+    #
99
+    # The command to re-create file is the same as the key (ie. no
100
+    # arguments).
101
+    #
102
+    local name=$1
103
+    __local_get "$name" && return 0
104
+    "$name" | __local_putb "$name"
105
+    __local_get "$name"
106
+}
107
+
108
+__local_putb() {
109
+    #
110
+    # Make file $1 in $MKIT_LOCAL from stdin and mark as built
111
+    #
112
+    local fpath=$1
113
+    __local_put "$fpath" && __rec_built "$MKIT_LOCAL/$fpath"
114
+}
115
+
116
+__local_put() {
117
+    #
118
+    # Make file $1 in $MKIT_LOCAL from stdin
119
+    #
120
+    local fpath="$MKIT_LOCAL/$1"
121
+    { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
122
+     || die "cannot write to local cache: $fpath"
123
+}
124
+
125
+__local_get() {
126
+    #
127
+    # Read file $1 in $MKIT_LOCAL
128
+    #
129
+    local fpath="$MKIT_LOCAL/$1"
130
+    cat "$fpath" 2>/dev/null
131
+}
132
+
133
+__rec_built() {
134
+    #
135
+    # Record file $1 for deletion on `clean`
136
+    #
137
+    local file=$1
138
+    mkdir -p "$MKIT_LOCAL"
139
+    echo "$file" >> "$MKIT_LOCAL/built.lst"
140
+}
141
+
90 142
 _mkit_data() {
91 143
     #
92 144
     # Build sampler showing all token values
@@ -125,7 +177,6 @@ build() {
125 177
     # Add meat to all skeletons
126 178
     #
127 179
     local srcpath   # each source path
128
-    semver >/dev/null
129 180
     find . -type f -name '*.skel' \
130 181
      | while read -r srcpath; do
131 182
            __build1 "$srcpath"
@@ -153,14 +204,14 @@ debstuff() {
153 204
     local debian_skel   # 'debian' folder skeleton
154 205
     local dfsrc         # each source file from ^^
155 206
     local dftgt         # each built packaging file
156
-    version=$(semver)
207
+    version=$(__cached semver)
157 208
 
158 209
     # tarball - we should already have by means of 'dist'
159 210
     #
160 211
     mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
161 212
        "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
162 213
      || die "could not rename tarball"
163
-    rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
214
+    __rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
164 215
 
165 216
     # read content of each mandatory file from debian_skel
166 217
     #
@@ -174,7 +225,7 @@ debstuff() {
174 225
             mkdir -p "$(dirname "$dftgt")"
175 226
             __build1 "$dfsrc" "$dftgt" debstuff
176 227
         done
177
-    rec_built debian
228
+    __rec_built debian
178 229
 }
179 230
 
180 231
 dist() {
@@ -192,12 +243,12 @@ dist() {
192 243
     git_lasthash=$(git_lasthash)
193 244
     mkdir -p "$dirname"
194 245
     ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
195
-    update_version "$version" "$dirname/mkit.ini"
196 246
     mkdir -p "$dirname/.mkit"
247
+    echo -n "$version" > "$dirname/.mkit/semver"
197 248
     echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
198 249
     tar -cf "$dirname.tar" "$dirname"
199 250
     gzip -f "$dirname.tar"      # see above FIXME
200
-    rec_built "$dirname.tar.gz"
251
+    __rec_built "$dirname.tar.gz"
201 252
     rm -rf "$dirname"
202 253
 }
203 254
 

+ 53
- 62
utils/mkit/include/facts.sh Wyświetl plik

@@ -85,100 +85,91 @@ git_lasthash() {
85 85
     #
86 86
     # Show last commit hash (with .dirty suffix if needed)
87 87
     #
88
-    # If outside git repo, get it from .mkit/git_lasthash, which
89
-    # should have been put there by dist target.  (I.e., this won't
90
-    # work if you got outside the git repo in other way than dist
91
-    # target, but that's actually expected.)
88
+    # We can't do it outside git repo (or without git) but we should
89
+    # not be asked to; targets that don't require git should make use
90
+    # of cache built by dist target.
92 91
     #
93 92
     local last_hash     # last commit hash
94
-    if git_present; then    # we are in git repo
95
-        last_hash=$(git rev-parse HEAD)
96
-        echo -n "$last_hash"
97
-        git_bool dirty && echo -n ".dirty"
98
-    else    # we are outside (eg. distributor's build dir')
99
-        grep . .mkit/git_lasthash || {
100
-            echo UNKNOWN
101
-            warn "malformed source, could not determine git hash"
102
-        }
103
-    fi
93
+    git_present || {
94
+        echo UNKNOWN_HASH
95
+        warn "no git present; could not determine last hash"
96
+        return 3
97
+    }
98
+    last_hash=$(git rev-parse HEAD)
99
+    echo -n "$last_hash"
100
+    git_bool dirty && echo -n ".dirty"
104 101
 }
105 102
 
106 103
 semver() {
107 104
     #
108
-    # Build semver version string with build metadata
105
+    # Build proper SemVer version string
109 106
     #
110 107
     # Build version string from available info using following
111 108
     # logic:
112 109
     #
113
-    #  1. use project.version (from mkit.ini)
114
-    #  2. if we are in git, override the version with last tag
115
-    #  3. if set, add project:prerl (from mkit.ini) as pre-release ID
110
+    #  1. Use version from last git tag (or mkit.ini if there is no
111
+    #     tag, which is possible on new project)
112
+    #  2. if set, add project:prerl (from mkit.ini) as pre-release ID
116 113
     #     (afer dash)
117
-    #  4. if we are at a later commit than the last tag, add branch
114
+    #  3. if we are at a later commit than the last tag, add branch
118 115
     #     name and commit sha1 to build metadata (after plus sign)
119
-    #  5. if the tree is "dirty", i.e. has uncommited changes,
116
+    #  4. if the tree is "dirty", i.e. has uncommited changes,
120 117
     #     add "dirty" to build metadata
121 118
     #
122 119
     # The version is compatible with SemVer 2.0.0.
123 120
     #
124 121
     # Examples:
125 122
     #
126
-    #     myprog v1.0.7                         # all clear
127
-    #     myprog v1.0.7-alpha                   # mkit.ini: project:prerl="alpha"
128
-    #     myprog v1.0.7-alpha+g1aef811.master   # ^^ + some commits after
129
-    #     myprog v1.0.7-alpha+gf14fc4f.api2     # ^^ + on a feature branch
130
-    #     myprog v1.0.7-alpha+gf14fc4f.api2.dirty  # ^^ + tree edited
131
-    #     myprog v1.0.7-alpha+dirty             # tag OK but tree edited
132
-    #     myprog v1.0.7+dirty                   # ^^ but no pre-release id
123
+    #     foo v1.0.7                            # all clear; proper release
124
+    #     foo v1.0.7-beta                       # mkit.ini: project:prerl="beta"
125
+    #     foo v1.0.7-beta+g1aef811.master       # ^^ + some commits after
126
+    #     foo v1.0.7-beta+gf14fc4f.api2         # ^^ + on a feature branch
127
+    #     foo v1.0.7-beta+gf14fc4f.api2.dirty   # ^^ + tree edited
128
+    #     foo v1.0.7-beta+dirty                 # tag OK but tree edited
129
+    #     foo v1.0.7+dirty                      # ^^ but no pre-release id
133 130
     #
134 131
     # Note that versions with "dirty" should be perceived as kind of
135 132
     # dangerous outside developer's own machine.  Versions with sha1 are
136 133
     # safer but must not be released.
137 134
     #
138
-    # I have considered decorating the git commit refs to make them
139
-    # sort of sortable (e.g. "r1.g1aef811"), but on second thought,
140
-    # I don't think it's good idea to give *any* semantics to meta-data
141
-    # at all.  First, there is no rule that r1<r2<r3; a commit can be
142
-    # removing what other just added and one change can be split to
143
-    # multiple commits.  Also, the whole thing breaks anyway once you
144
-    # rebase your branch (no, it's not a sin).  The sole purpose of
145
-    # meta-data is to *identify* the code, and provide safe path back
146
-    # to tree; commit refs are already perfect for that.
147
-    #
148 135
     # FIXME:  Using project:prerl for release IDs may not be compatible with
149 136
     #         release strategy implemented in release.sh
150 137
     #
151
-    local version       # version string (final result)
152
-    local prerl         # pre-release keyword (from mkit.ini, eg. 'alpha')
138
+    local xyz           # base version string
139
+    local prerl         # pre-release keyword (from mkit.ini, eg. 'beta')
153 140
     local latest_tag    # latest git tag
154 141
     local commit        # commit indicator (CURRENT_BRANCH.gHASH)
155 142
     local dirty         # 0 if dirty, 1 if clean
156 143
     local suffix        # version suffix
157
-    local_get semver && return 0
158
-    version=$(ini 1value project:version)
159 144
     prerl=$(ini 1value project:prerl)
160 145
     grep ":" <<<"$prerl" \
161 146
      && warn "colon in project:prerl may corrupt version data: $prerl"
162
-    if git_present;
163
-    then    # we are in git repo... so we can get smart
164
-        latest_tag=$(git_fact latest_tag)
165
-        if ! git describe --tags --exact-match HEAD >&/dev/null;
166
-        then    # we are at a later commit than the last tag
167
-            commit="$(git_fact current_branch).g$(git_fact latest_sha)"
168
-        fi
169
-        git_bool dirty; dirty=$?
170
-        test -n "$latest_tag" && version=${latest_tag:1}
171
-        case "$dirty:$commit" in
172
-            1:)  suffix=""               ;;
173
-            0:)  suffix="+dirty"         ;;
174
-            1:*) suffix="+$commit"       ;;
175
-            0:*) suffix="+$commit.dirty" ;;
176
-            *)   suffix=MKIT_BUG
177
-                 warn "MKIT_BUG: bad dirt/commit detection" ;;
178
-        esac
179
-        test -n "$prerl" && suffix="-$prerl$suffix"
180
-        version="$version$suffix"
147
+    git_present || {
148
+        echo UNKNOWN_VERSION
149
+        warn "no git present; could not determine SemVer"
150
+        return 3
151
+    }
152
+    latest_tag=$(git_fact latest_tag)
153
+    case $latest_tag in
154
+        v*) xyz=${latest_tag:1} ;;
155
+        "") warn "no tags, using base version from mkit.ini (ok for new project)"
156
+            xyz=$(ini 1value project:version) ;;
157
+        *)  warn "bad form of last tag, using base version from mkit.ini: tag is '$latest_tag'"
158
+            xyz=$(ini 1value project:version) ;;
159
+    esac
160
+    if ! git describe --tags --exact-match HEAD >&/dev/null;
161
+    then    # we are at a later commit than the last tag
162
+        commit="$(git_fact current_branch).g$(git_fact latest_sha)"
181 163
     fi
182
-    local_putb semver <<<"$version"
183
-    echo "$version"
164
+    git_bool dirty; dirty=$?
165
+    case "$dirty:$commit" in
166
+        1:)  suffix=""               ;;
167
+        0:)  suffix="+dirty"         ;;
168
+        1:*) suffix="+$commit"       ;;
169
+        0:*) suffix="+$commit.dirty" ;;
170
+        *)   suffix=MKIT_BUG
171
+             warn "MKIT_BUG: bad dirt/commit detection" ;;
172
+    esac
173
+    test -n "$prerl" && suffix="-$prerl$suffix"
174
+    echo "$xyz$suffix"
184 175
 }

+ 0
- 34
utils/mkit/include/mkit.sh Wyświetl plik

@@ -125,31 +125,6 @@ __chkiniversion() {
125 125
      || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
126 126
 }
127 127
 
128
-local_putb() {
129
-    #
130
-    # Make file $1 in $MKIT_LOCAL from stdin and mark as built
131
-    #
132
-    local fpath=$1
133
-    local_put "$fpath" && rec_built "$MKIT_LOCAL/$fpath"
134
-}
135
-
136
-local_put() {
137
-    #
138
-    # Make file $1 in $MKIT_LOCAL from stdin
139
-    #
140
-    local fpath="$MKIT_LOCAL/$1"
141
-    { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
142
-     || die "cannot write to local cache: $fpath"
143
-}
144
-
145
-local_get() {
146
-    #
147
-    # Read file $1 in $MKIT_LOCAL
148
-    #
149
-    local fpath="$MKIT_LOCAL/$1"
150
-    cat "$fpath" 2>/dev/null
151
-}
152
-
153 128
 mkit_init() {
154 129
     #
155 130
     # Do basic initialization
@@ -163,15 +138,6 @@ mkit_init() {
163 138
     __chkiniversion
164 139
 }
165 140
 
166
-rec_built() {
167
-    #
168
-    # Record file $1 for deletion on `clean`
169
-    #
170
-    local file=$1
171
-    mkdir -p "$MKIT_LOCAL"
172
-    echo "$file" >> "$MKIT_LOCAL/built.lst"
173
-}
174
-
175 141
 route() {
176 142
     #
177 143
     # Call correct function based on $1

+ 1
- 1
utils/mkit/include/vars.sh Wyświetl plik

@@ -58,4 +58,4 @@ MKIT_PROJ_PKGNAME=""
58 58
 #
59 59
 # This MKit version
60 60
 #
61
-MKIT_VERSION=0.0.27+master.gfa49a61
61
+MKIT_VERSION=0.0.28+master.ge02e222

+ 3
- 12
utils/mkit/stub Wyświetl plik

@@ -141,7 +141,6 @@ deploy() {
141 141
             echo 'Summary:    __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
142 142
             test -n "$VcsBrowser" && echo 'URL:        __MKIT_PROJ_VCS_BROWSER__'
143 143
             $MkLicense && echo "License:    $License"
144
-            echo ''
145 144
             echo 'Source0:    %{name}-%{version}.tar.gz'
146 145
             echo 'BuildArch:  noarch'
147 146
             echo ''
@@ -177,7 +176,8 @@ deploy() {
177 176
             echo 'Section: misc'
178 177
             echo 'Priority: extra'
179 178
             echo 'Standards-Version: 3.9.2'
180
-            echo 'Build-Depends: debhelper (>= 9)'
179
+            echo 'Build-Depends:'
180
+            echo ' debhelper (>= 9),'
181 181
             echo ''
182 182
             echo 'Package: __MKIT_PROJ_PKGNAME__'
183 183
             echo 'Architecture: all'
@@ -245,7 +245,6 @@ deploy() {
245 245
             echo "everything, so few things still need to be done manually."
246 246
             echo "This document will guide you throught the rest of the"
247 247
             echo "process."
248
-
249 248
             echo ""
250 249
             echo ""
251 250
             echo "Structure"
@@ -293,7 +292,6 @@ deploy() {
293 292
             echo "    idea!), be prepared that you will need to follow their"
294 293
             echo "    guidelines.  This will most probably mean huge changes"
295 294
             echo "    to these packages or even changes to your workflow."
296
-
297 295
             echo ""
298 296
             echo ""
299 297
             echo "Placeholders"
@@ -357,7 +355,6 @@ deploy() {
357 355
             echo "    Typical example of a role is e.g. 'bin' for commands"
358 356
             echo "    (normally under '/usr/bin' or '/usr/local/bin'), 'doc'"
359 357
             echo "    for documents or 'lib' for libraries."
360
-
361 358
             echo ""
362 359
             echo " 2. Next, in \`[roots]\` section, you have to set target"
363 360
             echo "    root directory for each role.  However, in order to"
@@ -366,7 +363,6 @@ deploy() {
366 363
             echo "    environment variable.  For this reason, most paths"
367 364
             echo "    need to start with \`[ENV:PREFIX]\`."
368 365
             echo ""
369
-
370 366
             echo " 3. \`[files]\` section is where you assign actual files"
371 367
             echo "    from your repository to their final paths.  The format"
372 368
             echo "    is \`ROLE = REPOPATH [RENAMED]\`, where ROLE is file's"
@@ -381,12 +377,10 @@ deploy() {
381 377
             echo "    individually, if in your repo you have a directory with"
382 378
             echo "    100 files of the same role, you can add just path to the"
383 379
             echo "    directory itself."
384
-
385 380
             echo ""
386 381
             echo " 4. If some roles require special permissions on your files,"
387 382
             echo "    \`[modes]\` section is your friend.  Permissions here"
388 383
             echo "    should be in UNIX octal format."
389
-
390 384
             echo ""
391 385
             echo " 5. Next, \`[tokens]\` section allows you to define own"
392 386
             echo "    placeholders that will be replaced when your scripts are"
@@ -396,7 +390,6 @@ deploy() {
396 390
             echo "    defined here, plus range of tokens automatically defined"
397 391
             echo "    by MKit.  During build, these tokens are replaced with"
398 392
             echo "    their actual values."
399
-
400 393
             echo ""
401 394
             echo " 6. Less interesting, but important section is \`[dist]\`,"
402 395
             echo "    which lists files in your codebase that will be added"
@@ -404,14 +397,12 @@ deploy() {
404 397
             echo "    above).  Listing directory here will include all its"
405 398
             echo "    contents, and normally it's OK to be very inclusive, so"
406 399
             echo "    most of the time this section should be OK."
407
-
408 400
             echo ""
409 401
             echo " 7. Even less interesting is section \`[ENV]\`.  It is"
410 402
             echo "    special in that it provides *default* value for an"
411 403
             echo "    environment variable.  You almost never need to touch"
412 404
             echo "    this."
413 405
             echo ""
414
-
415 406
             echo " 8. Finally, the most interesting section!  \`[project]\`,"
416 407
             echo "    provides most general information for your project such"
417 408
             echo "    as name and version."
@@ -494,7 +485,7 @@ usage() {
494 485
         echo "    -R            skip creating README.md"
495 486
         echo "    -M            skip creating Makefile"
496 487
         echo "    -P            skip creating packaging templates"
497
-        echo "    -L            list know licenses and exit"
488
+        echo "    -L            list known licenses and exit"
498 489
         echo ""
499 490
         echo "PKGNAME should be packaging-friendly name, ie. consist"
500 491
         echo "only of small letters, numbers, underscore and dash."