Ver código fonte

Add helper functions to simplify operations in .mkit

Alois Mahdal 7 anos atrás
pai
commit
0ffdce9d39
1 arquivos alterados com 34 adições e 0 exclusões
  1. 34
    0
      src/include/mkit.sh

+ 34
- 0
src/include/mkit.sh Ver arquivo

@@ -125,6 +125,31 @@ _chkiniversion() {
125 125
      || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
126 126
 }
127 127
 
128
+local_putb() {
129
+    #
130
+    # Make file $1 in $MKIT_LOCAL from stdin and mark as built
131
+    #
132
+    local fpath=$1
133
+    local_put "$fpath" && rec_built "$MKIT_LOCAL/$fpath"
134
+}
135
+
136
+local_put() {
137
+    #
138
+    # Make file $1 in $MKIT_LOCAL from stdin
139
+    #
140
+    local fpath="$MKIT_LOCAL/$1"
141
+    { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
142
+     || die "cannot write to local cache: $fpath"
143
+}
144
+
145
+local_get() {
146
+    #
147
+    # Read file $1 in $MKIT_LOCAL
148
+    #
149
+    local fpath="$MKIT_LOCAL/$1"
150
+    cat "$fpath" 2>/dev/null
151
+}
152
+
128 153
 mkit_init() {
129 154
     #
130 155
     # Do basic initialization
@@ -138,6 +163,15 @@ mkit_init() {
138 163
     _chkiniversion
139 164
 }
140 165
 
166
+rec_built() {
167
+    #
168
+    # Record file $1 for deletion on `clean`
169
+    #
170
+    local file=$1
171
+    mkdir -p "$MKIT_LOCAL"
172
+    echo "$file" >> "$MKIT_LOCAL/built.lst"
173
+}
174
+
141 175
 route() {
142 176
     #
143 177
     # Call correct function based on $1