8
8
9
9
import copy
10
10
import gyp .input
11
- import optparse
11
+ import argparse
12
12
import os .path
13
13
import re
14
14
import shlex
@@ -244,15 +244,15 @@ def Noop(value):
244
244
245
245
return flags
246
246
247
- class RegeneratableOptionParser (optparse . OptionParser ):
248
- def __init__ (self ):
247
+ class RegeneratableOptionParser (argparse . ArgumentParser ):
248
+ def __init__ (self , usage ):
249
249
self .__regeneratable_options = {}
250
- optparse . OptionParser .__init__ (self )
250
+ argparse . ArgumentParser .__init__ (self , usage = usage )
251
251
252
- def add_option (self , * args , ** kw ):
252
+ def add_argument (self , * args , ** kw ):
253
253
"""Add an option to the parser.
254
254
255
- This accepts the same arguments as OptionParser.add_option , plus the
255
+ This accepts the same arguments as ArgumentParser.add_argument , plus the
256
256
following:
257
257
regenerate: can be set to False to prevent this option from being included
258
258
in regeneration.
@@ -269,7 +269,7 @@ def add_option(self, *args, **kw):
269
269
# it as a string.
270
270
type = kw .get ('type' )
271
271
if type == 'path' :
272
- kw ['type' ] = 'string'
272
+ kw ['type' ] = str
273
273
274
274
self .__regeneratable_options [dest ] = {
275
275
'action' : kw .get ('action' ),
@@ -278,50 +278,50 @@ def add_option(self, *args, **kw):
278
278
'opt' : args [0 ],
279
279
}
280
280
281
- optparse . OptionParser . add_option (self , * args , ** kw )
281
+ argparse . ArgumentParser . add_argument (self , * args , ** kw )
282
282
283
283
def parse_args (self , * args ):
284
- values , args = optparse . OptionParser . parse_args (self , * args )
284
+ values , args = argparse . ArgumentParser . parse_known_args (self , * args )
285
285
values ._regeneration_metadata = self .__regeneratable_options
286
286
return values , args
287
287
288
288
def gyp_main (args ):
289
289
my_name = os .path .basename (sys .argv [0 ])
290
+ usage = 'usage: %(prog)s [options ...] [build_file ...]'
290
291
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' ,
295
295
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' ,
297
297
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' ,
299
299
env_name = 'GYP_CONFIG_DIR' , default = None ,
300
300
help = 'The location for configuration files like '
301
301
'include.gypi.' )
302
- parser .add_option ('-d' , '--debug' , dest = 'debug' , metavar = 'DEBUGMODE' ,
302
+ parser .add_argument ('-d' , '--debug' , dest = 'debug' , metavar = 'DEBUGMODE' ,
303
303
action = 'append' , default = [], help = 'turn on a debugging '
304
304
'mode for debugging GYP. Supported modes are "variables", '
305
305
'"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' ,
307
307
env_name = 'GYP_DEFINES' ,
308
308
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' ,
310
310
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' ,
312
312
env_name = 'GYP_GENERATORS' , regenerate = False ,
313
313
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 = [],
315
315
metavar = 'FLAG=VAL' , env_name = 'GYP_GENERATOR_FLAGS' ,
316
316
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' ,
318
318
action = 'store' , default = None , metavar = 'DIR' , type = 'path' ,
319
319
env_name = 'GYP_GENERATOR_OUTPUT' ,
320
320
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' ,
322
322
action = 'store_false' , default = True , regenerate = False ,
323
323
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' ,
325
325
metavar = 'INCLUDE' , type = 'path' ,
326
326
help = 'files to include in all loaded .gyp files' )
327
327
# --no-circular-check disables the check for circular relationships between
@@ -331,7 +331,7 @@ def gyp_main(args):
331
331
# option allows the strict behavior to be used on Macs and the lenient
332
332
# behavior to be used elsewhere.
333
333
# 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' ,
335
335
action = 'store_false' , default = True , regenerate = False ,
336
336
help = "don't check for circular relationships between files" )
337
337
# --no-duplicate-basename-check disables the check for duplicate basenames
@@ -340,18 +340,18 @@ def gyp_main(args):
340
340
# when duplicate basenames are passed into Make generator on Mac.
341
341
# TODO(yukawa): Remove this option when these legacy generators are
342
342
# deprecated.
343
- parser .add_option ('--no-duplicate-basename-check' ,
343
+ parser .add_argument ('--no-duplicate-basename-check' ,
344
344
dest = 'duplicate_basename_check' , action = 'store_false' ,
345
345
default = True , regenerate = False ,
346
346
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 ,
348
348
help = 'Disable multiprocessing' )
349
- parser .add_option ('-S' , '--suffix' , dest = 'suffix' , default = '' ,
349
+ parser .add_argument ('-S' , '--suffix' , dest = 'suffix' , default = '' ,
350
350
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' ,
352
352
default = None , metavar = 'DIR' , type = 'path' ,
353
353
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' ,
355
355
action = 'append' , metavar = 'TARGET' ,
356
356
help = 'include only TARGET and its deep dependencies' )
357
357
0 commit comments