Skip to content

Commit 58b01b8

Browse files
committed
Don't call LuaSrcDiet on init_script.lua
This way, error stacktraces map to readable code. To avoid bloating the library, we strip all Lua comments except the first license notice and "-- @file ..." lines.
1 parent 0523d76 commit 58b01b8

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

Makefile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ CODE_SIGN_IDENTITY ?=
77
OTHER_CODE_SIGN_FLAGS ?=
88
# Configurable binaries
99
GODOT_BIN ?= godot
10-
LUA_BIN ?= lua
1110
LIPO ?= lipo
1211
STRIP ?= strip
1312
CODESIGN ?= codesign
@@ -120,15 +119,13 @@ LUA_INIT_SCRIPT_SRC = \
120119
src/register_in_editor_callbacks.lua
121120

122121
ifneq (1,$(DEBUG))
123-
EMBED_SCRIPT_SED := src/tools/compact_c_ffi.sed
124-
LUA_INIT_SCRIPT_TO_USE = build/init_script-diet.lua
125122
STRIP_CMD = $(_STRIP) $1
126123
else
127-
LUA_INIT_SCRIPT_TO_USE = build/init_script.lua
128124
STRIP_CMD =
129125
LDOC_ARGS = --all
130126
endif
131-
EMBED_SCRIPT_SED += src/tools/embed_to_c.sed src/tools/add_script_c_decl.sed
127+
INIT_SCRIPT_SED = src/tools/remove_lua_comments.sed src/tools/squeeze_blank_lines.sed src/tools/compact_c_ffi.sed
128+
EMBED_SCRIPT_SED = src/tools/embed_to_c.sed src/tools/add_script_c_decl.sed
132129

133130
ifneq (,$(CODE_SIGN_IDENTITY))
134131
CODESIGN_CMD = codesign -s "$(CODE_SIGN_IDENTITY)" $1 $(OTHER_CODE_SIGN_FLAGS)
@@ -166,11 +163,9 @@ build/jit/vmdef.lua: build/native/luajit/src/jit/vmdef.lua | build/jit
166163
build/jit/%.lua: lib/luajit/src/jit/%.lua | build/jit
167164
cp $< $@
168165

169-
build/init_script.lua: $(LUA_INIT_SCRIPT_SRC) | build
170-
cat $^ > $@
171-
build/init_script-diet.lua: build/init_script.lua
172-
env LUA_PATH=';;lib/luasrcdiet/?.lua;lib/luasrcdiet/?/init.lua' $(LUA_BIN) lib/luasrcdiet/bin/luasrcdiet $< -o $@ $(LUASRCDIET_FLAGS)
173-
build/%/init_script.c: $(LUA_INIT_SCRIPT_TO_USE) $(EMBED_SCRIPT_SED) | build/%
166+
build/init_script.lua: $(LUA_INIT_SCRIPT_SRC) $(INIT_SCRIPT_SED) | build
167+
cat $(filter %.lua,$^) $(addprefix | sed -E -f ,$(filter %.sed,$^)) > $@
168+
build/%/init_script.c: build/init_script.lua $(EMBED_SCRIPT_SED) | build/%
174169
sed -E $(addprefix -f ,$(EMBED_SCRIPT_SED)) $< > $@
175170

176171
build/%/init_script.o: build/%/init_script.c

src/tools/remove_lua_comments.sed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Remove all comment lines but the first license notice and "-- @file ..." lines
2+
25,$ {
3+
# Ensure there is a new line before "-- @file ..." lines
4+
s/(-- @file)/\n\1/
5+
# Skip next command if the previous one substituted anything
6+
# That is, when current line is a "-- @file ..." line, skip everything below
7+
t
8+
# Remove comment lines
9+
/^[[:space:]]*--/d
10+
}

src/tools/squeeze_blank_lines.sed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# On empty lines, do:
2+
/^$/ {
3+
: remove-empty-line
4+
# Load the next input line
5+
N
6+
# Remove last line, if it is empty
7+
s/\n$//
8+
# In case last line was empty, repeat the process to squeeze multiple empty lines into a single one
9+
t remove-empty-line
10+
}
11+

0 commit comments

Comments
 (0)