Parcourir la source

Update own dogfood

Alois Mahdal il y a 6 ans
Parent
révision
911a07ed96

+ 62
- 41
utils/mkit/include/build.sh Voir le fichier

@@ -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
 

+ 26
- 2
utils/mkit/include/ini.sh Voir le fichier

@@ -30,13 +30,19 @@ __ini_expand() {
30 30
     done
31 31
 }
32 32
 
33
+__ini_grepcmt() {
34
+    #
35
+    # Remove comments from INI file on stdin
36
+    #
37
+    grep -v '^[[:space:]]*#'
38
+}
39
+
33 40
 __ini_grepkey() {
34 41
     #
35 42
     # Read key from a section
36 43
     #
37 44
     local wnt=$1    # wanted key
38 45
     grep '.' \
39
-      | grep -v '\s*#' \
40 46
       | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
41 47
       | grep -e "^$wnt=" \
42 48
       | cut -d= -f2- \
@@ -112,6 +118,24 @@ __ini_maybe_expand() {
112 118
     fi
113 119
 }
114 120
 
121
+__ini_body() {
122
+    #
123
+    # Produce mkit.ini body including INCLUDE
124
+    #
125
+    # Note: recursive includes are not supported.
126
+    #
127
+    local inc                       # file to include
128
+    local incre='\[INCLUDE:.*\]'    # include directive regex
129
+    local iline                     # include directive line
130
+    if iline=$(grep -m1 -x "$incre" "$MKIT_INI"); then
131
+        inc=${iline#*:}; inc=${inc%]}
132
+        grep -vx "$incre" "$inc"
133
+        grep -vx "$incre" "$MKIT_INI"
134
+    else
135
+        cat "$MKIT_INI"
136
+    fi | __ini_grepcmt
137
+}
138
+
115 139
 ini() {
116 140
     #
117 141
     # do ini operation
@@ -128,7 +152,7 @@ ini() {
128 152
         1value) fn=__ini_greppath; limit="tail -1" ;;
129 153
         *)      die "incorrect use of \`ini()\`"
130 154
     esac
131
-    <"$MKIT_INI" $fn "$arg" | $limit
155
+    __ini_body | $fn "$arg" | $limit
132 156
 }
133 157
 
134 158
 update_version() {

+ 4
- 4
utils/mkit/include/mkit.sh Voir le fichier

@@ -66,12 +66,12 @@ debug_var() {
66 66
     #
67 67
     $MKIT_DEBUG || return 0
68 68
     local __mkit_debug_var_name__       # variable name to debug
69
+    local decl                          # declare string
69 70
     for __mkit_debug_var_name__ in "$@"; do
70 71
         {
71
-            echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
72
-            echo -n " $__mkit_debug_var_name__"
73
-            echo -n "='${!__mkit_debug_var_name__}'"
74
-            echo
72
+            decl=$(declare -p "$__mkit_debug_var_name__")
73
+            decl=${decl#declare ?? }
74
+            echo "MKIT_DEBUG: ${FUNCNAME[1]}(): $decl"
75 75
         } >&2
76 76
     done
77 77
 }

+ 2
- 2
utils/mkit/include/vars.sh Voir le fichier

@@ -51,11 +51,11 @@ MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
51 51
 #
52 52
 # Package name
53 53
 #
54
-# Used as base for tarball and in some default tokens.
54
+# Used as base for tarball and in some default macros.
55 55
 #
56 56
 MKIT_PROJ_PKGNAME=""
57 57
 
58 58
 #
59 59
 # This MKit version
60 60
 #
61
-MKIT_VERSION=0.0.28+master.ge02e222
61
+MKIT_VERSION=0.0.29+HEAD.g0ada671

+ 8
- 8
utils/mkit/stub Voir le fichier

@@ -82,7 +82,7 @@ deploy() {
82 82
                 remake_section dist
83 83
                 remake_section ENV
84 84
                 remake_section roots
85
-                remake_section tokens
85
+                remake_section macros
86 86
                 remake_section modes
87 87
                 remake_section files
88 88
             else
@@ -112,7 +112,7 @@ deploy() {
112 112
                     echo "doc = [ENV:PREFIX]/share/doc/$PackageName"
113 113
                 } | reformat_section
114 114
                 echo ""
115
-                echo "[tokens]"
115
+                echo "[macros]"
116 116
                 {
117 117
                     echo "__${PackageName^^}_FOO__ = Barr.."
118 118
                 } | reformat_section
@@ -258,7 +258,7 @@ deploy() {
258 258
             echo "    machine should be uder 'src'."
259 259
             echo ""
260 260
             echo "    Note that during build time, files named ending with"
261
-            echo "    '.skel' are subject to token expansion, see mkit.ini"
261
+            echo "    '.skel' are subject to macro expansion, see mkit.ini"
262 262
             echo "    section below for details."
263 263
             echo ""
264 264
             echo " *  *notes* directory - here you shall store notes"
@@ -279,7 +279,7 @@ deploy() {
279 279
             echo " *  *packaging* directory contains templates that enable"
280 280
             echo "    MKit create raw stuffs used to create DEB or RPM"
281 281
             echo "    packages.  Similar to '.skel' files in 'src', all files"
282
-            echo "    here are automatically considered for token expansion,"
282
+            echo "    here are automatically considered for macro expansion,"
283 283
             echo "    no matter how they are named (see mkit.ini section"
284 284
             echo "    below)."
285 285
             echo ""
@@ -382,13 +382,13 @@ deploy() {
382 382
             echo "    \`[modes]\` section is your friend.  Permissions here"
383 383
             echo "    should be in UNIX octal format."
384 384
             echo ""
385
-            echo " 5. Next, \`[tokens]\` section allows you to define own"
385
+            echo " 5. Next, \`[macros]\` section allows you to define own"
386 386
             echo "    placeholders that will be replaced when your scripts are"
387 387
             echo "    built.  Each file in 'src' directory that is named with"
388 388
             echo "    '.skel' suffix, and each file from 'packaging' directory"
389
-            echo "    (no matter its name), can contain one or more of tokens"
390
-            echo "    defined here, plus range of tokens automatically defined"
391
-            echo "    by MKit.  During build, these tokens are replaced with"
389
+            echo "    (no matter its name), can contain one or more of macros"
390
+            echo "    defined here, plus range of macros automatically defined"
391
+            echo "    by MKit.  During build, these macros are replaced with"
392 392
             echo "    their actual values."
393 393
             echo ""
394 394
             echo " 6. Less interesting, but important section is \`[dist]\`,"