build: make GluonSrcDiet simpler and more robust (#2033)

- If luasrcdiet fails for a Lua script, this is a bug that should be
  noticed rather than including the unminified script
- Use .tmp suffix for temporary file rather than .o
- Replace chmod + stat + mv with simpler cp + rm to overwrite file while
  preserving file mode
This commit is contained in:
Matthias Schiffer 2020-06-04 22:53:14 +02:00 committed by GitHub
parent 1956696da5
commit 50adb097fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,11 +62,11 @@ define GluonSrcDiet
rm -rf $(2) rm -rf $(2)
$(CP) $(1) $(2) $(CP) $(1) $(2)
ifdef CONFIG_GLUON_MINIFY ifdef CONFIG_GLUON_MINIFY
$(FIND) $(2) -type f | while read src; do \ # Use cp + rm instead of mv to preserve destination permissions
if luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; then \ set -e; $(FIND) $(2) -type f | while read src; do \
chmod $$$$(stat -c%a "$$$$src") "$$$$src.o"; \ luasrcdiet --noopt-binequiv -o "$$$$src.tmp" "$$$$src"; \
mv "$$$$src.o" "$$$$src"; \ cp "$$$$src.tmp" "$$$$src"; \
fi; \ rm "$$$$src.tmp"; \
done done
endif endif
endef endef