Skip to content

Commit ad735d1

Browse files
committed
revert file to the most actual version and apply changes
1 parent fad2978 commit ad735d1

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

tools/file_packager.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
Usage:
2323
24-
file_packager TARGET [--preload A [B..]] [--embed C [D..]] [--exclude E [F..]]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--indexedDB-name=EM_PRELOAD_CACHE] [--separate-metadata] [--lz4] [--use-preload-plugins] [--no-node]
24+
file_packager TARGET [--preload A [B..]] [--embed C [D..]] [--exclude E [F..]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--indexedDB-name=EM_PRELOAD_CACHE] [--separate-metadata] [--lz4] [--use-preload-plugins] [--no-node] [--help]
2525
2626
--preload ,
2727
--embed See emcc --help for more details on those options.
@@ -84,6 +84,7 @@
8484
sys.path.insert(0, __rootdir__)
8585

8686
from tools import shared, utils, js_manipulation
87+
from tools.response_file import substitute_response_files
8788

8889

8990
DEBUG = os.environ.get('EMCC_DEBUG')
@@ -128,7 +129,6 @@ def __init__(self):
128129
self.use_preload_plugins = False
129130
self.support_node = True
130131
self.wasm64 = False
131-
self.modularize = False
132132

133133

134134
class DataFile:
@@ -158,8 +158,7 @@ def has_hidden_attribute(filepath):
158158
return False
159159

160160
try:
161-
attrs = ctypes.windll.kernel32.GetFileAttributesW(
162-
'%s' % filepath)
161+
attrs = ctypes.windll.kernel32.GetFileAttributesW(filepath)
163162
assert attrs != -1
164163
result = bool(attrs & 2)
165164
except Exception:
@@ -319,8 +318,6 @@ def generate_object_file(data_files):
319318
# A list of triples of:
320319
# (file_name_ptr, file_data_size, file_data_ptr)
321320
# The list in null terminate with a single 0
322-
.globl __emscripten_embedded_file_data
323-
.export_name __emscripten_embedded_file_data, __emscripten_embedded_file_data
324321
.section .rodata.__emscripten_embedded_file_data,"",@
325322
__emscripten_embedded_file_data:
326323
.p2align {align}
@@ -365,16 +362,26 @@ def main(): # noqa: C901, PLR0912, PLR0915
365362
To revalidate these numbers, run `ruff check --select=C901,PLR091`.
366363
"""
367364
if len(sys.argv) == 1:
368-
err('''Usage: file_packager TARGET [--preload A [B..]] [--embed C [D..]] [--exclude E [F..]]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--indexedDB-name=EM_PRELOAD_CACHE] [--separate-metadata] [--lz4] [--use-preload-plugins] [--no-node]
369-
See the source for more details.''')
365+
err('''Usage: file_packager TARGET [--preload A [B..]] [--embed C [D..]] [--exclude E [F..]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--indexedDB-name=EM_PRELOAD_CACHE] [--separate-metadata] [--lz4] [--use-preload-plugins] [--no-node] [--help]
366+
Try 'file_packager --help' for more details.''')
370367
return 1
371368

372-
data_target = sys.argv[1]
369+
# read response files very early on
370+
try:
371+
args = substitute_response_files(sys.argv[1:])
372+
except OSError as e:
373+
shared.exit_with_error(e)
374+
375+
if '--help' in args:
376+
print(__doc__.strip())
377+
return 0
378+
379+
data_target = args[0]
373380
data_files = []
374381
plugins = []
375382
leading = ''
376383

377-
for arg in sys.argv[2:]:
384+
for arg in args[1:]:
378385
if arg == '--preload':
379386
leading = 'preload'
380387
elif arg == '--embed':
@@ -623,19 +630,19 @@ def generate_js(data_target, data_files, metadata):
623630
ret = '''
624631
var Module = typeof %(EXPORT_NAME)s != 'undefined' ? %(EXPORT_NAME)s : {};\n''' % {"EXPORT_NAME": options.export_name}
625632

626-
ret += '''
633+
ret += '''
627634
Module['expectedDataFileDownloads'] ??= 0;
628635
Module['expectedDataFileDownloads']++;'''
629636

630637
if not options.modularize:
631-
ret += '''
638+
ret += '''
632639
(() => {'''
633640

634-
ret += '''
635-
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
636-
var isPthread = typeof ENVIRONMENT_IS_PTHREAD != 'undefined' && ENVIRONMENT_IS_PTHREAD;
637-
var isWasmWorker = typeof ENVIRONMENT_IS_WASM_WORKER != 'undefined' && ENVIRONMENT_IS_WASM_WORKER;
638-
if (isPthread || isWasmWorker) return;\n'''
641+
ret += '''
642+
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
643+
var isPthread = typeof ENVIRONMENT_IS_PTHREAD != 'undefined' && ENVIRONMENT_IS_PTHREAD;
644+
var isWasmWorker = typeof ENVIRONMENT_IS_WASM_WORKER != 'undefined' && ENVIRONMENT_IS_WASM_WORKER;
645+
if (isPthread || isWasmWorker) return;\n'''
639646

640647
if options.support_node:
641648
ret += " var isNode = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';\n"
@@ -816,13 +823,7 @@ def generate_js(data_target, data_files, metadata):
816823
return errback();
817824
}'''
818825
code += '''
819-
var indexedDB;
820-
if (typeof window === 'object') {
821-
indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
822-
} else if (typeof location !== 'undefined') {
823-
// worker
824-
indexedDB = self.indexedDB;
825-
} else {
826+
if (typeof indexedDB == 'undefined') {
826827
throw 'using IndexedDB to cache data can only be done on a web page or in a web worker';
827828
}
828829
try {

0 commit comments

Comments
 (0)