|
@@ -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() {
|
37
|
|
- #
|
38
|
|
- # Read stdin, expanding tokens from sections $@
|
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
|
|
36
|
+__expand_line() {
|
|
37
|
+ #
|
|
38
|
+ # Expand macro from $MacroMap in single line $1
|
|
39
|
+ #
|
|
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__|$(__cached git_lasthash | __qfs)|g;"
|
63
|
|
- echo "s|__MKIT_PROJ_VERSION__|$(__cached 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() {
|
|
@@ -141,14 +166,14 @@ __rec_built() {
|
141
|
166
|
|
142
|
167
|
_mkit_data() {
|
143
|
168
|
#
|
144
|
|
- # Build sampler showing all token values
|
|
169
|
+ # Build sampler showing all macro values
|
145
|
170
|
#
|
146
|
|
- local token
|
|
171
|
+ local macro
|
147
|
172
|
local section
|
148
|
173
|
local sections
|
149
|
174
|
sections=()
|
150
|
|
- ini lskeys tokens | grep -q . && sections=(tokens)
|
151
|
|
- sections+=( $(ini lssect | grep ':tokens$') )
|
|
175
|
+ ini lskeys macros | grep -q . && sections=(macros)
|
|
176
|
+ sections+=( $(ini lssect | grep ':macros$') )
|
152
|
177
|
{
|
153
|
178
|
echo "(builtin):"
|
154
|
179
|
echo " x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
|
|
@@ -163,12 +188,12 @@ _mkit_data() {
|
163
|
188
|
echo " x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
|
164
|
189
|
for section in "${sections[@]}"; do
|
165
|
190
|
echo "$section:"
|
166
|
|
- for token in $(ini lskeys "$section"); do
|
167
|
|
- echo " x${token:1} => '$token'"
|
|
191
|
+ for macro in $(ini lskeys "$section"); do
|
|
192
|
+ echo " x${macro:1} => '$macro'"
|
168
|
193
|
done
|
169
|
194
|
done
|
170
|
195
|
} \
|
171
|
|
- | __expand_tokens "MKIT_BUILTIN" "${sections[@]}" \
|
|
196
|
+ | __expand_macros "MKIT_BUILTIN" "${sections[@]}" \
|
172
|
197
|
| sed '/^ x/ s|x|_|'
|
173
|
198
|
}
|
174
|
199
|
|