mozbuild.configure package

Submodules

mozbuild.configure.check_debug_ranges module

mozbuild.configure.check_debug_ranges.get_range_for(compilation_unit, debug_info)

Returns the range offset for a given compilation unit in a given debug_info.

mozbuild.configure.check_debug_ranges.get_range_length(range, debug_ranges)

Returns the number of items in the range starting at the given offset.

mozbuild.configure.check_debug_ranges.main(bin, compilation_unit)

mozbuild.configure.constants module

mozbuild.configure.help module

class mozbuild.configure.help.HelpFormatter(argv0)

Bases: object

add(option)
usage(out)

mozbuild.configure.libstdcxx module

mozbuild.configure.libstdcxx.cmp_ver(a, b)

Compare versions in the form ‘a.b.c’

mozbuild.configure.libstdcxx.encode_ver(v)

Encode the version as a single number.

mozbuild.configure.libstdcxx.find_version(e)

Given the value of environment variable CXX or HOST_CXX, find the version of the libstdc++ it uses.

mozbuild.configure.libstdcxx.parse_ld_line(x)

Parse a line from the output of ld -t. The output of gold is just the full path, gnu ld prints “-lstdc++ (path)”.

mozbuild.configure.libstdcxx.parse_readelf_line(x)

Return the version from a readelf line that looks like: 0x00ec: Rev: 1 Flags: none Index: 8 Cnt: 2 Name: GLIBCXX_3.4.6

mozbuild.configure.libstdcxx.split_ver(v)

Covert the string ‘1.2.3’ into the list [1,2,3]

mozbuild.configure.options module

class mozbuild.configure.options.CommandLineHelper(environ={'LANG': 'C.UTF-8', 'READTHEDOCS_PROJECT': 'gfritzsche-demo', 'READTHEDOCS': 'True', 'APPDIR': '/app', 'DEBIAN_FRONTEND': 'noninteractive', 'OLDPWD': '/', 'HOSTNAME': 'build-4258433-project-55928-gfritzsche-demo', u'SHELL': u'/bin/bash', 'PWD': '/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/checkouts/latest/tools/docs', 'BIN_PATH': '/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/envs/latest/bin', 'READTHEDOCS_VERSION': 'latest', 'PATH': '/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/checkouts/latest/tools/docs/_build/html/_venv/bin:/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/envs/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME': '/home/docs'}, argv=['/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/envs/latest/bin/sphinx-build', '-T', '-E', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])

Bases: object

Helper class to handle the various ways options can be given either on the command line of through the environment.

For instance, an Option(‘–foo’, env=’FOO’) can be passed as –foo on the command line, or as FOO=1 in the environment or on the command line.

If multiple variants are given, command line is prefered over the environment, and if different values are given on the command line, the last one wins. (This mimicks the behavior of autoconf, avoiding to break existing mozconfigs using valid options in weird ways)

Extra options can be added afterwards through API calls. For those, conflicting values will raise an exception.

add(arg, origin=u'command-line', args=None)
handle(option)

Return the OptionValue corresponding to the given Option instance, depending on the command line, environment, and extra arguments, and the actual option or variable that set it. Only works once for a given Option.

exception mozbuild.configure.options.ConflictingOptionError(message, **format_data)

Bases: mozbuild.configure.options.InvalidOptionError

exception mozbuild.configure.options.InvalidOptionError

Bases: exceptions.Exception

class mozbuild.configure.options.NegativeOptionValue(origin=u'unknown')

Bases: mozbuild.configure.options.OptionValue

Represents the value for a negative option (–disable/–without)

This is effectively an empty tuple with a origin attribute.

class mozbuild.configure.options.Option(name=None, env=None, nargs=None, default=None, possible_origins=None, choices=None, help=None)

Bases: object

Represents a configure option

A configure option can be a command line flag or an environment variable or both.

  • name is the full command line flag (e.g. –enable-foo).
  • env is the environment variable name (e.g. ENV)
  • nargs is the number of arguments the option may take. It can be a number or the special values ‘?’ (0 or 1), ‘*’ (0 or more), or ‘+’ (1 or more).
  • default can be used to give a default value to the option. When the name of the option starts with ‘–enable-‘ or ‘–with-‘, the implied default is an empty PositiveOptionValue. When it starts with ‘–disable-‘ or ‘–without-‘, the implied default is a NegativeOptionValue.
  • choices restricts the set of values that can be given to the option.
  • 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’.
choices
default
env
get_value(option=None, origin=u'unknown')

Given a full command line option (e.g. –enable-foo=bar) or a variable assignment (FOO=bar), returns the corresponding OptionValue.

Note: variable assignments can come from either the environment or from the command line (e.g. ../configure CFLAGS=-O2)

help
id
maxargs
minargs
name
nargs
option
possible_origins
prefix
static split_option(option)

Split a flag or variable into a prefix, a name and values

Variables come in the form NAME=values (no prefix). Flags come in the form –name=values or –prefix-name=values where prefix is one of ‘with’, ‘without’, ‘enable’ or ‘disable’. The ‘=values’ part is optional. Values are separated with commas.

class mozbuild.configure.options.OptionValue(values=(), origin=u'unknown')

Bases: tuple

Represents the value of a configure option.

This class is not meant to be used directly. Use its subclasses instead.

The origin attribute holds where the option comes from (e.g. environment, command line, or default)

format(option)
class mozbuild.configure.options.PositiveOptionValue(values=(), origin=u'unknown')

Bases: mozbuild.configure.options.OptionValue

Represents the value for a positive option (–enable/–with/–foo) in the form of a tuple for when values are given to the option (in the form –option=value[,value2...].

mozbuild.configure.options.istupleofstrings(obj)

mozbuild.configure.util module

class mozbuild.configure.util.ConfigureOutputHandler(stdout=<open file '<stdout>', mode 'w'>, stderr=<open file '<stderr>', mode 'w'>, maxlen=20)

Bases: logging.Handler

A logging handler class that sends info messages to stdout and other messages to stderr.

Messages sent to stdout are not formatted with the attached Formatter. Additionally, if they end with ‘... ‘, no newline character is printed, making the next message printed follow the ‘... ‘.

Only messages above log level INFO (included) are logged.

Messages below that level can be kept until an ERROR message is received, at which point the last maxlen accumulated messages below INFO are printed out. This feature is only enabled under the queue_debug context manager.

INTERRUPTED = 2
KEEP = 1
PRINT = 2
THROW = 0
WAITING = 1
emit(record)
queue_debug(*args, **kwds)
class mozbuild.configure.util.LineIO(callback)

Bases: object

File-like class that sends each line of the written data to a callback (without carriage returns).

close()
write(buf)
class mozbuild.configure.util.Version(version)

Bases: distutils.version.LooseVersion

A simple subclass of distutils.version.LooseVersion. Adds attributes for major, minor, patch for the first three version components so users can easily pull out major/minor versions, like:

v = Version(‘1.2b’) v.major == 1 v.minor == 2 v.patch == 0

mozbuild.configure.util.getpreferredencoding()

Module contents

exception mozbuild.configure.ConfigureError

Bases: exceptions.Exception

class mozbuild.configure.ConfigureSandbox(config, environ={'LANG': 'C.UTF-8', 'READTHEDOCS_PROJECT': 'gfritzsche-demo', 'READTHEDOCS': 'True', 'APPDIR': '/app', 'DEBIAN_FRONTEND': 'noninteractive', 'OLDPWD': '/', 'HOSTNAME': 'build-4258433-project-55928-gfritzsche-demo', u'SHELL': u'/bin/bash', 'PWD': '/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/checkouts/latest/tools/docs', 'BIN_PATH': '/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/envs/latest/bin', 'READTHEDOCS_VERSION': 'latest', 'PATH': '/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/checkouts/latest/tools/docs/_build/html/_venv/bin:/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/envs/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME': '/home/docs'}, argv=['/home/docs/checkouts/readthedocs.org/user_builds/gfritzsche-demo/envs/latest/bin/sphinx-build', '-T', '-E', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'], stdout=<open file '<stdout>', mode 'w'>, stderr=<open file '<stderr>', mode 'w'>, logger=None)

Bases: dict

Represents a sandbox for executing Python code for build configuration. This is a different kind of sandboxing than the one used for moz.build processing.

The sandbox has 8 primitives: - option - depends - template - imports - include - set_config - set_define - imply_option

option, include, set_config, set_define and imply_option are functions. depends, template, and imports are decorators.

These primitives are declared as name_impl methods to this class and the mapping name -> name_impl is done automatically in __getitem__.

Additional primitives should be frowned upon to keep the sandbox itself as simple as possible. Instead, helpers should be created within the sandbox with the existing primitives.

The sandbox is given, at creation, a dict where the yielded configuration will be stored.

config = {} sandbox = ConfigureSandbox(config) sandbox.run(path) do_stuff(config)
BUILTINS = {u'None': None, u'set': <type 'set'>, u'tuple': <type 'tuple'>, u'int': <type 'int'>, '__import__': <function forbidden_import at 0x7ff501a7f668>, u'all': <built-in function all>, u'len': <built-in function len>, u'enumerate': <type 'enumerate'>, u'isinstance': <built-in function isinstance>, u'any': <built-in function any>, u'hasattr': <built-in function hasattr>, u'False': False, u'zip': <built-in function zip>, u'list': <type 'list'>, u'getattr': <built-in function getattr>, u'range': <built-in function range>, u'bool': <type 'bool'>, 'str': <type 'unicode'>, u'dict': <type 'dict'>, u'True': True}
OS = <ReadOnlyNamespace {'path': <ReadOnlyNamespace {'isdir': <function isdir at 0x7ff5093ed1b8>, 'realpath': <function realpath at 0x7ff505089140>, 'join': <function join at 0x7ff505089230>, 'exists': <function exists at 0x7ff5093ed0c8>, 'abspath': <function abspath at 0x7ff5050891b8>, 'isabs': <function isabs at 0x7ff5093f8050>, 'normcase': <function normcase at 0x7ff5093edf50>, 'normpath': <function normpath at 0x7ff5050892a8>, 'dirname': <function dirname at 0x7ff505089320>, 'isfile': <function isfile at 0x7ff5093ed140>, 'basename': <function basename at 0x7ff505089410>, 'relpath': <function relpath at 0x7ff5050890c8>}>}>
RE_MODULE = <_sre.SRE_Pattern object>
depends_impl(*args)

Implementation of @depends() This function is a decorator. It returns a function that subsequently takes a function and returns a dummy function. The dummy function identifies the actual function for the sandbox, while preventing further function calls from within the sandbox.

@depends() takes a variable number of option strings or dummy function references. The decorated function is called as soon as the decorator is called, and the arguments it receives are the OptionValue or function results corresponding to each of the arguments to @depends. As an exception, when a HelpFormatter is attached, only functions that have ‘–help’ in their @depends argument list are called.

The decorated function is altered to use a different global namespace for its execution. This different global namespace exposes a limited set of functions from os.path.

imply_option_impl(option, value, reason=None)

Implementation of imply_option(). Injects additional options as if they had been passed on the command line. The option argument is a string as in option()’s name or env. The option must be declared after imply_option references it. The value argument indicates the value to pass to the option. It can be: - True. In this case imply_option injects the positive option

(–enable-foo/–with-foo).
imply_option(‘–enable-foo’, True) imply_option(‘–disable-foo’, True)

are both equivalent to –enable-foo on the command line.

  • False. In this case imply_option injects the negative option (–disable-foo/–without-foo).

    imply_option(‘–enable-foo’, False) imply_option(‘–disable-foo’, False)

    are both equivalent to –disable-foo on the command line.

  • None. In this case imply_option does nothing.

    imply_option(‘–enable-foo’, None) imply_option(‘–disable-foo’, None)

    are both equivalent to not passing any flag on the command line.

  • a string or a tuple. In this case imply_option injects the positive option with the given value(s).

    imply_option(‘–enable-foo’, ‘a’) imply_option(‘–disable-foo’, ‘a’)

    are both equivalent to –enable-foo=a on the command line.

    imply_option(‘–enable-foo’, (‘a’, ‘b’)) imply_option(‘–disable-foo’, (‘a’, ‘b’))

    are both equivalent to –enable-foo=a,b on the command line.

Because imply_option(‘–disable-foo’, ...) can be misleading, it is recommended to use the positive form (‘–enable’ or ‘–with’) for option.

The value argument can also be (and usually is) a reference to a @depends function, in which case the result of that function will be used as per the descripted mapping above.

The reason argument indicates what caused the option to be implied. It is necessary when it cannot be inferred from the value.

imports_impl(_import, _from=None, _as=None)

Implementation of @imports. This decorator imports the given _import from the given _from module optionally under a different _as name. The options correspond to the various forms for the import builtin.

@imports(‘sys’) @imports(_from=’mozpack’, _import=’path’, _as=’mozpath’)
include_file(path)

Include one file in the sandbox. Users of this class probably want

Note: this will execute all template invocations, as well as @depends functions that depend on ‘–help’, but nothing else.

include_impl(what)

Implementation of include(). Allows to include external files for execution in the sandbox. It is possible to use a @depends function as argument, in which case the result of the function is the file name to include. This latter feature is only really meant for –enable-application/–enable-project.

option_impl(*args, **kwargs)

Implementation of option() This function creates and returns an Option() object, passing it the resolved arguments (uses the result of functions when functions are passed). In most cases, the result of this function is not expected to be used. Command line argument/environment variable parsing for this Option is handled here.

run(path=None)

Executes the given file within the sandbox, as well as everything pending from any other included file, and ensure the overall consistency of the executed script(s).

set_config_impl(name, value)

Implementation of set_config(). Set the configuration items with the given name to the given value. Both name and value can be references to @depends functions, in which case the result from these functions is used. If the result of either function is None, the configuration item is not set.

set_define_impl(name, value)

Implementation of set_define(). Set the define with the given name to the given value. Both name and value can be references to @depends functions, in which case the result from these functions is used. If the result of either function is None, the define is not set. If the result is False, the define is explicitly undefined (-U).

template_impl(func)

Implementation of @template. This function is a decorator. Template functions are called immediately. They are altered so that their global namespace exposes a limited set of functions from os.path, as well as depends and option. Templates allow to simplify repetitive constructs, or to implement helper decorators and somesuch.

class mozbuild.configure.DependsFunction

Bases: object

Sandbox-visible representation of @depends functions.

class mozbuild.configure.SandboxedGlobal

Bases: dict

Identifiable dict type for use as function global

mozbuild.configure.forbidden_import(*args, **kwargs)