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

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

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

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

@ -4,26 +4,10 @@
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
from collections import OrderedDict
import inspect
import os import os
import six import six
import sys import sys
from collections import OrderedDict
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)
def istupleofstrings(obj): def istupleofstrings(obj):
@ -174,24 +158,14 @@ class Option(object):
- `help` is the option description for use in the --help output. - `help` is the option description for use in the --help output.
- `possible_origins` is a tuple of strings that are origins accepted for - `possible_origins` is a tuple of strings that are origins accepted for
this option. Example origins are 'mozconfig', 'implied', and 'environment'. 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__ = ( __slots__ = (
'id', 'prefix', 'name', 'env', 'nargs', 'default', 'choices', 'help', '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, def __init__(self, name=None, env=None, nargs=None, default=None,
possible_origins=None, choices=None, category=None, help=None, possible_origins=None, choices=None, help=None):
define_depth=0):
if not name and not env: if not name and not env:
raise InvalidOptionError( raise InvalidOptionError(
'At least an option name or an environment variable name must ' 'At least an option name or an environment variable name must '
@ -224,14 +198,6 @@ class Option(object):
if choices and not istupleofstrings(choices): if choices and not istupleofstrings(choices):
raise InvalidOptionError( raise InvalidOptionError(
'choices must be a tuple of strings') '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: if not help:
raise InvalidOptionError('A help string must be provided') raise InvalidOptionError('A help string must be provided')
if possible_origins and not istupleofstrings(possible_origins): if possible_origins and not istupleofstrings(possible_origins):
@ -301,7 +267,6 @@ class Option(object):
raise InvalidOptionError('Not enough `choices` for `nargs`') raise InvalidOptionError('Not enough `choices` for `nargs`')
self.choices = choices self.choices = choices
self.help = help self.help = help
self.category = category or _infer_option_category(define_depth)
@staticmethod @staticmethod
def split_option(option): def split_option(option):

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

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