MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / parse_args

Function parse_args

tools/cmdline.py:197–622  ·  view source on GitHub ↗

Future modifications should consider refactoring to reduce complexity. * The McCabe cyclomatiic complexity is currently 117 vs 10 recommended. * There are currently 115 branches vs 12 recommended. * There are currently 302 statements vs 50 recommended. To revalidate these numbers, run `ruf

(newargs)

Source from the content-addressed store, hash-verified

195
196
197def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
198 """Future modifications should consider refactoring to reduce complexity.
199
200 * The McCabe cyclomatiic complexity is currently 117 vs 10 recommended.
201 * There are currently 115 branches vs 12 recommended.
202 * There are currently 302 statements vs 50 recommended.
203
204 To revalidate these numbers, run `ruff check --select=C901,PLR091`.
205 """
206 should_exit = False
207 skip = False
208 builtin_settings = set(settings.keys())
209 LEGACY_ARGS = {'--js-opts', '--llvm-opts', '--llvm-lto', '--memory-init-file'}
210 LEGACY_FLAGS = {'--separate-asm', '--jcache', '--proxy-to-worker', '--default-obj-ext',
211 '--embind-emit-tsd', '--remove-duplicates', '--no-heap-copy'}
212
213 for i in range(len(newargs)):
214 if skip:
215 skip = False
216 continue
217
218 # Support legacy '--bind' flag, by mapping to `-lembind` which now
219 # has the same effect
220 if newargs[i] == '--bind':
221 newargs[i] = '-lembind'
222
223 arg = newargs[i]
224 arg_value = None
225
226 if arg in CLANG_FLAGS_WITH_ARGS:
227 # Ignore the next argument rather than trying to parse it. This is needed
228 # because that next arg could, for example, start with `-o` and we don't want
229 # to confuse that with a normal `-o` flag.
230 skip = True
231
232 def check_flag(value):
233 # Check for and consume a flag
234 if arg == value:
235 newargs[i] = ''
236 return True
237 return False
238
239 def check_arg(name):
240 nonlocal arg, arg_value
241 if arg.startswith(name) and '=' in arg:
242 arg, arg_value = arg.split('=', 1)
243 newargs[i] = ''
244 return True
245 if arg == name:
246 if len(newargs) <= i + 1:
247 exit_with_error(f"option '{arg}' requires an argument")
248 arg_value = newargs[i + 1]
249 newargs[i] = ''
250 newargs[i + 1] = ''
251 return True
252 return False
253
254 def consume_arg():

Callers 1

parse_argumentsFunction · 0.70

Calls 15

exit_with_errorFunction · 0.90
check_argFunction · 0.85
consume_argFunction · 0.85
is_dash_s_for_emccFunction · 0.85
consume_arg_fileFunction · 0.85
check_flagFunction · 0.85
is_unsigned_intFunction · 0.85
version_stringFunction · 0.85
is_valid_abspathFunction · 0.85
warningMethod · 0.80
appendMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected