Hi,
This patch makes able to minify lua code sequential inside directories. Here is an example how do can call it in package Makefiles:
First of all you need the host dependencies. PKG_BUILD_DEPENDS += luci-base/host lua/host
Then you muss have to include the gluon spesific package.mk. include $(GLUONDIR)/include/package.mk
After the all abouve just call the following command inside the package compile define. $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
luasrc can have subdirectorys there will also created inside luadest including its minifyed files.
As an example how good it will woke. I minifyed the Nordwest Freifunk hoodselector. This lua file have currently around 680 lines and a size of 22042 Bytes after minifying it has just 9480 Bytes.
Here is a table of the minifying process:
-------------------------------------------------------------------- Lexical Input Input Input Output Output Output Elements Count Bytes Average Count Bytes Average -------------------------------------------------------------------- TK_KEYWORD 526 1958 3.72 526 1958 3.72 TK_NAME 813 5506 6.77 813 1984 2.44 TK_NUMBER 35 36 1.03 35 36 1.03 TK_STRING 246 3379 13.74 246 3379 13.74 TK_LSTRING 0 0 0.00 0 0 0.00 TK_OP 1276 1356 1.06 1276 1356 1.06 TK_EOS 1 0 0.00 1 0 0.00 -------------------------------------------------------------------- TK_COMMENT 137 6982 50.96 1 14 14.00 TK_LCOMMENT 0 0 0.00 0 0 0.00 TK_EOL 676 676 1.00 466 466 1.00 TK_SPACE 1187 2149 1.81 287 287 1.00 -------------------------------------------------------------------- Total Elements 4897 22042 4.50 3651 9480 2.60 -------------------------------------------------------------------- Total Tokens 2897 12235 4.22 2897 8713 3.01 --------------------------------------------------------------------
Patches for preparing all gluon spesific packages that includes lua code will follow soon.
cheers Tarek
Jan-Tarek Butt (1): add luaSrcDiet call define to package.mk
include/package.mk | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Is this enabled by default and/or can it be enabled/disabled by a flag? Otherwise this could become a debugging-nightmare as i assume the minifying works by replacing meaningful identifiers by 1-letter shortnames and stripping linebreaks, comments etc.?
maybe the best idea would be to enable the minifying on a per-device-basis so that routers with enough flash can continue using the uncompressed easy-to-debug-and-modify-firmware while the smaller routers with just 4mb would get a compressed image. that would be the best compromise imho
regards, eike
Am 07.07.2016 um 11:44 schrieb Jan-Tarek Butt via Dev:
Hi,
This patch makes able to minify lua code sequential inside directories. Here is an example how do can call it in package Makefiles:
First of all you need the host dependencies. PKG_BUILD_DEPENDS += luci-base/host lua/host
Then you muss have to include the gluon spesific package.mk. include $(GLUONDIR)/include/package.mk
After the all abouve just call the following command inside the package compile define. $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
luasrc can have subdirectorys there will also created inside luadest including its minifyed files.
As an example how good it will woke. I minifyed the Nordwest Freifunk hoodselector. This lua file have currently around 680 lines and a size of 22042 Bytes after minifying it has just 9480 Bytes.
Here is a table of the minifying process:
Lexical Input Input Input Output Output Output Elements Count Bytes Average Count Bytes Average
TK_KEYWORD 526 1958 3.72 526 1958 3.72 TK_NAME 813 5506 6.77 813 1984 2.44 TK_NUMBER 35 36 1.03 35 36 1.03 TK_STRING 246 3379 13.74 246 3379 13.74 TK_LSTRING 0 0 0.00 0 0 0.00 TK_OP 1276 1356 1.06 1276 1356 1.06 TK_EOS 1 0 0.00 1 0 0.00
TK_COMMENT 137 6982 50.96 1 14 14.00 TK_LCOMMENT 0 0 0.00 0 0 0.00 TK_EOL 676 676 1.00 466 466 1.00 TK_SPACE 1187 2149 1.81 287 287 1.00
Total Elements 4897 22042 4.50 3651 9480 2.60
Total Tokens 2897 12235 4.22 2897 8713 3.01
Patches for preparing all gluon spesific packages that includes lua code will follow soon.
cheers Tarek
Jan-Tarek Butt (1): add luaSrcDiet call define to package.mk
include/package.mk | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
On 07/07/16 15:13, Eike Baran via Dev wrote:
Is this enabled by default and/or can it be enabled/disabled by a flag? Otherwise this could become a debugging-nightmare as i assume the minifying works by replacing meaningful identifiers by 1-letter shortnames and stripping linebreaks, comments etc.?
Yes it can be use optionaly like the following lines inside package Makefiles
define Build/Compile $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/) endef
if you dont want a minifyed lua file on a image you can just drop the line in your spesiffic package.
maybe the best idea would be to enable the minifying on a per-device-basis so that routers with enough flash can continue using the uncompressed easy-to-debug-and-modify-firmware while the smaller routers with just 4mb would get a compressed image. that would be the best compromise imho
I think this is not nessesary. For debunging oder developing you can transfare the unminifyed lua file via scp to routers and worke on it.
vg Tarek