|
@@ -26,45 +26,66 @@ __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
|
+ for mname in "${!MacroMap[@]}"; do
|
|
51
|
+ if ! test "${line//$mname}" == "$line"; then
|
|
52
|
+ while IFS= read -r mvline; do
|
|
53
|
+ echo "${line//$mname/$mvline}"
|
|
54
|
+ done <<<"${MacroMap[$mname]}"
|
|
55
|
+ return 0
|
|
56
|
+ fi
|
|
57
|
+ done
|
|
58
|
+ echo "$line"
|
|
59
|
+ return 1
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+__expand_macros() {
|
|
63
|
+ #
|
|
64
|
+ # Read stdin, expanding macros from sections $@
|
|
65
|
+ #
|
|
66
|
+ local section # each section to expand macros from
|
|
67
|
+ local line # each line on stdin
|
|
68
|
+ local mname # each macro name
|
|
69
|
+ local -A MacroMap # macro value map
|
|
70
|
+ MacroMap[__MKIT_PROJ_NAME__]=$(ini 1value project:name)
|
|
71
|
+ MacroMap[__MKIT_PROJ_CODENAME__]=$(ini 1value project:codename)
|
|
72
|
+ MacroMap[__MKIT_PROJ_LICENSE__]=$(ini 1value project:license)
|
|
73
|
+ MacroMap[__MKIT_PROJ_PKGNAME__]=$(ini 1value project:pkgname)
|
|
74
|
+ MacroMap[__MKIT_PROJ_TAGLINE__]=$(ini 1value project:tagline)
|
|
75
|
+ MacroMap[__MKIT_PROJ_MAINTAINER__]=$(ini 1value project:maintainer)
|
|
76
|
+ MacroMap[__MKIT_PROJ_VCS_BROWSER__]=$(ini 1value project:vcs_browser)
|
|
77
|
+ MacroMap[__MKIT_PROJ_GIT_LASTHASH__]=$(__cached git_lasthash)
|
|
78
|
+ MacroMap[__MKIT_PROJ_VERSION__]=$(__cached semver)
|
|
79
|
+ MacroMap[__MKIT_SELF_VERSION__]=$MKIT_VERSION
|
|
80
|
+ for section in "$@"; do
|
|
81
|
+ for mname in $(ini lskeys "$section"); do
|
|
82
|
+ MacroMap[$mname]=$(ini values "$section:$mname")
|
54
|
83
|
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"
|
|
84
|
+ done
|
|
85
|
+ debug_var MacroMap
|
|
86
|
+ while IFS= read -r line; do
|
|
87
|
+ __expand_line "$line"
|
|
88
|
+ done
|
68
|
89
|
}
|
69
|
90
|
|
70
|
91
|
__guess_ftype() {
|
|
@@ -141,14 +162,14 @@ __rec_built() {
|
141
|
162
|
|
142
|
163
|
_mkit_data() {
|
143
|
164
|
#
|
144
|
|
- # Build sampler showing all token values
|
|
165
|
+ # Build sampler showing all macro values
|
145
|
166
|
#
|
146
|
|
- local token
|
|
167
|
+ local macro
|
147
|
168
|
local section
|
148
|
169
|
local sections
|
149
|
170
|
sections=()
|
150
|
|
- ini lskeys tokens | grep -q . && sections=(tokens)
|
151
|
|
- sections+=( $(ini lssect | grep ':tokens$') )
|
|
171
|
+ ini lskeys macros | grep -q . && sections=(macros)
|
|
172
|
+ sections+=( $(ini lssect | grep ':macros$') )
|
152
|
173
|
{
|
153
|
174
|
echo "(builtin):"
|
154
|
175
|
echo " x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
|
|
@@ -163,12 +184,12 @@ _mkit_data() {
|
163
|
184
|
echo " x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
|
164
|
185
|
for section in "${sections[@]}"; do
|
165
|
186
|
echo "$section:"
|
166
|
|
- for token in $(ini lskeys "$section"); do
|
167
|
|
- echo " x${token:1} => '$token'"
|
|
187
|
+ for macro in $(ini lskeys "$section"); do
|
|
188
|
+ echo " x${macro:1} => '$macro'"
|
168
|
189
|
done
|
169
|
190
|
done
|
170
|
191
|
} \
|
171
|
|
- | __expand_tokens "MKIT_BUILTIN" "${sections[@]}" \
|
|
192
|
+ | __expand_macros "MKIT_BUILTIN" "${sections[@]}" \
|
172
|
193
|
| sed '/^ x/ s|x|_|'
|
173
|
194
|
}
|
174
|
195
|
|