@@ -68,13 +68,50 @@ def parse_args():
68
68
parser .add_argument ('--preserve-manifest' , action = 'store_true' ,
69
69
help = 'Preserve generated manifest file. This sets --verbose too.' )
70
70
args , forwarded_args = parser .parse_known_args ()
71
- if '--manifest' in forwarded_args :
72
- exit_with_error ('manifest file will be generated by this script and should not be given' )
71
+
73
72
if args .preserve_manifest :
74
73
args .verbose = True
74
+ if not args .wasm_split :
75
+ args .wasm_split = os .path .join (building .get_binaryen_bin (), shared .exe_suffix ('wasm-split' ))
76
+
77
+ if '--manifest' in forwarded_args :
78
+ parser .error ('manifest file will be generated by this script and should not be given' )
79
+ if '-o' not in forwarded_args and '--output' not in forwarded_args :
80
+ parser .error ('-o (--output) is required' )
75
81
return args , forwarded_args
76
82
77
83
84
+ def check_errors (args ):
85
+ if args .wasm and not os .path .isfile (args .wasm ):
86
+ exit_with_error (f"'{ args .wasm } ' was not found or not a file" )
87
+ if args .paths_file and not os .path .isfile (args .paths_file ):
88
+ exit_with_error (f"'{ args .paths_file } ' was not found or not a file" )
89
+
90
+ if args .sourcemap :
91
+ if not os .path .isfile (args .sourcemap ):
92
+ exit_with_error (f"'{ args .sourcemap } ' was not found or not a file" )
93
+
94
+ if args .wasm :
95
+ with webassembly .Module (args .wasm ) as module :
96
+ if not args .sourcemap and not emsymbolizer .get_sourceMappingURL_section (module ):
97
+ exit_with_error ('sourceMappingURL section does not exist' )
98
+ sourcemap = module .get_sourceMappingURL ()
99
+ if not os .path .isfile (sourcemap ):
100
+ exit_with_error (f"'{ sourcemap } ' was not found or not a file" )
101
+ if not module .has_name_section ():
102
+ exit_with_error ('Name section does not eixst' )
103
+
104
+ if not os .path .isfile (args .wasm_split ):
105
+ exit_with_error (f"'{ args .wasm_split } ' was not found or not a file" )
106
+
107
+
108
+ def get_sourceMappingURL (wasm , arg_sourcemap ):
109
+ if arg_sourcemap :
110
+ return arg_sourcemap
111
+ with webassembly .Module (wasm ) as module :
112
+ return module .get_sourceMappingURL ()
113
+
114
+
78
115
def get_path_to_functions_map (wasm , sourcemap , paths ):
79
116
def is_synthesized_func (func ):
80
117
# TODO There can be more
@@ -98,21 +135,13 @@ def is_synthesized_func(func):
98
135
# {src file: list of functions} map, and construct {path: list of functions}
99
136
# map from it
100
137
with webassembly .Module (wasm ) as module :
101
- if not module .has_name_section ():
102
- exit_with_error ('Name section does not eixst' )
103
- if not sourcemap :
104
- if not emsymbolizer .get_sourceMappingURL_section (module ):
105
- exit_with_error ('sourceMappingURL section does not exist' )
106
-
107
138
funcs = module .get_functions ()
108
139
func_names = module .get_function_names ()
109
140
assert len (funcs ) == len (func_names )
110
141
111
142
func_to_src = {}
112
143
src_to_funcs = {}
113
144
114
- if not sourcemap :
115
- sourcemap = module .get_sourceMappingURL ()
116
145
sm = emsymbolizer .WasmSourceMap ()
117
146
sm .parse (sourcemap )
118
147
@@ -170,20 +199,9 @@ def is_synthesized_func(func):
170
199
171
200
def main ():
172
201
args , forwarded_args = parse_args ()
173
- if args .wasm_split :
174
- wasm_split = args .wasm_split
175
- else :
176
- wasm_split = os .path .join (building .get_binaryen_bin (), shared .exe_suffix ('wasm-split' ))
202
+ check_errors (args )
177
203
178
- if not os .path .isfile (args .wasm ):
179
- exit_with_error (f"'{ args .wasm } ' was not found or not a file" )
180
- if not os .path .isfile (args .paths_file ):
181
- exit_with_error (f"'{ args .paths_file } ' was not found or not a file" )
182
- if args .sourcemap :
183
- if not os .path .isfile (args .sourcemap ):
184
- exit_with_error (f"'{ args .sourcemap } ' was not found or not a file" )
185
- if not os .path .isfile (wasm_split ):
186
- exit_with_error (f"'{ wasm_split } ' was not found or not a file" )
204
+ sourcemap = get_sourceMappingURL (args .wasm , args .sourcemap )
187
205
188
206
paths = utils .read_file (args .paths_file ).splitlines ()
189
207
paths = [utils .normalize_path (path .strip ()) for path in paths if path .strip ()]
@@ -193,7 +211,7 @@ def main():
193
211
paths = list (dict .fromkeys (paths ))
194
212
195
213
# Compute {path: list of functions} map
196
- path_to_funcs = get_path_to_functions_map (args .wasm , args . sourcemap , paths )
214
+ path_to_funcs = get_path_to_functions_map (args .wasm , sourcemap , paths )
197
215
198
216
# Write .manifest file
199
217
with tempfile .NamedTemporaryFile (suffix = ".manifest" , mode = 'w+' , delete = args .preserve_manifest ) as f :
@@ -213,7 +231,7 @@ def main():
213
231
f .write ('\n ' )
214
232
f .flush ()
215
233
216
- cmd = [wasm_split , '--multi-split' , args .wasm , '--manifest' , manifest ]
234
+ cmd = [args . wasm_split , '--multi-split' , args .wasm , '--manifest' , manifest ]
217
235
if args .verbose :
218
236
# This option is used both in this script and wasm-split
219
237
cmd .append ('-v' )
0 commit comments