|
@@ -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() {
|
|
@@ -26,45 +26,70 @@ __build1_ftype() {
|
26
|
26
|
#
|
27
|
27
|
local ftype=$1 # file/builder type
|
28
|
28
|
case $ftype in
|
29
|
|
- MKIT_COMMON) __expand_tokens "tokens" ;;
|
30
|
|
- rpmstuff) __expand_tokens "tokens" "rpmstuff:tokens" ;;
|
31
|
|
- debstuff) __expand_tokens "tokens" "debstuff:tokens" ;;
|
|
29
|
+ MKIT_COMMON) __expand_macros "macros" ;;
|
|
30
|
+ rpmstuff) __expand_macros "macros" "rpmstuff:macros" ;;
|
|
31
|
+ debstuff) __expand_macros "macros" "debstuff:macros" ;;
|
32
|
32
|
*) die "unknown file type: $ftype" ;;
|
33
|
33
|
esac
|
34
|
34
|
}
|
35
|
35
|
|
36
|
|
-__expand_tokens() {
|
|
36
|
+__expand_line() {
|
37
|
37
|
#
|
38
|
|
- # Read stdin, expanding tokens from sections $@
|
|
38
|
+ # Expand macro from $MacroMap in single line $1
|
39
|
39
|
#
|
40
|
|
- local script # sed script cache
|
41
|
|
- local section # each section to expand tokens from
|
42
|
|
- local varname # each token name
|
43
|
|
- local varvalue # each token value
|
44
|
|
- script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
|
45
|
|
- {
|
46
|
|
- for section in "$@"; do
|
47
|
|
- debug_var section
|
48
|
|
- ini lskeys "$section" \
|
49
|
|
- | while read -r varname; do
|
50
|
|
- varvalue="$(ini 1value "$section:$varname" | __qfs )"
|
51
|
|
- echo "s|$varname|$varvalue|g;"
|
52
|
|
- debug_var varname varvalue
|
53
|
|
- done
|
|
40
|
+ # If macro value has multiple lines, repeat original line with
|
|
41
|
+ # different substitution.
|
|
42
|
+ #
|
|
43
|
+ # E.g. if macro value is "foo\nbar" and macro name is __FOO__,
|
|
44
|
+ # line `see: "__FOO__"` will expand to two lines: `see: "foo"`
|
|
45
|
+ # and `see: "bar"`.
|
|
46
|
+ #
|
|
47
|
+ local line=$1 # line to process
|
|
48
|
+ local mname # macro name
|
|
49
|
+ local mvline # line of macro value
|
|
50
|
+ local xline # expanded line
|
|
51
|
+ xline=$line
|
|
52
|
+ for mname in "${!MacroMap[@]}"; do
|
|
53
|
+ if ! test "${line//$mname}" == "$line"; then
|
|
54
|
+ xline=$(
|
|
55
|
+ while IFS= read -r mvline; do
|
|
56
|
+ echo "${line//$mname/$mvline}"
|
|
57
|
+ done <<<"${MacroMap[$mname]}"
|
|
58
|
+ )
|
|
59
|
+ fi
|
|
60
|
+ line=$xline
|
|
61
|
+ done
|
|
62
|
+ echo "$xline"
|
|
63
|
+ return 1
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+__expand_macros() {
|
|
67
|
+ #
|
|
68
|
+ # Read stdin, expanding macros from sections $@
|
|
69
|
+ #
|
|
70
|
+ local section # each section to expand macros from
|
|
71
|
+ local line # each line on stdin
|
|
72
|
+ local mname # each macro name
|
|
73
|
+ local -A MacroMap # macro value map
|
|
74
|
+ MacroMap[__MKIT_PROJ_NAME__]=$(ini 1value project:name)
|
|
75
|
+ MacroMap[__MKIT_PROJ_CODENAME__]=$(ini 1value project:codename)
|
|
76
|
+ MacroMap[__MKIT_PROJ_LICENSE__]=$(ini 1value project:license)
|
|
77
|
+ MacroMap[__MKIT_PROJ_PKGNAME__]=$(ini 1value project:pkgname)
|
|
78
|
+ MacroMap[__MKIT_PROJ_TAGLINE__]=$(ini 1value project:tagline)
|
|
79
|
+ MacroMap[__MKIT_PROJ_MAINTAINER__]=$(ini 1value project:maintainer)
|
|
80
|
+ MacroMap[__MKIT_PROJ_VCS_BROWSER__]=$(ini 1value project:vcs_browser)
|
|
81
|
+ MacroMap[__MKIT_PROJ_GIT_LASTHASH__]=$(__cached git_lasthash)
|
|
82
|
+ MacroMap[__MKIT_PROJ_VERSION__]=$(__cached semver)
|
|
83
|
+ MacroMap[__MKIT_SELF_VERSION__]=$MKIT_VERSION
|
|
84
|
+ for section in "$@"; do
|
|
85
|
+ for mname in $(ini lskeys "$section"); do
|
|
86
|
+ MacroMap[$mname]=$(ini values "$section:$mname")
|
54
|
87
|
done
|
55
|
|
- echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | __qfs)|g;"
|
56
|
|
- echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | __qfs)|g;"
|
57
|
|
- echo "s|__MKIT_PROJ_LICENSE__|$(ini 1value project:license | __qfs)|g;"
|
58
|
|
- echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | __qfs)|g;"
|
59
|
|
- echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | __qfs)|g;"
|
60
|
|
- echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | __qfs)|g;"
|
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;"
|
64
|
|
- echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
|
65
|
|
- } >> "$script"
|
66
|
|
- sed -f "$script" || die "__expand_tokens failed"
|
67
|
|
- rm "$script"
|
|
88
|
+ done
|
|
89
|
+ debug_var MacroMap
|
|
90
|
+ while IFS= read -r line; do
|
|
91
|
+ __expand_line "$line"
|
|
92
|
+ done
|
68
|
93
|
}
|
69
|
94
|
|
70
|
95
|
__guess_ftype() {
|
|
@@ -87,16 +112,68 @@ __qfs() {
|
87
|
112
|
'
|
88
|
113
|
}
|
89
|
114
|
|
|
115
|
+__cached() {
|
|
116
|
+ #
|
|
117
|
+ # Cached value $1 of function $1()
|
|
118
|
+ #
|
|
119
|
+ # In order to support git-less builds, some values might be cached
|
|
120
|
+ # in $MKIT_LOCAL. This function gets file $1 from that cache (cache
|
|
121
|
+ # hit) or re-creates it (cache miss), but prints its body in either
|
|
122
|
+ # case.
|
|
123
|
+ #
|
|
124
|
+ # The command to re-create file is the same as the key (ie. no
|
|
125
|
+ # arguments).
|
|
126
|
+ #
|
|
127
|
+ local name=$1
|
|
128
|
+ __local_get "$name" && return 0
|
|
129
|
+ "$name" | __local_putb "$name"
|
|
130
|
+ __local_get "$name"
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+__local_putb() {
|
|
134
|
+ #
|
|
135
|
+ # Make file $1 in $MKIT_LOCAL from stdin and mark as built
|
|
136
|
+ #
|
|
137
|
+ local fpath=$1
|
|
138
|
+ __local_put "$fpath" && __rec_built "$MKIT_LOCAL/$fpath"
|
|
139
|
+}
|
|
140
|
+
|
|
141
|
+__local_put() {
|
|
142
|
+ #
|
|
143
|
+ # Make file $1 in $MKIT_LOCAL from stdin
|
|
144
|
+ #
|
|
145
|
+ local fpath="$MKIT_LOCAL/$1"
|
|
146
|
+ { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
|
|
147
|
+ || die "cannot write to local cache: $fpath"
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+__local_get() {
|
|
151
|
+ #
|
|
152
|
+ # Read file $1 in $MKIT_LOCAL
|
|
153
|
+ #
|
|
154
|
+ local fpath="$MKIT_LOCAL/$1"
|
|
155
|
+ cat "$fpath" 2>/dev/null
|
|
156
|
+}
|
|
157
|
+
|
|
158
|
+__rec_built() {
|
|
159
|
+ #
|
|
160
|
+ # Record file $1 for deletion on `clean`
|
|
161
|
+ #
|
|
162
|
+ local file=$1
|
|
163
|
+ mkdir -p "$MKIT_LOCAL"
|
|
164
|
+ echo "$file" >> "$MKIT_LOCAL/built.lst"
|
|
165
|
+}
|
|
166
|
+
|
90
|
167
|
_mkit_data() {
|
91
|
168
|
#
|
92
|
|
- # Build sampler showing all token values
|
|
169
|
+ # Build sampler showing all macro values
|
93
|
170
|
#
|
94
|
|
- local token
|
|
171
|
+ local macro
|
95
|
172
|
local section
|
96
|
173
|
local sections
|
97
|
174
|
sections=()
|
98
|
|
- ini lskeys tokens | grep -q . && sections=(tokens)
|
99
|
|
- sections+=( $(ini lssect | grep ':tokens$') )
|
|
175
|
+ ini lskeys macros | grep -q . && sections=(macros)
|
|
176
|
+ sections+=( $(ini lssect | grep ':macros$') )
|
100
|
177
|
{
|
101
|
178
|
echo "(builtin):"
|
102
|
179
|
echo " x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
|
|
@@ -111,12 +188,12 @@ _mkit_data() {
|
111
|
188
|
echo " x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
|
112
|
189
|
for section in "${sections[@]}"; do
|
113
|
190
|
echo "$section:"
|
114
|
|
- for token in $(ini lskeys "$section"); do
|
115
|
|
- echo " x${token:1} => '$token'"
|
|
191
|
+ for macro in $(ini lskeys "$section"); do
|
|
192
|
+ echo " x${macro:1} => '$macro'"
|
116
|
193
|
done
|
117
|
194
|
done
|
118
|
195
|
} \
|
119
|
|
- | __expand_tokens "MKIT_BUILTIN" "${sections[@]}" \
|
|
196
|
+ | __expand_macros "MKIT_BUILTIN" "${sections[@]}" \
|
120
|
197
|
| sed '/^ x/ s|x|_|'
|
121
|
198
|
}
|
122
|
199
|
|
|
@@ -125,7 +202,6 @@ build() {
|
125
|
202
|
# Add meat to all skeletons
|
126
|
203
|
#
|
127
|
204
|
local srcpath # each source path
|
128
|
|
- semver >/dev/null
|
129
|
205
|
find . -type f -name '*.skel' \
|
130
|
206
|
| while read -r srcpath; do
|
131
|
207
|
__build1 "$srcpath"
|
|
@@ -153,14 +229,14 @@ debstuff() {
|
153
|
229
|
local debian_skel # 'debian' folder skeleton
|
154
|
230
|
local dfsrc # each source file from ^^
|
155
|
231
|
local dftgt # each built packaging file
|
156
|
|
- version=$(semver)
|
|
232
|
+ version=$(__cached semver)
|
157
|
233
|
|
158
|
234
|
# tarball - we should already have by means of 'dist'
|
159
|
235
|
#
|
160
|
236
|
mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
|
161
|
237
|
"${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
|
162
|
238
|
|| die "could not rename tarball"
|
163
|
|
- rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
|
|
239
|
+ __rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
|
164
|
240
|
|
165
|
241
|
# read content of each mandatory file from debian_skel
|
166
|
242
|
#
|
|
@@ -174,7 +250,7 @@ debstuff() {
|
174
|
250
|
mkdir -p "$(dirname "$dftgt")"
|
175
|
251
|
__build1 "$dfsrc" "$dftgt" debstuff
|
176
|
252
|
done
|
177
|
|
- rec_built debian
|
|
253
|
+ __rec_built debian
|
178
|
254
|
}
|
179
|
255
|
|
180
|
256
|
dist() {
|
|
@@ -192,12 +268,12 @@ dist() {
|
192
|
268
|
git_lasthash=$(git_lasthash)
|
193
|
269
|
mkdir -p "$dirname"
|
194
|
270
|
ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
|
195
|
|
- update_version "$version" "$dirname/mkit.ini"
|
196
|
271
|
mkdir -p "$dirname/.mkit"
|
|
272
|
+ echo -n "$version" > "$dirname/.mkit/semver"
|
197
|
273
|
echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
|
198
|
274
|
tar -cf "$dirname.tar" "$dirname"
|
199
|
275
|
gzip -f "$dirname.tar" # see above FIXME
|
200
|
|
- rec_built "$dirname.tar.gz"
|
|
276
|
+ __rec_built "$dirname.tar.gz"
|
201
|
277
|
rm -rf "$dirname"
|
202
|
278
|
}
|
203
|
279
|
|