PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/couchjs/scons/scons-local-2.0.1/SCons/Script/SConsOptions.py

http://github.com/cloudant/bigcouch
Python | 939 lines | 861 code | 15 blank | 63 comment | 26 complexity | 3c0dd3525e718fc717240cc531cad28d MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  16. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #
  23. __revision__ = "src/engine/SCons/Script/SConsOptions.py 5134 2010/08/16 23:02:40 bdeegan"
  24. import optparse
  25. import re
  26. import sys
  27. import textwrap
  28. no_hyphen_re = re.compile(r'(\s+|(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')
  29. try:
  30. from gettext import gettext
  31. except ImportError:
  32. def gettext(message):
  33. return message
  34. _ = gettext
  35. import SCons.Node.FS
  36. import SCons.Warnings
  37. OptionValueError = optparse.OptionValueError
  38. SUPPRESS_HELP = optparse.SUPPRESS_HELP
  39. diskcheck_all = SCons.Node.FS.diskcheck_types()
  40. def diskcheck_convert(value):
  41. if value is None:
  42. return []
  43. if not SCons.Util.is_List(value):
  44. value = value.split(',')
  45. result = []
  46. for v in value:
  47. v = v.lower()
  48. if v == 'all':
  49. result = diskcheck_all
  50. elif v == 'none':
  51. result = []
  52. elif v in diskcheck_all:
  53. result.append(v)
  54. else:
  55. raise ValueError(v)
  56. return result
  57. class SConsValues(optparse.Values):
  58. """
  59. Holder class for uniform access to SCons options, regardless
  60. of whether or not they can be set on the command line or in the
  61. SConscript files (using the SetOption() function).
  62. A SCons option value can originate three different ways:
  63. 1) set on the command line;
  64. 2) set in an SConscript file;
  65. 3) the default setting (from the the op.add_option()
  66. calls in the Parser() function, below).
  67. The command line always overrides a value set in a SConscript file,
  68. which in turn always overrides default settings. Because we want
  69. to support user-specified options in the SConscript file itself,
  70. though, we may not know about all of the options when the command
  71. line is first parsed, so we can't make all the necessary precedence
  72. decisions at the time the option is configured.
  73. The solution implemented in this class is to keep these different sets
  74. of settings separate (command line, SConscript file, and default)
  75. and to override the __getattr__() method to check them in turn.
  76. This should allow the rest of the code to just fetch values as
  77. attributes of an instance of this class, without having to worry
  78. about where they came from.
  79. Note that not all command line options are settable from SConscript
  80. files, and the ones that are must be explicitly added to the
  81. "settable" list in this class, and optionally validated and coerced
  82. in the set_option() method.
  83. """
  84. def __init__(self, defaults):
  85. self.__dict__['__defaults__'] = defaults
  86. self.__dict__['__SConscript_settings__'] = {}
  87. def __getattr__(self, attr):
  88. """
  89. Fetches an options value, checking first for explicit settings
  90. from the command line (which are direct attributes), then the
  91. SConscript file settings, then the default values.
  92. """
  93. try:
  94. return self.__dict__[attr]
  95. except KeyError:
  96. try:
  97. return self.__dict__['__SConscript_settings__'][attr]
  98. except KeyError:
  99. return getattr(self.__dict__['__defaults__'], attr)
  100. settable = [
  101. 'clean',
  102. 'diskcheck',
  103. 'duplicate',
  104. 'help',
  105. 'implicit_cache',
  106. 'max_drift',
  107. 'md5_chunksize',
  108. 'no_exec',
  109. 'num_jobs',
  110. 'random',
  111. 'stack_size',
  112. 'warn',
  113. ]
  114. def set_option(self, name, value):
  115. """
  116. Sets an option from an SConscript file.
  117. """
  118. if not name in self.settable:
  119. raise SCons.Errors.UserError("This option is not settable from a SConscript file: %s"%name)
  120. if name == 'num_jobs':
  121. try:
  122. value = int(value)
  123. if value < 1:
  124. raise ValueError
  125. except ValueError:
  126. raise SCons.Errors.UserError("A positive integer is required: %s"%repr(value))
  127. elif name == 'max_drift':
  128. try:
  129. value = int(value)
  130. except ValueError:
  131. raise SCons.Errors.UserError("An integer is required: %s"%repr(value))
  132. elif name == 'duplicate':
  133. try:
  134. value = str(value)
  135. except ValueError:
  136. raise SCons.Errors.UserError("A string is required: %s"%repr(value))
  137. if not value in SCons.Node.FS.Valid_Duplicates:
  138. raise SCons.Errors.UserError("Not a valid duplication style: %s" % value)
  139. # Set the duplicate style right away so it can affect linking
  140. # of SConscript files.
  141. SCons.Node.FS.set_duplicate(value)
  142. elif name == 'diskcheck':
  143. try:
  144. value = diskcheck_convert(value)
  145. except ValueError, v:
  146. raise SCons.Errors.UserError("Not a valid diskcheck value: %s"%v)
  147. if 'diskcheck' not in self.__dict__:
  148. # No --diskcheck= option was specified on the command line.
  149. # Set this right away so it can affect the rest of the
  150. # file/Node lookups while processing the SConscript files.
  151. SCons.Node.FS.set_diskcheck(value)
  152. elif name == 'stack_size':
  153. try:
  154. value = int(value)
  155. except ValueError:
  156. raise SCons.Errors.UserError("An integer is required: %s"%repr(value))
  157. elif name == 'md5_chunksize':
  158. try:
  159. value = int(value)
  160. except ValueError:
  161. raise SCons.Errors.UserError("An integer is required: %s"%repr(value))
  162. elif name == 'warn':
  163. if SCons.Util.is_String(value):
  164. value = [value]
  165. value = self.__SConscript_settings__.get(name, []) + value
  166. SCons.Warnings.process_warn_strings(value)
  167. self.__SConscript_settings__[name] = value
  168. class SConsOption(optparse.Option):
  169. def convert_value(self, opt, value):
  170. if value is not None:
  171. if self.nargs in (1, '?'):
  172. return self.check_value(opt, value)
  173. else:
  174. return tuple([self.check_value(opt, v) for v in value])
  175. def process(self, opt, value, values, parser):
  176. # First, convert the value(s) to the right type. Howl if any
  177. # value(s) are bogus.
  178. value = self.convert_value(opt, value)
  179. # And then take whatever action is expected of us.
  180. # This is a separate method to make life easier for
  181. # subclasses to add new actions.
  182. return self.take_action(
  183. self.action, self.dest, opt, value, values, parser)
  184. def _check_nargs_optional(self):
  185. if self.nargs == '?' and self._short_opts:
  186. fmt = "option %s: nargs='?' is incompatible with short options"
  187. raise SCons.Errors.UserError(fmt % self._short_opts[0])
  188. try:
  189. _orig_CONST_ACTIONS = optparse.Option.CONST_ACTIONS
  190. _orig_CHECK_METHODS = optparse.Option.CHECK_METHODS
  191. except AttributeError:
  192. # optparse.Option had no CONST_ACTIONS before Python 2.5.
  193. _orig_CONST_ACTIONS = ("store_const",)
  194. def _check_const(self):
  195. if self.action not in self.CONST_ACTIONS and self.const is not None:
  196. raise OptionError(
  197. "'const' must not be supplied for action %r" % self.action,
  198. self)
  199. # optparse.Option collects its list of unbound check functions
  200. # up front. This sucks because it means we can't just override
  201. # the _check_const() function like a normal method, we have to
  202. # actually replace it in the list. This seems to be the most
  203. # straightforward way to do that.
  204. _orig_CHECK_METHODS = [optparse.Option._check_action,
  205. optparse.Option._check_type,
  206. optparse.Option._check_choice,
  207. optparse.Option._check_dest,
  208. _check_const,
  209. optparse.Option._check_nargs,
  210. optparse.Option._check_callback]
  211. CHECK_METHODS = _orig_CHECK_METHODS + [_check_nargs_optional]
  212. CONST_ACTIONS = _orig_CONST_ACTIONS + optparse.Option.TYPED_ACTIONS
  213. class SConsOptionGroup(optparse.OptionGroup):
  214. """
  215. A subclass for SCons-specific option groups.
  216. The only difference between this and the base class is that we print
  217. the group's help text flush left, underneath their own title but
  218. lined up with the normal "SCons Options".
  219. """
  220. def format_help(self, formatter):
  221. """
  222. Format an option group's help text, outdenting the title so it's
  223. flush with the "SCons Options" title we print at the top.
  224. """
  225. formatter.dedent()
  226. result = formatter.format_heading(self.title)
  227. formatter.indent()
  228. result = result + optparse.OptionContainer.format_help(self, formatter)
  229. return result
  230. class SConsOptionParser(optparse.OptionParser):
  231. preserve_unknown_options = False
  232. def error(self, msg):
  233. self.print_usage(sys.stderr)
  234. sys.stderr.write("SCons error: %s\n" % msg)
  235. sys.exit(2)
  236. def _process_long_opt(self, rargs, values):
  237. """
  238. SCons-specific processing of long options.
  239. This is copied directly from the normal
  240. optparse._process_long_opt() method, except that, if configured
  241. to do so, we catch the exception thrown when an unknown option
  242. is encountered and just stick it back on the "leftover" arguments
  243. for later (re-)processing.
  244. """
  245. arg = rargs.pop(0)
  246. # Value explicitly attached to arg? Pretend it's the next
  247. # argument.
  248. if "=" in arg:
  249. (opt, next_arg) = arg.split("=", 1)
  250. rargs.insert(0, next_arg)
  251. had_explicit_value = True
  252. else:
  253. opt = arg
  254. had_explicit_value = False
  255. try:
  256. opt = self._match_long_opt(opt)
  257. except optparse.BadOptionError:
  258. if self.preserve_unknown_options:
  259. # SCons-specific: if requested, add unknown options to
  260. # the "leftover arguments" list for later processing.
  261. self.largs.append(arg)
  262. if had_explicit_value:
  263. # The unknown option will be re-processed later,
  264. # so undo the insertion of the explicit value.
  265. rargs.pop(0)
  266. return
  267. raise
  268. option = self._long_opt[opt]
  269. if option.takes_value():
  270. nargs = option.nargs
  271. if nargs == '?':
  272. if had_explicit_value:
  273. value = rargs.pop(0)
  274. else:
  275. value = option.const
  276. elif len(rargs) < nargs:
  277. if nargs == 1:
  278. self.error(_("%s option requires an argument") % opt)
  279. else:
  280. self.error(_("%s option requires %d arguments")
  281. % (opt, nargs))
  282. elif nargs == 1:
  283. value = rargs.pop(0)
  284. else:
  285. value = tuple(rargs[0:nargs])
  286. del rargs[0:nargs]
  287. elif had_explicit_value:
  288. self.error(_("%s option does not take a value") % opt)
  289. else:
  290. value = None
  291. option.process(opt, value, values, self)
  292. def add_local_option(self, *args, **kw):
  293. """
  294. Adds a local option to the parser.
  295. This is initiated by a SetOption() call to add a user-defined
  296. command-line option. We add the option to a separate option
  297. group for the local options, creating the group if necessary.
  298. """
  299. try:
  300. group = self.local_option_group
  301. except AttributeError:
  302. group = SConsOptionGroup(self, 'Local Options')
  303. group = self.add_option_group(group)
  304. self.local_option_group = group
  305. result = group.add_option(*args, **kw)
  306. if result:
  307. # The option was added succesfully. We now have to add the
  308. # default value to our object that holds the default values
  309. # (so that an attempt to fetch the option's attribute will
  310. # yield the default value when not overridden) and then
  311. # we re-parse the leftover command-line options, so that
  312. # any value overridden on the command line is immediately
  313. # available if the user turns around and does a GetOption()
  314. # right away.
  315. setattr(self.values.__defaults__, result.dest, result.default)
  316. self.parse_args(self.largs, self.values)
  317. return result
  318. class SConsIndentedHelpFormatter(optparse.IndentedHelpFormatter):
  319. def format_usage(self, usage):
  320. return "usage: %s\n" % usage
  321. def format_heading(self, heading):
  322. """
  323. This translates any heading of "options" or "Options" into
  324. "SCons Options." Unfortunately, we have to do this here,
  325. because those titles are hard-coded in the optparse calls.
  326. """
  327. if heading == 'options':
  328. # The versions of optparse.py shipped with Pythons 2.3 and
  329. # 2.4 pass this in uncapitalized; override that so we get
  330. # consistent output on all versions.
  331. heading = "Options"
  332. if heading == 'Options':
  333. heading = "SCons Options"
  334. return optparse.IndentedHelpFormatter.format_heading(self, heading)
  335. def format_option(self, option):
  336. """
  337. A copy of the normal optparse.IndentedHelpFormatter.format_option()
  338. method. This has been snarfed so we can modify text wrapping to
  339. out liking:
  340. -- add our own regular expression that doesn't break on hyphens
  341. (so things like --no-print-directory don't get broken);
  342. -- wrap the list of options themselves when it's too long
  343. (the wrapper.fill(opts) call below);
  344. -- set the subsequent_indent when wrapping the help_text.
  345. """
  346. # The help for each option consists of two parts:
  347. # * the opt strings and metavars
  348. # eg. ("-x", or "-fFILENAME, --file=FILENAME")
  349. # * the user-supplied help string
  350. # eg. ("turn on expert mode", "read data from FILENAME")
  351. #
  352. # If possible, we write both of these on the same line:
  353. # -x turn on expert mode
  354. #
  355. # But if the opt string list is too long, we put the help
  356. # string on a second line, indented to the same column it would
  357. # start in if it fit on the first line.
  358. # -fFILENAME, --file=FILENAME
  359. # read data from FILENAME
  360. result = []
  361. try:
  362. opts = self.option_strings[option]
  363. except AttributeError:
  364. # The Python 2.3 version of optparse attaches this to
  365. # to the option argument, not to this object.
  366. opts = option.option_strings
  367. opt_width = self.help_position - self.current_indent - 2
  368. if len(opts) > opt_width:
  369. wrapper = textwrap.TextWrapper(width=self.width,
  370. initial_indent = ' ',
  371. subsequent_indent = ' ')
  372. wrapper.wordsep_re = no_hyphen_re
  373. opts = wrapper.fill(opts) + '\n'
  374. indent_first = self.help_position
  375. else: # start help on same line as opts
  376. opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
  377. indent_first = 0
  378. result.append(opts)
  379. if option.help:
  380. try:
  381. expand_default = self.expand_default
  382. except AttributeError:
  383. # The HelpFormatter base class in the Python 2.3 version
  384. # of optparse has no expand_default() method.
  385. help_text = option.help
  386. else:
  387. help_text = expand_default(option)
  388. # SCons: indent every line of the help text but the first.
  389. wrapper = textwrap.TextWrapper(width=self.help_width,
  390. subsequent_indent = ' ')
  391. wrapper.wordsep_re = no_hyphen_re
  392. help_lines = wrapper.wrap(help_text)
  393. result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
  394. for line in help_lines[1:]:
  395. result.append("%*s%s\n" % (self.help_position, "", line))
  396. elif opts[-1] != "\n":
  397. result.append("\n")
  398. return "".join(result)
  399. # For consistent help output across Python versions, we provide a
  400. # subclass copy of format_option_strings() and these two variables.
  401. # This is necessary (?) for Python2.3, which otherwise concatenates
  402. # a short option with its metavar.
  403. _short_opt_fmt = "%s %s"
  404. _long_opt_fmt = "%s=%s"
  405. def format_option_strings(self, option):
  406. """Return a comma-separated list of option strings & metavariables."""
  407. if option.takes_value():
  408. metavar = option.metavar or option.dest.upper()
  409. short_opts = []
  410. for sopt in option._short_opts:
  411. short_opts.append(self._short_opt_fmt % (sopt, metavar))
  412. long_opts = []
  413. for lopt in option._long_opts:
  414. long_opts.append(self._long_opt_fmt % (lopt, metavar))
  415. else:
  416. short_opts = option._short_opts
  417. long_opts = option._long_opts
  418. if self.short_first:
  419. opts = short_opts + long_opts
  420. else:
  421. opts = long_opts + short_opts
  422. return ", ".join(opts)
  423. def Parser(version):
  424. """
  425. Returns an options parser object initialized with the standard
  426. SCons options.
  427. """
  428. formatter = SConsIndentedHelpFormatter(max_help_position=30)
  429. op = SConsOptionParser(option_class=SConsOption,
  430. add_help_option=False,
  431. formatter=formatter,
  432. usage="usage: scons [OPTION] [TARGET] ...",)
  433. op.preserve_unknown_options = True
  434. op.version = version
  435. # Add the options to the parser we just created.
  436. #
  437. # These are in the order we want them to show up in the -H help
  438. # text, basically alphabetical. Each op.add_option() call below
  439. # should have a consistent format:
  440. #
  441. # op.add_option("-L", "--long-option-name",
  442. # nargs=1, type="string",
  443. # dest="long_option_name", default='foo',
  444. # action="callback", callback=opt_long_option,
  445. # help="help text goes here",
  446. # metavar="VAR")
  447. #
  448. # Even though the optparse module constructs reasonable default
  449. # destination names from the long option names, we're going to be
  450. # explicit about each one for easier readability and so this code
  451. # will at least show up when grepping the source for option attribute
  452. # names, or otherwise browsing the source code.
  453. # options ignored for compatibility
  454. def opt_ignore(option, opt, value, parser):
  455. sys.stderr.write("Warning: ignoring %s option\n" % opt)
  456. op.add_option("-b", "-d", "-e", "-m", "-S", "-t", "-w",
  457. "--environment-overrides",
  458. "--no-keep-going",
  459. "--no-print-directory",
  460. "--print-directory",
  461. "--stop",
  462. "--touch",
  463. action="callback", callback=opt_ignore,
  464. help="Ignored for compatibility.")
  465. op.add_option('-c', '--clean', '--remove',
  466. dest="clean", default=False,
  467. action="store_true",
  468. help="Remove specified targets and dependencies.")
  469. op.add_option('-C', '--directory',
  470. nargs=1, type="string",
  471. dest="directory", default=[],
  472. action="append",
  473. help="Change to DIR before doing anything.",
  474. metavar="DIR")
  475. op.add_option('--cache-debug',
  476. nargs=1,
  477. dest="cache_debug", default=None,
  478. action="store",
  479. help="Print CacheDir debug info to FILE.",
  480. metavar="FILE")
  481. op.add_option('--cache-disable', '--no-cache',
  482. dest='cache_disable', default=False,
  483. action="store_true",
  484. help="Do not retrieve built targets from CacheDir.")
  485. op.add_option('--cache-force', '--cache-populate',
  486. dest='cache_force', default=False,
  487. action="store_true",
  488. help="Copy already-built targets into the CacheDir.")
  489. op.add_option('--cache-show',
  490. dest='cache_show', default=False,
  491. action="store_true",
  492. help="Print build actions for files from CacheDir.")
  493. config_options = ["auto", "force" ,"cache"]
  494. def opt_config(option, opt, value, parser, c_options=config_options):
  495. if not value in c_options:
  496. raise OptionValueError("Warning: %s is not a valid config type" % value)
  497. setattr(parser.values, option.dest, value)
  498. opt_config_help = "Controls Configure subsystem: %s." \
  499. % ", ".join(config_options)
  500. op.add_option('--config',
  501. nargs=1, type="string",
  502. dest="config", default="auto",
  503. action="callback", callback=opt_config,
  504. help = opt_config_help,
  505. metavar="MODE")
  506. op.add_option('-D',
  507. dest="climb_up", default=None,
  508. action="store_const", const=2,
  509. help="Search up directory tree for SConstruct, "
  510. "build all Default() targets.")
  511. deprecated_debug_options = {
  512. "dtree" : '; please use --tree=derived instead',
  513. "nomemoizer" : ' and has no effect',
  514. "stree" : '; please use --tree=all,status instead',
  515. "tree" : '; please use --tree=all instead',
  516. }
  517. debug_options = ["count", "explain", "findlibs",
  518. "includes", "memoizer", "memory", "objects",
  519. "pdb", "presub", "stacktrace",
  520. "time"] + list(deprecated_debug_options.keys())
  521. def opt_debug(option, opt, value, parser,
  522. debug_options=debug_options,
  523. deprecated_debug_options=deprecated_debug_options):
  524. if value in debug_options:
  525. parser.values.debug.append(value)
  526. if value in deprecated_debug_options.keys():
  527. try:
  528. parser.values.delayed_warnings
  529. except AttributeError:
  530. parser.values.delayed_warnings = []
  531. msg = deprecated_debug_options[value]
  532. w = "The --debug=%s option is deprecated%s." % (value, msg)
  533. t = (SCons.Warnings.DeprecatedDebugOptionsWarning, w)
  534. parser.values.delayed_warnings.append(t)
  535. else:
  536. raise OptionValueError("Warning: %s is not a valid debug type" % value)
  537. opt_debug_help = "Print various types of debugging information: %s." \
  538. % ", ".join(debug_options)
  539. op.add_option('--debug',
  540. nargs=1, type="string",
  541. dest="debug", default=[],
  542. action="callback", callback=opt_debug,
  543. help=opt_debug_help,
  544. metavar="TYPE")
  545. def opt_diskcheck(option, opt, value, parser):
  546. try:
  547. diskcheck_value = diskcheck_convert(value)
  548. except ValueError, e:
  549. raise OptionValueError("Warning: `%s' is not a valid diskcheck type" % e)
  550. setattr(parser.values, option.dest, diskcheck_value)
  551. op.add_option('--diskcheck',
  552. nargs=1, type="string",
  553. dest='diskcheck', default=None,
  554. action="callback", callback=opt_diskcheck,
  555. help="Enable specific on-disk checks.",
  556. metavar="TYPE")
  557. def opt_duplicate(option, opt, value, parser):
  558. if not value in SCons.Node.FS.Valid_Duplicates:
  559. raise OptionValueError("`%s' is not a valid duplication style." % value)
  560. setattr(parser.values, option.dest, value)
  561. # Set the duplicate style right away so it can affect linking
  562. # of SConscript files.
  563. SCons.Node.FS.set_duplicate(value)
  564. opt_duplicate_help = "Set the preferred duplication methods. Must be one of " \
  565. + ", ".join(SCons.Node.FS.Valid_Duplicates)
  566. op.add_option('--duplicate',
  567. nargs=1, type="string",
  568. dest="duplicate", default='hard-soft-copy',
  569. action="callback", callback=opt_duplicate,
  570. help=opt_duplicate_help)
  571. op.add_option('-f', '--file', '--makefile', '--sconstruct',
  572. nargs=1, type="string",
  573. dest="file", default=[],
  574. action="append",
  575. help="Read FILE as the top-level SConstruct file.")
  576. op.add_option('-h', '--help',
  577. dest="help", default=False,
  578. action="store_true",
  579. help="Print defined help message, or this one.")
  580. op.add_option("-H", "--help-options",
  581. action="help",
  582. help="Print this message and exit.")
  583. op.add_option('-i', '--ignore-errors',
  584. dest='ignore_errors', default=False,
  585. action="store_true",
  586. help="Ignore errors from build actions.")
  587. op.add_option('-I', '--include-dir',
  588. nargs=1,
  589. dest='include_dir', default=[],
  590. action="append",
  591. help="Search DIR for imported Python modules.",
  592. metavar="DIR")
  593. op.add_option('--implicit-cache',
  594. dest='implicit_cache', default=False,
  595. action="store_true",
  596. help="Cache implicit dependencies")
  597. def opt_implicit_deps(option, opt, value, parser):
  598. setattr(parser.values, 'implicit_cache', True)
  599. setattr(parser.values, option.dest, True)
  600. op.add_option('--implicit-deps-changed',
  601. dest="implicit_deps_changed", default=False,
  602. action="callback", callback=opt_implicit_deps,
  603. help="Ignore cached implicit dependencies.")
  604. op.add_option('--implicit-deps-unchanged',
  605. dest="implicit_deps_unchanged", default=False,
  606. action="callback", callback=opt_implicit_deps,
  607. help="Ignore changes in implicit dependencies.")
  608. op.add_option('--interact', '--interactive',
  609. dest='interactive', default=False,
  610. action="store_true",
  611. help="Run in interactive mode.")
  612. op.add_option('-j', '--jobs',
  613. nargs=1, type="int",
  614. dest="num_jobs", default=1,
  615. action="store",
  616. help="Allow N jobs at once.",
  617. metavar="N")
  618. op.add_option('-k', '--keep-going',
  619. dest='keep_going', default=False,
  620. action="store_true",
  621. help="Keep going when a target can't be made.")
  622. op.add_option('--max-drift',
  623. nargs=1, type="int",
  624. dest='max_drift', default=SCons.Node.FS.default_max_drift,
  625. action="store",
  626. help="Set maximum system clock drift to N seconds.",
  627. metavar="N")
  628. op.add_option('--md5-chunksize',
  629. nargs=1, type="int",
  630. dest='md5_chunksize', default=SCons.Node.FS.File.md5_chunksize,
  631. action="store",
  632. help="Set chunk-size for MD5 signature computation to N kilobytes.",
  633. metavar="N")
  634. op.add_option('-n', '--no-exec', '--just-print', '--dry-run', '--recon',
  635. dest='no_exec', default=False,
  636. action="store_true",
  637. help="Don't build; just print commands.")
  638. op.add_option('--no-site-dir',
  639. dest='no_site_dir', default=False,
  640. action="store_true",
  641. help="Don't search or use the usual site_scons dir.")
  642. op.add_option('--profile',
  643. nargs=1,
  644. dest="profile_file", default=None,
  645. action="store",
  646. help="Profile SCons and put results in FILE.",
  647. metavar="FILE")
  648. op.add_option('-q', '--question',
  649. dest="question", default=False,
  650. action="store_true",
  651. help="Don't build; exit status says if up to date.")
  652. op.add_option('-Q',
  653. dest='no_progress', default=False,
  654. action="store_true",
  655. help="Suppress \"Reading/Building\" progress messages.")
  656. op.add_option('--random',
  657. dest="random", default=False,
  658. action="store_true",
  659. help="Build dependencies in random order.")
  660. op.add_option('-s', '--silent', '--quiet',
  661. dest="silent", default=False,
  662. action="store_true",
  663. help="Don't print commands.")
  664. op.add_option('--site-dir',
  665. nargs=1,
  666. dest='site_dir', default=None,
  667. action="store",
  668. help="Use DIR instead of the usual site_scons dir.",
  669. metavar="DIR")
  670. op.add_option('--stack-size',
  671. nargs=1, type="int",
  672. dest='stack_size',
  673. action="store",
  674. help="Set the stack size of the threads used to run jobs to N kilobytes.",
  675. metavar="N")
  676. op.add_option('--taskmastertrace',
  677. nargs=1,
  678. dest="taskmastertrace_file", default=None,
  679. action="store",
  680. help="Trace Node evaluation to FILE.",
  681. metavar="FILE")
  682. tree_options = ["all", "derived", "prune", "status"]
  683. def opt_tree(option, opt, value, parser, tree_options=tree_options):
  684. import Main
  685. tp = Main.TreePrinter()
  686. for o in value.split(','):
  687. if o == 'all':
  688. tp.derived = False
  689. elif o == 'derived':
  690. tp.derived = True
  691. elif o == 'prune':
  692. tp.prune = True
  693. elif o == 'status':
  694. tp.status = True
  695. else:
  696. raise OptionValueError("Warning: %s is not a valid --tree option" % o)
  697. parser.values.tree_printers.append(tp)
  698. opt_tree_help = "Print a dependency tree in various formats: %s." \
  699. % ", ".join(tree_options)
  700. op.add_option('--tree',
  701. nargs=1, type="string",
  702. dest="tree_printers", default=[],
  703. action="callback", callback=opt_tree,
  704. help=opt_tree_help,
  705. metavar="OPTIONS")
  706. op.add_option('-u', '--up', '--search-up',
  707. dest="climb_up", default=0,
  708. action="store_const", const=1,
  709. help="Search up directory tree for SConstruct, "
  710. "build targets at or below current directory.")
  711. op.add_option('-U',
  712. dest="climb_up", default=0,
  713. action="store_const", const=3,
  714. help="Search up directory tree for SConstruct, "
  715. "build Default() targets from local SConscript.")
  716. def opt_version(option, opt, value, parser):
  717. sys.stdout.write(parser.version + '\n')
  718. sys.exit(0)
  719. op.add_option("-v", "--version",
  720. action="callback", callback=opt_version,
  721. help="Print the SCons version number and exit.")
  722. def opt_warn(option, opt, value, parser, tree_options=tree_options):
  723. if SCons.Util.is_String(value):
  724. value = value.split(',')
  725. parser.values.warn.extend(value)
  726. op.add_option('--warn', '--warning',
  727. nargs=1, type="string",
  728. dest="warn", default=[],
  729. action="callback", callback=opt_warn,
  730. help="Enable or disable warnings.",
  731. metavar="WARNING-SPEC")
  732. op.add_option('-Y', '--repository', '--srcdir',
  733. nargs=1,
  734. dest="repository", default=[],
  735. action="append",
  736. help="Search REPOSITORY for source and target files.")
  737. # Options from Make and Cons classic that we do not yet support,
  738. # but which we may support someday and whose (potential) meanings
  739. # we don't want to change. These all get a "the -X option is not
  740. # yet implemented" message and don't show up in the help output.
  741. def opt_not_yet(option, opt, value, parser):
  742. msg = "Warning: the %s option is not yet implemented\n" % opt
  743. sys.stderr.write(msg)
  744. op.add_option('-l', '--load-average', '--max-load',
  745. nargs=1, type="int",
  746. dest="load_average", default=0,
  747. action="callback", callback=opt_not_yet,
  748. # action="store",
  749. # help="Don't start multiple jobs unless load is below "
  750. # "LOAD-AVERAGE."
  751. help=SUPPRESS_HELP)
  752. op.add_option('--list-actions',
  753. dest="list_actions",
  754. action="callback", callback=opt_not_yet,
  755. # help="Don't build; list files and build actions."
  756. help=SUPPRESS_HELP)
  757. op.add_option('--list-derived',
  758. dest="list_derived",
  759. action="callback", callback=opt_not_yet,
  760. # help="Don't build; list files that would be built."
  761. help=SUPPRESS_HELP)
  762. op.add_option('--list-where',
  763. dest="list_where",
  764. action="callback", callback=opt_not_yet,
  765. # help="Don't build; list files and where defined."
  766. help=SUPPRESS_HELP)
  767. op.add_option('-o', '--old-file', '--assume-old',
  768. nargs=1, type="string",
  769. dest="old_file", default=[],
  770. action="callback", callback=opt_not_yet,
  771. # action="append",
  772. # help = "Consider FILE to be old; don't rebuild it."
  773. help=SUPPRESS_HELP)
  774. op.add_option('--override',
  775. nargs=1, type="string",
  776. action="callback", callback=opt_not_yet,
  777. dest="override",
  778. # help="Override variables as specified in FILE."
  779. help=SUPPRESS_HELP)
  780. op.add_option('-p',
  781. action="callback", callback=opt_not_yet,
  782. dest="p",
  783. # help="Print internal environments/objects."
  784. help=SUPPRESS_HELP)
  785. op.add_option('-r', '-R', '--no-builtin-rules', '--no-builtin-variables',
  786. action="callback", callback=opt_not_yet,
  787. dest="no_builtin_rules",
  788. # help="Clear default environments and variables."
  789. help=SUPPRESS_HELP)
  790. op.add_option('--write-filenames',
  791. nargs=1, type="string",
  792. dest="write_filenames",
  793. action="callback", callback=opt_not_yet,
  794. # help="Write all filenames examined into FILE."
  795. help=SUPPRESS_HELP)
  796. op.add_option('-W', '--new-file', '--assume-new', '--what-if',
  797. nargs=1, type="string",
  798. dest="new_file",
  799. action="callback", callback=opt_not_yet,
  800. # help="Consider FILE to be changed."
  801. help=SUPPRESS_HELP)
  802. op.add_option('--warn-undefined-variables',
  803. dest="warn_undefined_variables",
  804. action="callback", callback=opt_not_yet,
  805. # help="Warn when an undefined variable is referenced."
  806. help=SUPPRESS_HELP)
  807. return op
  808. # Local Variables:
  809. # tab-width:4
  810. # indent-tabs-mode:nil
  811. # End:
  812. # vim: set expandtab tabstop=4 shiftwidth=4: