]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_core/commitdiff
push* scripts: use luasrcdiet if directed
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sun, 30 Jul 2017 01:34:55 +0000 (21:34 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 31 Jul 2017 23:23:28 +0000 (19:23 -0400)
If ${LUADIET} is empty, send files as they are; otherwise, stream them
through luasrcdiet.  To use the default options, use 'LUADIET=' '" or
something to that effect.  This can be set per-file, should some module
turn out to be broken by dieting.

The "dopush" utility macro is split and now called "dopushlua" and
"dopushtext" (which skips luasrcdiet even if it is engaged).

host/pushcommon.sh
host/pushinit.sh
host/pushvia.expect

index d43f1454248636dec5b03d5730a36daf5ef5dd2f..1fce50a411ddd461eb3baccc071b87c1249c952d 100644 (file)
@@ -1,11 +1,33 @@
-if [ -z ${MCUHOST:-} ]; then
-  # Uses LUATOOL to push init and dependencies to the device; bootstrap!
+luafile () {
+  if [ -z "${LUADIET:-}" ]; then
+    echo "No diet for lua" >&2
+    LUAFILE=$1
+  else
+    DF=$(mktemp -p /tmp esp-pushcommon-XXXXX)
+    if [ -n "${luafilefd:-}" ]; then exec {luafilefd}<&-; fi
+    exec {luafilefd}<>${DF}
+
+    echo "Lua diet ${LUADIET}" >&2
+    lua5.1 \
+      -e 'package.path=package.path..";_external/luasrcdiet/?.lua"' \
+      ./_external/luasrcdiet/bin/luasrcdiet $1 -o ${DF} \
+      --quiet ${=LUADIET} 2>/dev/null
+    rm ${DF}
+    LUAFILE=/dev/fd/${luafilefd}
+  fi
+}
+
+if [ -z "${MCUHOST:-}" ]; then
+  if [ -z "${LUATOOL:-}" ]; then echo "Need LUATOOL or MCUHOST"; exit 1; fi
+  if [ -z "${MCUPORT:-}" ]; then echo "Need MCUPORT or MCUHOST"; exit 1; fi
+  if [ -z "${MCUBAUD:-}" ]; then echo "Need MCUBAUD or MCUHOST"; exit 1; fi
   PUSHCMD="${LUATOOL} --delay 0.1 -p ${MCUPORT} -b ${MCUBAUD}"
-  dopush() { ${=PUSHCMD} -f $1 -t ${2:-`basename $1`}; }
-  dopushcompile() { ${=PUSHCMD} -f $1 -t ${2:-`basename $1`} -c; }
+  dopushtext()    {                ${=PUSHCMD} -f $1         -t ${2:-`basename $1`}    ; }
+  dopushlua()     { luafile ${1} ; ${=PUSHCMD} -f ${LUAFILE} -t ${2:-`basename $1`}    ; }
+  dopushcompile() { luafile ${1} ; ${=PUSHCMD} -f ${LUAFILE} -t ${2:-`basename $1`} -c ; }
 else
-  # Uses host/pushvia to push everything if MCUHOST is set
   PUSHCMD="./host/pushvia.expect ${MCUHOST} ${PORT:-23}"
-  dopush() { ${=PUSHCMD} ${2:-`basename $1`} $1; }
-  dopushcompile() { ${=PUSHCMD} ${2:-`basename $1`} $1 compile; }
+  dopushtext()    {                ${=PUSHCMD} ${2:-`basename $1`} $1                 ; }
+  dopushlua()     { luafile ${1} ; ${=PUSHCMD} ${2:-`basename $1`} ${LUAFILE}         ; }
+  dopushcompile() { luafile ${1} ; ${=PUSHCMD} ${2:-`basename $1`} ${LUAFILE} compile ; }
 fi
index c3801add9d05dd129040efd9ff37ca184ba4bd32..ffdf9991961f2e3d891f0aecf9184816cb2096e7 100755 (executable)
@@ -12,13 +12,13 @@ dopushcompile net/nwfnet.lua
 dopushcompile net/nwfnet-sntp.lua
 dopushcompile net/nwfnet-go.lua
 dopushcompile net/nwfnet-diag.lua
-#dopush        net/conf/nwfnet.conf
-#dopush        net/conf/nwfnet.cert
-#dopush        net/conf/nwfnet.conf2
+#dopushtext   net/conf/nwfnet.conf
+#dopushtext   net/conf/nwfnet.cert
+#dopushtext   net/conf/nwfnet.conf2
 dopushcompile net/fifosock.lua
 dopushcompile telnetd/telnetd.lua
 dopushcompile telnetd/telnetd-file.lua
 dopushcompile telnetd/telnetd-diag.lua
-dopush        init.lua
+dopushlua     init.lua
 
 echo "SUCCESS"
index 1c80c5aaf4de6cdead0956d2dc864031090a386c..c6f1e8a9c071ef000999b06e225557c5314e95d3 100755 (executable)
@@ -33,7 +33,7 @@ set remote_sid ${spawn_id}
 
 set rfn [lindex $argv 2]
 set lfn [lindex $argv 3]
-set lchan [open ${lfn} r+]
+set lchan [open ${lfn} r]
 fconfigure ${lchan} -translation binary -encoding binary
 
 set timeout 2