Backed out changeset 015fd18edd63 (bug 1582155) for python failures on test_configure.py.

--HG--
extra : rebase_source : 0d9dcf79f447a91fb8acf3a41e91a0c18c1d8c7e
This commit is contained in:
Cosmin Sabou 2019-10-21 19:05:02 +03:00
Родитель 4900ffa1bc
Коммит af6083b6c6
6 изменённых файлов: 47 добавлений и 136 удалений

Просмотреть файл

@ -19,7 +19,6 @@ from functools import wraps
from mozbuild.configure.options import (
CommandLineHelper,
ConflictingOptionError,
HELP_OPTIONS_CATEGORY,
InvalidOptionError,
Option,
OptionValue,
@ -344,9 +343,6 @@ class ConfigureSandbox(dict):
assert isinstance(config, dict)
self._config = config
# Tracks how many templates "deep" we are in the stack.
self._template_depth = 0
logging.addLevelName(TRACE, 'TRACE')
if logger is None:
logger = moz_logger = logging.getLogger('moz.configure')
@ -392,8 +388,8 @@ class ConfigureSandbox(dict):
self.log_impl = ReadOnlyNamespace(**log_namespace)
self._help = None
self._help_option = self.option_impl(
'--help', help='print this message', category=HELP_OPTIONS_CATEGORY)
self._help_option = self.option_impl('--help',
help='print this message')
self._seen.add(self._help_option)
self._always = DependsFunction(self, lambda: True, [])
@ -680,12 +676,6 @@ class ConfigureSandbox(dict):
args = [self._resolve(arg) for arg in args]
kwargs = {k: self._resolve(v) for k, v in six.iteritems(kwargs)
if k != 'when'}
# The Option constructor needs to look up the stack to infer a category
# for the Option, since the category is based on the filename where the
# Option is defined. However, if the Option is defined in a template, we
# want the category to reference the caller of the template rather than
# the caller of the option() function.
kwargs['define_depth'] = self._template_depth * 3
option = Option(*args, **kwargs)
if when:
self._conditions[option] = when
@ -808,9 +798,7 @@ class ConfigureSandbox(dict):
args = [maybe_prepare_function(arg) for arg in args]
kwargs = {k: maybe_prepare_function(v)
for k, v in kwargs.items()}
self._template_depth += 1
ret = template(*args, **kwargs)
self._template_depth -= 1
if isfunction(ret):
# We can't expect the sandboxed code to think about all the
# details of implementing decorators, so do some of the

Просмотреть файл

@ -4,7 +4,6 @@
from __future__ import absolute_import, print_function, unicode_literals
from collections import defaultdict
import os
import re
from mozbuild.configure.options import Option
@ -13,38 +12,33 @@ from mozbuild.configure.options import Option
class HelpFormatter(object):
def __init__(self, argv0):
self.intro = ['Usage: %s [options]' % os.path.basename(argv0)]
self.options = []
self.options = ['Options: [defaults in brackets after descriptions]']
self.env = ['Environment variables:']
def add(self, option):
assert isinstance(option, Option)
if option.possible_origins == ('implied',):
# Don't display help if our option can only be implied.
return
self.options.append(option)
def format_options_by_category(self, options_by_category):
ret = []
for category, options in sorted(options_by_category.items(),
key=lambda x: x[0]):
ret.append(' ' + category + ':')
for option in sorted(options, key=lambda opt: opt.option):
opt = option.option
if option.choices:
opt += '={%s}' % ','.join(option.choices)
help = self.format_help(option)
if len(option.default):
if help:
help += ' '
help += '[%s]' % ','.join(option.default)
# TODO: improve formatting
target = self.options if option.name else self.env
opt = option.option
if option.choices:
opt += '={%s}' % ','.join(option.choices)
help = self.format_help(option)
if len(option.default):
if help:
help += ' '
help += '[%s]' % ','.join(option.default)
if len(opt) > 24 or not help:
ret.append(' %s' % opt)
if help:
ret.append('%s%s' % (' ' * 30, help))
else:
ret.append(' %-24s %s' % (opt, help))
ret.append('')
return ret
if len(opt) > 24 or not help:
target.append(' %s' % opt)
if help:
target.append('%s%s' % (' ' * 28, help))
else:
target.append(' %-24s %s' % (opt, help))
RE_FORMAT = re.compile(r'{([^|}]*)\|([^|}]*)}')
@ -71,17 +65,6 @@ class HelpFormatter(object):
return self.RE_FORMAT.sub(replacement, option.help)
def usage(self, out):
options_by_category = defaultdict(list)
env_by_category = defaultdict(list)
for option in self.options:
target = options_by_category if option.name else env_by_category
target[option.category].append(option)
options_formatted = [
'Options: [defaults in brackets after descriptions]'
] + self.format_options_by_category(options_by_category)
env_formatted = (['Environment variables:'] +
self.format_options_by_category(env_by_category))
print('\n\n'.join('\n'.join(t)
for t in (self.intro, options_formatted,
env_formatted)),
for t in (self.intro, self.options, self.env)),
file=out)

Просмотреть файл

@ -4,26 +4,10 @@
from __future__ import absolute_import, print_function, unicode_literals
from collections import OrderedDict
import inspect
import os
import six
import sys
HELP_OPTIONS_CATEGORY = 'Help options'
# List of whitelisted option categories. If you want to add a new category,
# simply add it to this list; however, exercise discretion as
# "./configure --help" becomes less useful if there are an excessive number of
# categories.
_ALL_CATEGORIES = (
HELP_OPTIONS_CATEGORY,
)
def _infer_option_category(define_depth):
stack_frame = inspect.stack()[3 + define_depth]
return 'Options from ' + os.path.relpath(stack_frame[0].f_code.co_filename)
from collections import OrderedDict
def istupleofstrings(obj):
@ -174,24 +158,14 @@ class Option(object):
- `help` is the option description for use in the --help output.
- `possible_origins` is a tuple of strings that are origins accepted for
this option. Example origins are 'mozconfig', 'implied', and 'environment'.
- `category` is a human-readable string used only for categorizing command-
line options when displaying the output of `configure --help`. If not
supplied, the script will attempt to infer an appropriate category based
on the name of the file where the option was defined. If supplied it must
be in the _ALL_CATEGORIES list above.
- `define_depth` should generally only be used by templates that are used
to instantiate an option indirectly. Set this to a positive integer to
force the script to look into a deeper stack frame when inferring the
`category`.
'''
__slots__ = (
'id', 'prefix', 'name', 'env', 'nargs', 'default', 'choices', 'help',
'possible_origins', 'category', 'define_depth',
'possible_origins',
)
def __init__(self, name=None, env=None, nargs=None, default=None,
possible_origins=None, choices=None, category=None, help=None,
define_depth=0):
possible_origins=None, choices=None, help=None):
if not name and not env:
raise InvalidOptionError(
'At least an option name or an environment variable name must '
@ -224,14 +198,6 @@ class Option(object):
if choices and not istupleofstrings(choices):
raise InvalidOptionError(
'choices must be a tuple of strings')
if category and not isinstance(category, six.string_types):
raise InvalidOptionError('Category must be a string')
if category and category not in _ALL_CATEGORIES:
raise InvalidOptionError(
'Category must either be inferred or in the _ALL_CATEGORIES '
'list in options.py: %s' % ', '.join(_ALL_CATEGORIES))
if not isinstance(define_depth, int):
raise InvalidOptionError('DefineDepth must be an integer')
if not help:
raise InvalidOptionError('A help string must be provided')
if possible_origins and not istupleofstrings(possible_origins):
@ -301,7 +267,6 @@ class Option(object):
raise InvalidOptionError('Not enough `choices` for `nargs`')
self.choices = choices
self.help = help
self.category = category or _infer_option_category(define_depth)
@staticmethod
def split_option(option):

Просмотреть файл

@ -51,7 +51,3 @@ def check(value):
return platform()
set_config('PLATFORM', check)
@template
def indirectly_define_option(*args, **kwargs):
option(*args, **kwargs)

Просмотреть файл

@ -170,10 +170,3 @@ def with_imports(value):
return hasattr(os.path, 'getatime')
set_config('HAS_GETATIME2', with_imports)
# This option should be attributed to this file in the --help output even though
# included.configure is the actual file that defines the option.
indirectly_define_option('--indirect-option', help='Indirectly defined option')
@depends('--indirect-option')
def indirect_option(option):
return option

Просмотреть файл

@ -42,7 +42,7 @@ class TestConfigure(unittest.TestCase):
sandbox.run(mozpath.join(test_data_path, configure))
if '--help' in options:
return out.getvalue().decode('utf-8'), config
return out.getvalue(), config
self.assertEquals('', out.getvalue())
return config
@ -77,30 +77,24 @@ class TestConfigure(unittest.TestCase):
'Usage: configure [options]\n'
'\n'
'Options: [defaults in brackets after descriptions]\n'
' Help options:\n'
' --help print this message\n'
'\n'
' Options from python/mozbuild/mozbuild/test/configure/data/included.configure:\n'
' --enable-imports-in-template\n Imports in template\n'
'\n'
' Options from python/mozbuild/mozbuild/test/configure/data/moz.configure:\n'
' --enable-include Include\n'
' --enable-simple Enable simple\n'
' --enable-values Enable values\n'
' --enable-with-env Enable with env\n'
' --indirect-option Indirectly defined option\n'
' --option Option\n'
' --returned-choices Choices\n'
' --with-imports Imports\n'
' --with-returned-default Returned default [not-simple]\n'
' --with-stuff Build with stuff\n'
' --without-thing Build without thing\n'
'\n'
' --help print this message\n'
' --enable-simple Enable simple\n'
' --enable-with-env Enable with env\n'
' --enable-values Enable values\n'
' --without-thing Build without thing\n'
' --with-stuff Build with stuff\n'
' --option Option\n'
' --with-returned-default Returned default [not-simple]\n'
' --returned-choices Choices\n'
' --enable-imports-in-template\n'
' Imports in template\n'
' --enable-include Include\n'
' --with-imports Imports\n'
'\n'
'Environment variables:\n'
' Options from python/mozbuild/mozbuild/test/configure/data/moz.configure:\n'
' CC C Compiler\n'
'\n', help)
' CC C Compiler\n',
help
)
def test_unknown(self):
with self.assertRaises(InvalidOptionError):
@ -1013,12 +1007,8 @@ class TestConfigure(unittest.TestCase):
Usage: configure [options]
Options: [defaults in brackets after descriptions]
Help options:
--help print this message
Options from python/mozbuild/mozbuild/test/configure/data/moz.configure:
--with-foo foo
--help print this message
--with-foo foo
Environment variables:
'''))
@ -1028,13 +1018,9 @@ class TestConfigure(unittest.TestCase):
Usage: configure [options]
Options: [defaults in brackets after descriptions]
Help options:
--help print this message
Options from python/mozbuild/mozbuild/test/configure/data/moz.configure:
--with-foo foo
--with-qux qux
--help print this message
--with-foo foo
--with-qux qux
Environment variables:
'''))