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

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