|
|
@@ -1,21 +1,10 @@
|
|
1
|
1
|
#!/bin/bash
|
|
2
|
2
|
|
|
3
|
|
-. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
|
|
|
3
|
+. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
|
|
|
4
|
+. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
|
|
4
|
5
|
|
|
5
|
6
|
|
|
6
|
|
-build() {
|
|
7
|
|
- #
|
|
8
|
|
- # Add meat to all skeletons
|
|
9
|
|
- #
|
|
10
|
|
- local srcpath
|
|
11
|
|
- find src -type f -name '*.skel' \
|
|
12
|
|
- | while read srcpath;
|
|
13
|
|
- do
|
|
14
|
|
- build1 "$srcpath"
|
|
15
|
|
- done
|
|
16
|
|
-}
|
|
17
|
|
-
|
|
18
|
|
-build1() {
|
|
|
7
|
+_build1() {
|
|
19
|
8
|
#
|
|
20
|
9
|
# Process one skeleton
|
|
21
|
10
|
#
|
|
|
@@ -23,14 +12,84 @@ build1() {
|
|
23
|
12
|
local dstpath="$2"
|
|
24
|
13
|
local ftype="$3"
|
|
25
|
14
|
test -n "$dstpath" || dstpath=${srcpath%.skel}
|
|
26
|
|
- test -n "$ftype" || ftype=$(guess_ftype "$dstpath")
|
|
|
15
|
+ test -n "$ftype" || ftype=$(_guess_ftype "$dstpath")
|
|
27
|
16
|
debug_var srcpath dstpath ftype
|
|
28
|
|
- <"$srcpath" build1_ftype "$ftype" >"$dstpath"
|
|
|
17
|
+ <"$srcpath" _build1_ftype "$ftype" >"$dstpath"
|
|
29
|
18
|
mkdir -p "$MKIT_LOCAL"
|
|
30
|
19
|
echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
|
|
31
|
20
|
}
|
|
32
|
21
|
|
|
33
|
|
-guess_ftype() {
|
|
|
22
|
+_build1_ftype() {
|
|
|
23
|
+ #
|
|
|
24
|
+ # Build a file of type $1
|
|
|
25
|
+ #
|
|
|
26
|
+ local ftype="$1"
|
|
|
27
|
+ case $ftype in
|
|
|
28
|
+ MKIT_COMMON) _expand_tokens "tokens" ;;
|
|
|
29
|
+ markdown) _expand_includes | _expand_tokens "tokens" ;;
|
|
|
30
|
+ rpmstuff) _expand_tokens "tokens" "rpmstuff:tokens" ;;
|
|
|
31
|
+ *) die "unknown file type: $ftype" ;;
|
|
|
32
|
+ esac
|
|
|
33
|
+}
|
|
|
34
|
+
|
|
|
35
|
+_expand_includes() {
|
|
|
36
|
+ #
|
|
|
37
|
+ # Expand include directives
|
|
|
38
|
+ #
|
|
|
39
|
+ # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
|
|
|
40
|
+ #
|
|
|
41
|
+ perl -we '
|
|
|
42
|
+ use strict;
|
|
|
43
|
+ my $text;
|
|
|
44
|
+ while (<>) {
|
|
|
45
|
+ chomp;
|
|
|
46
|
+ if (m/<!-- include4: (\S+) -->/) {
|
|
|
47
|
+ open my $fh, $1 or warn "cannot find: $1";
|
|
|
48
|
+ my $text = do { local($/); <$fh> };
|
|
|
49
|
+ close $fh;
|
|
|
50
|
+ $text =~ s/^(.)/ $1/gm;
|
|
|
51
|
+ chomp $text;
|
|
|
52
|
+ print "$text\n";
|
|
|
53
|
+ } else {
|
|
|
54
|
+ print "$_\n";
|
|
|
55
|
+ }
|
|
|
56
|
+ }
|
|
|
57
|
+ '
|
|
|
58
|
+}
|
|
|
59
|
+
|
|
|
60
|
+_expand_tokens() {
|
|
|
61
|
+ #
|
|
|
62
|
+ # Expand tokens from sections $@
|
|
|
63
|
+ #
|
|
|
64
|
+ local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
|
|
|
65
|
+ local section varname varvalue
|
|
|
66
|
+ {
|
|
|
67
|
+ for section in "$@";
|
|
|
68
|
+ do
|
|
|
69
|
+ debug_var section
|
|
|
70
|
+ ini lskeys "$section" \
|
|
|
71
|
+ | while read varname;
|
|
|
72
|
+ do
|
|
|
73
|
+ varvalue="$(ini 1value "$section:$varname" | _qfs )"
|
|
|
74
|
+ echo "s|$varname|$varvalue|g;"
|
|
|
75
|
+ debug_var varname varvalue
|
|
|
76
|
+ done
|
|
|
77
|
+ done
|
|
|
78
|
+ echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | _qfs)|g;"
|
|
|
79
|
+ echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | _qfs)|g;"
|
|
|
80
|
+ echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | _qfs)|g;"
|
|
|
81
|
+ echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | _qfs)|g;"
|
|
|
82
|
+ echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | _qfs)|g;"
|
|
|
83
|
+ echo "s|__MKIT_PROJ_VCS_BROWSER__|$(ini 1value project:vcs_browser | _qfs)|g;"
|
|
|
84
|
+ echo "s|__MKIT_PROJ_GIT_LASTHASH__|$(git_lasthash | _qfs)|g;"
|
|
|
85
|
+ echo "s|__MKIT_PROJ_VERSION__|$(semver | _qfs)|g;"
|
|
|
86
|
+ echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
|
|
|
87
|
+ } >> "$script"
|
|
|
88
|
+ sed -f "$script" || die "_expand_tokens failed"
|
|
|
89
|
+ rm "$script"
|
|
|
90
|
+}
|
|
|
91
|
+
|
|
|
92
|
+_guess_ftype() {
|
|
34
|
93
|
#
|
|
35
|
94
|
# Guess file type from destination path $1
|
|
36
|
95
|
#
|
|
|
@@ -41,17 +100,26 @@ guess_ftype() {
|
|
41
|
100
|
esac
|
|
42
|
101
|
}
|
|
43
|
102
|
|
|
44
|
|
-build1_ftype() {
|
|
|
103
|
+_qfs() {
|
|
45
|
104
|
#
|
|
46
|
|
- # Build a file of type $1
|
|
|
105
|
+ # Quote for our sed scipt's RHS
|
|
47
|
106
|
#
|
|
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
|
|
|
107
|
+ sed '
|
|
|
108
|
+ s:\\:\\\\:g
|
|
|
109
|
+ s:|:\\|:g
|
|
|
110
|
+ '
|
|
|
111
|
+}
|
|
|
112
|
+
|
|
|
113
|
+build() {
|
|
|
114
|
+ #
|
|
|
115
|
+ # Add meat to all skeletons
|
|
|
116
|
+ #
|
|
|
117
|
+ local srcpath
|
|
|
118
|
+ find src -type f -name '*.skel' \
|
|
|
119
|
+ | while read srcpath;
|
|
|
120
|
+ do
|
|
|
121
|
+ _build1 "$srcpath"
|
|
|
122
|
+ done
|
|
55
|
123
|
}
|
|
56
|
124
|
|
|
57
|
125
|
build_manpages() {
|
|
|
@@ -85,30 +153,11 @@ clean() {
|
|
85
|
153
|
true
|
|
86
|
154
|
}
|
|
87
|
155
|
|
|
88
|
|
-dist() {
|
|
89
|
|
- #
|
|
90
|
|
- # Create distributable tarball
|
|
91
|
|
- #
|
|
92
|
|
- #FIXME: lacking Makefile skills, we do this step twice fot
|
|
93
|
|
- # rpmstuff, hence -f hack for gzip
|
|
94
|
|
- #
|
|
95
|
|
- local version=$(get_version)
|
|
96
|
|
- local dirname=$MKIT_PROJ_PKGNAME-$version
|
|
97
|
|
- mkdir -p "$dirname"
|
|
98
|
|
- ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
|
|
99
|
|
- update_version "$version" "$dirname/mkit.ini"
|
|
100
|
|
- tar -cf "$dirname.tar" "$dirname"
|
|
101
|
|
- gzip -f "$dirname.tar" # see above FIXME
|
|
102
|
|
- mkdir -p "$MKIT_LOCAL"
|
|
103
|
|
- echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
|
|
104
|
|
- rm -rf "$dirname"
|
|
105
|
|
-}
|
|
106
|
|
-
|
|
107
|
156
|
debstuff() {
|
|
108
|
157
|
#
|
|
109
|
158
|
# Build Debian stuff (eamed tarball, debian dir)
|
|
110
|
159
|
#
|
|
111
|
|
- local version="$(get_version)"
|
|
|
160
|
+ local version="$(semver)"
|
|
112
|
161
|
|
|
113
|
162
|
# tarball - we should already have by means of 'dist'
|
|
114
|
163
|
#
|
|
|
@@ -129,11 +178,33 @@ debstuff() {
|
|
129
|
178
|
do
|
|
130
|
179
|
dftgt="debian/${dfsrc#$debian_skel}"
|
|
131
|
180
|
mkdir -p "$(dirname "$dftgt")"
|
|
132
|
|
- build1 "$dfsrc" "$dftgt"
|
|
|
181
|
+ _build1 "$dfsrc" "$dftgt"
|
|
133
|
182
|
done
|
|
134
|
183
|
echo debian >> "$MKIT_LOCAL/built.lst"
|
|
135
|
184
|
}
|
|
136
|
185
|
|
|
|
186
|
+dist() {
|
|
|
187
|
+ #
|
|
|
188
|
+ # Create distributable tarball
|
|
|
189
|
+ #
|
|
|
190
|
+ #FIXME: lacking Makefile skills, we do this step twice fot
|
|
|
191
|
+ # rpmstuff, hence -f hack for gzip
|
|
|
192
|
+ #
|
|
|
193
|
+ local version=$(semver)
|
|
|
194
|
+ local git_lasthash=$(git_lasthash)
|
|
|
195
|
+ local dirname=$MKIT_PROJ_PKGNAME-$version
|
|
|
196
|
+ mkdir -p "$dirname"
|
|
|
197
|
+ ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
|
|
|
198
|
+ update_version "$version" "$dirname/mkit.ini"
|
|
|
199
|
+ mkdir -p "$dirname/.mkit"
|
|
|
200
|
+ echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
|
|
|
201
|
+ tar -cf "$dirname.tar" "$dirname"
|
|
|
202
|
+ gzip -f "$dirname.tar" # see above FIXME
|
|
|
203
|
+ mkdir -p "$MKIT_LOCAL"
|
|
|
204
|
+ echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
|
|
|
205
|
+ rm -rf "$dirname"
|
|
|
206
|
+}
|
|
|
207
|
+
|
|
137
|
208
|
rpmstuff() {
|
|
138
|
209
|
#
|
|
139
|
210
|
# Build specfile
|
|
|
@@ -142,140 +213,5 @@ rpmstuff() {
|
|
142
|
213
|
local specsrc="$(ini 1value "rpmstuff:spec_skel")"
|
|
143
|
214
|
test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
|
|
144
|
215
|
test -f "$specsrc" || die "specfile template not found: $specsrc"
|
|
145
|
|
- build1 "$specsrc" "$specname"
|
|
146
|
|
-}
|
|
147
|
|
-
|
|
148
|
|
-expand_includes() {
|
|
149
|
|
- #
|
|
150
|
|
- # Expand include directives
|
|
151
|
|
- #
|
|
152
|
|
- # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
|
|
153
|
|
- #
|
|
154
|
|
- perl -we '
|
|
155
|
|
- use strict;
|
|
156
|
|
- my $text;
|
|
157
|
|
- while (<>) {
|
|
158
|
|
- chomp;
|
|
159
|
|
- if (m/<!-- include4: (\S+) -->/) {
|
|
160
|
|
- open my $fh, $1 or warn "cannot find: $1";
|
|
161
|
|
- my $text = do { local($/); <$fh> };
|
|
162
|
|
- close $fh;
|
|
163
|
|
- $text =~ s/^(.)/ $1/gm;
|
|
164
|
|
- chomp $text;
|
|
165
|
|
- print "$text\n";
|
|
166
|
|
- } else {
|
|
167
|
|
- print "$_\n";
|
|
168
|
|
- }
|
|
169
|
|
- }
|
|
170
|
|
- '
|
|
171
|
|
-}
|
|
172
|
|
-
|
|
173
|
|
-expand_variables() {
|
|
174
|
|
- #
|
|
175
|
|
- # Expand variables from sections $@
|
|
176
|
|
- #
|
|
177
|
|
- local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
|
|
178
|
|
- local section varname varvalue
|
|
179
|
|
- {
|
|
180
|
|
- for section in "$@";
|
|
181
|
|
- do
|
|
182
|
|
- debug_var section
|
|
183
|
|
- ini lskeys "$section" \
|
|
184
|
|
- | while read varname;
|
|
185
|
|
- do
|
|
186
|
|
- varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
|
|
187
|
|
- echo "s|$varname|$varvalue|;"
|
|
188
|
|
- debug_var varname varvalue
|
|
189
|
|
- done
|
|
190
|
|
- done
|
|
191
|
|
- echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename)|;"
|
|
192
|
|
- echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname)|;"
|
|
193
|
|
- echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline)|;"
|
|
194
|
|
- echo "s|__MKIT_PROJ_VERSION__|$(get_version)|;"
|
|
195
|
|
- echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|;"
|
|
196
|
|
- } >> "$script"
|
|
197
|
|
- perl -wp "$script" || die "expand_variables failed"
|
|
198
|
|
- rm "$script"
|
|
199
|
|
-}
|
|
200
|
|
-
|
|
201
|
|
-get_version() {
|
|
202
|
|
- #
|
|
203
|
|
- # Build semver version string with build metadata
|
|
204
|
|
- #
|
|
205
|
|
- # Build version string from available info using following
|
|
206
|
|
- # logic:
|
|
207
|
|
- #
|
|
208
|
|
- # 1. use project.version (from mkit.ini)
|
|
209
|
|
- # 2. if we are in git, override the version with last tag
|
|
210
|
|
- # 3. if set, add project:prerl (from mkit.ini) as pre-release ID
|
|
211
|
|
- # (afer dash)
|
|
212
|
|
- # 4. if we are at a later commit than the last tag, add branch
|
|
213
|
|
- # name and commit sha1 to build metadata (after plus sign)
|
|
214
|
|
- # 5. if the tree is "dirty", i.e. has uncommited changes,
|
|
215
|
|
- # add "dirty" to build metadata
|
|
216
|
|
- #
|
|
217
|
|
- # The version is compatible with SemVer 2.0.0.
|
|
218
|
|
- #
|
|
219
|
|
- # Examples:
|
|
220
|
|
- #
|
|
221
|
|
- # myprog v1.0.7 # all clear
|
|
222
|
|
- # myprog v1.0.7-alpha # mkit.ini: project:prerl="alpha"
|
|
223
|
|
- # myprog v1.0.7-alpha+g1aef811.master # ^^ + some commits after
|
|
224
|
|
- # myprog v1.0.7-alpha+gf14fc4f.api2 # ^^ + on a feature branch
|
|
225
|
|
- # myprog v1.0.7-alpha+gf14fc4f.api2.dirty # ^^ + tree edited
|
|
226
|
|
- # myprog v1.0.7-alpha+dirty # tag OK but tree edited
|
|
227
|
|
- # myprog v1.0.7+dirty # ^^ but no pre-release id
|
|
228
|
|
- #
|
|
229
|
|
- # Note that versions with "dirty" should be perceived as kind of
|
|
230
|
|
- # dangerous outside developer's own machine. Versions with sha1 are
|
|
231
|
|
- # safer but must not be released.
|
|
232
|
|
- #
|
|
233
|
|
- # I have considered decorating the git commit refs to make them
|
|
234
|
|
- # sort of sortable (e.g. "r1.g1aef811"), but on second thought,
|
|
235
|
|
- # I don't think it's good idea to give *any* semantics to meta-data
|
|
236
|
|
- # at all. First, there is no rule that r1<r2<r3; a commit can be
|
|
237
|
|
- # removing what other just added and one change can be split to
|
|
238
|
|
- # multiple commits. Also, the whole thing breaks anyway once you
|
|
239
|
|
- # rebase your branch (no, it's not a sin). The sole purpose of
|
|
240
|
|
- # meta-data is to *identify* the code, and provide safe path back
|
|
241
|
|
- # to tree; commit refs are already perfect for that.
|
|
242
|
|
- #
|
|
243
|
|
- # FIXME: Using project:prerl for release IDs may not be compatible with
|
|
244
|
|
- # release strategy implemented in release.sh
|
|
245
|
|
- #
|
|
246
|
|
- local version=$(ini 1value project:version)
|
|
247
|
|
- local prerl=$(ini 1value project:prerl)
|
|
248
|
|
- grep ":" <<<"$prerl" && warn "colon in project:prerl may corrupt version data: $prerl"
|
|
249
|
|
- if git rev-parse HEAD >&/dev/null;
|
|
250
|
|
- then # we are in git repo... so we can get smart
|
|
251
|
|
- local latest_tag=$(
|
|
252
|
|
- git log --format="%D" \
|
|
253
|
|
- | sed 's/,/\n/g' \
|
|
254
|
|
- | sed 's/^[[:blank:]]*//; ' \
|
|
255
|
|
- | grep -E '^tag: v[[:digit:]]+\.' \
|
|
256
|
|
- | cut -d' ' -f2 \
|
|
257
|
|
- | head -1
|
|
258
|
|
- )
|
|
259
|
|
- if ! git describe --tags --exact-match HEAD >&/dev/null;
|
|
260
|
|
- then # we are at a later commit than the last tag
|
|
261
|
|
- local sha=g$(git log -1 --pretty=format:%h HEAD)
|
|
262
|
|
- local curbranch=$(git rev-parse --abbrev-ref HEAD)
|
|
263
|
|
- local commit="$curbranch.$sha"
|
|
264
|
|
- fi
|
|
265
|
|
- if test "$(git diff --shortstat 2>/dev/null)" != "";
|
|
266
|
|
- then # the tree is "dirty", i.e. has been edited
|
|
267
|
|
- local dirty=dirty
|
|
268
|
|
- fi
|
|
269
|
|
- test -n "$latest_tag" && version=${latest_tag:1}
|
|
270
|
|
- local suffix=""
|
|
271
|
|
- case "$commit:$dirty" in
|
|
272
|
|
- :) suffix="" ;;
|
|
273
|
|
- :dirty) suffix="+$dirty" ;;
|
|
274
|
|
- *:) suffix="+$commit" ;;
|
|
275
|
|
- *:dirty) suffix="+$commit.$dirty" ;;
|
|
276
|
|
- esac
|
|
277
|
|
- test -b "$prerl" && suffix="-$prerl$suffix"
|
|
278
|
|
- version="$version$suffix"
|
|
279
|
|
- fi
|
|
280
|
|
- echo "$version"
|
|
|
216
|
+ _build1 "$specsrc" "$specname"
|
|
281
|
217
|
}
|