Use a sanitized JS export name for WASM modules (qmake)

Previously, a target name with a JS special character (like, -, for
example), would lead to an invalid export name being generated for
WASM modules. Sanitize these by replacing any non-alphanumeric
character with underscores, as is done for feature names.
This is a qmake version of 58a47edda1

Fixes: QTBUG-115506
Change-Id: I7c84076be54da91cf0f707c1613afc382acdcb83
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
This commit is contained in:
Mikolaj Boc 2023-07-25 14:01:09 +02:00
parent ea0b7dafb2
commit 44d3d87930

View File

@ -18,8 +18,10 @@ exists($$QMAKE_QT_CONFIG) {
!isEmpty(QT_WASM_EXPORT_NAME): {
EXPORT_NAME = $$QT_WASM_EXPORT_NAME
} else {
EXPORT_NAME = $${TARGET}_entry
TARGET_SANITIZED = $$replace(TARGET, [^a-zA-Z0-9_], _)
EXPORT_NAME = $${TARGET_SANITIZED}_entry
}
EMCC_LFLAGS += -s EXPORT_NAME=$$EXPORT_NAME
qtConfig(thread) {
@ -103,7 +105,7 @@ contains(TEMPLATE, .*app) {
# replacing the app name placeholder with the actual app name.
apphtml.name = application main html file
apphtml.output = $$DESTDIR/$$TARGET_HTML
apphtml.commands = $$QMAKE_STREAM_EDITOR -e s/@APPNAME@/$$TARGET_BASE/g $$WASM_PLUGIN_PATH/wasm_shell.html > $$DESTDIR/$$TARGET_HTML
apphtml.commands = $$QMAKE_STREAM_EDITOR -e s/@APPNAME@/$$TARGET_BASE/g -e s/@APPEXPORTNAME@/$$EXPORT_NAME/g $$WASM_PLUGIN_PATH/wasm_shell.html > $$DESTDIR/$$TARGET_HTML
apphtml.input = $$WASM_PLUGIN_PATH/wasm_shell.html
apphtml.depends = $$apphtml.input
QMAKE_EXTRA_COMPILERS += apphtml