88
99import copy
1010import gyp .input
11- import optparse
11+ import argparse
1212import os .path
1313import re
1414import shlex
@@ -244,15 +244,15 @@ def Noop(value):
244244
245245 return flags
246246
247- class RegeneratableOptionParser (optparse . OptionParser ):
248- def __init__ (self ):
247+ class RegeneratableOptionParser (argparse . ArgumentParser ):
248+ def __init__ (self , usage ):
249249 self .__regeneratable_options = {}
250- optparse . OptionParser .__init__ (self )
250+ argparse . ArgumentParser .__init__ (self , usage = usage )
251251
252- def add_option (self , * args , ** kw ):
252+ def add_argument (self , * args , ** kw ):
253253 """Add an option to the parser.
254254
255- This accepts the same arguments as OptionParser.add_option , plus the
255+ This accepts the same arguments as ArgumentParser.add_argument , plus the
256256 following:
257257 regenerate: can be set to False to prevent this option from being included
258258 in regeneration.
@@ -269,7 +269,7 @@ def add_option(self, *args, **kw):
269269 # it as a string.
270270 type = kw .get ('type' )
271271 if type == 'path' :
272- kw ['type' ] = 'string'
272+ kw ['type' ] = str
273273
274274 self .__regeneratable_options [dest ] = {
275275 'action' : kw .get ('action' ),
@@ -278,50 +278,50 @@ def add_option(self, *args, **kw):
278278 'opt' : args [0 ],
279279 }
280280
281- optparse . OptionParser . add_option (self , * args , ** kw )
281+ argparse . ArgumentParser . add_argument (self , * args , ** kw )
282282
283283 def parse_args (self , * args ):
284- values , args = optparse . OptionParser . parse_args (self , * args )
284+ values , args = argparse . ArgumentParser . parse_known_args (self , * args )
285285 values ._regeneration_metadata = self .__regeneratable_options
286286 return values , args
287287
288288def gyp_main (args ):
289289 my_name = os .path .basename (sys .argv [0 ])
290+ usage = 'usage: %(prog)s [options ...] [build_file ...]'
290291
291- parser = RegeneratableOptionParser ()
292- usage = 'usage: %s [options ...] [build_file ...]'
293- parser .set_usage (usage .replace ('%s' , '%prog' ))
294- parser .add_option ('--build' , dest = 'configs' , action = 'append' ,
292+
293+ parser = RegeneratableOptionParser (usage = usage .replace ('%s' , '%(prog)s' ))
294+ parser .add_argument ('--build' , dest = 'configs' , action = 'append' ,
295295 help = 'configuration for build after project generation' )
296- parser .add_option ('--check' , dest = 'check' , action = 'store_true' ,
296+ parser .add_argument ('--check' , dest = 'check' , action = 'store_true' ,
297297 help = 'check format of gyp files' )
298- parser .add_option ('--config-dir' , dest = 'config_dir' , action = 'store' ,
298+ parser .add_argument ('--config-dir' , dest = 'config_dir' , action = 'store' ,
299299 env_name = 'GYP_CONFIG_DIR' , default = None ,
300300 help = 'The location for configuration files like '
301301 'include.gypi.' )
302- parser .add_option ('-d' , '--debug' , dest = 'debug' , metavar = 'DEBUGMODE' ,
302+ parser .add_argument ('-d' , '--debug' , dest = 'debug' , metavar = 'DEBUGMODE' ,
303303 action = 'append' , default = [], help = 'turn on a debugging '
304304 'mode for debugging GYP. Supported modes are "variables", '
305305 '"includes" and "general" or "all" for all of them.' )
306- parser .add_option ('-D' , dest = 'defines' , action = 'append' , metavar = 'VAR=VAL' ,
306+ parser .add_argument ('-D' , dest = 'defines' , action = 'append' , metavar = 'VAR=VAL' ,
307307 env_name = 'GYP_DEFINES' ,
308308 help = 'sets variable VAR to value VAL' )
309- parser .add_option ('--depth' , dest = 'depth' , metavar = 'PATH' , type = 'path' ,
309+ parser .add_argument ('--depth' , dest = 'depth' , metavar = 'PATH' , type = 'path' ,
310310 help = 'set DEPTH gyp variable to a relative path to PATH' )
311- parser .add_option ('-f' , '--format' , dest = 'formats' , action = 'append' ,
311+ parser .add_argument ('-f' , '--format' , dest = 'formats' , action = 'append' ,
312312 env_name = 'GYP_GENERATORS' , regenerate = False ,
313313 help = 'output formats to generate' )
314- parser .add_option ('-G' , dest = 'generator_flags' , action = 'append' , default = [],
314+ parser .add_argument ('-G' , dest = 'generator_flags' , action = 'append' , default = [],
315315 metavar = 'FLAG=VAL' , env_name = 'GYP_GENERATOR_FLAGS' ,
316316 help = 'sets generator flag FLAG to VAL' )
317- parser .add_option ('--generator-output' , dest = 'generator_output' ,
317+ parser .add_argument ('--generator-output' , dest = 'generator_output' ,
318318 action = 'store' , default = None , metavar = 'DIR' , type = 'path' ,
319319 env_name = 'GYP_GENERATOR_OUTPUT' ,
320320 help = 'puts generated build files under DIR' )
321- parser .add_option ('--ignore-environment' , dest = 'use_environment' ,
321+ parser .add_argument ('--ignore-environment' , dest = 'use_environment' ,
322322 action = 'store_false' , default = True , regenerate = False ,
323323 help = 'do not read options from environment variables' )
324- parser .add_option ('-I' , '--include' , dest = 'includes' , action = 'append' ,
324+ parser .add_argument ('-I' , '--include' , dest = 'includes' , action = 'append' ,
325325 metavar = 'INCLUDE' , type = 'path' ,
326326 help = 'files to include in all loaded .gyp files' )
327327 # --no-circular-check disables the check for circular relationships between
@@ -331,7 +331,7 @@ def gyp_main(args):
331331 # option allows the strict behavior to be used on Macs and the lenient
332332 # behavior to be used elsewhere.
333333 # TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
334- parser .add_option ('--no-circular-check' , dest = 'circular_check' ,
334+ parser .add_argument ('--no-circular-check' , dest = 'circular_check' ,
335335 action = 'store_false' , default = True , regenerate = False ,
336336 help = "don't check for circular relationships between files" )
337337 # --no-duplicate-basename-check disables the check for duplicate basenames
@@ -340,18 +340,18 @@ def gyp_main(args):
340340 # when duplicate basenames are passed into Make generator on Mac.
341341 # TODO(yukawa): Remove this option when these legacy generators are
342342 # deprecated.
343- parser .add_option ('--no-duplicate-basename-check' ,
343+ parser .add_argument ('--no-duplicate-basename-check' ,
344344 dest = 'duplicate_basename_check' , action = 'store_false' ,
345345 default = True , regenerate = False ,
346346 help = "don't check for duplicate basenames" )
347- parser .add_option ('--no-parallel' , action = 'store_true' , default = False ,
347+ parser .add_argument ('--no-parallel' , action = 'store_true' , default = False ,
348348 help = 'Disable multiprocessing' )
349- parser .add_option ('-S' , '--suffix' , dest = 'suffix' , default = '' ,
349+ parser .add_argument ('-S' , '--suffix' , dest = 'suffix' , default = '' ,
350350 help = 'suffix to add to generated files' )
351- parser .add_option ('--toplevel-dir' , dest = 'toplevel_dir' , action = 'store' ,
351+ parser .add_argument ('--toplevel-dir' , dest = 'toplevel_dir' , action = 'store' ,
352352 default = None , metavar = 'DIR' , type = 'path' ,
353353 help = 'directory to use as the root of the source tree' )
354- parser .add_option ('-R' , '--root-target' , dest = 'root_targets' ,
354+ parser .add_argument ('-R' , '--root-target' , dest = 'root_targets' ,
355355 action = 'append' , metavar = 'TARGET' ,
356356 help = 'include only TARGET and its deep dependencies' )
357357
0 commit comments