mozbuild.configure package


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 module


Bases: object


mozbuild.configure.libstdcxx module

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

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


Encode the version as a single number.


Given a base command line for a compiler, find the version of the libstdc++ it uses.


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


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


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

mozbuild.configure.lint module

class mozbuild.configure.lint.LintSandbox(environ=None, argv=None, stdout=None, stderr=None)

Bases: mozbuild.configure.ConfigureSandbox

option_impl(*args, **kwargs)

mozbuild.configure.lint_util module


mozbuild.configure.options module

class mozbuild.configure.options.CommandLineHelper(environ={'TASKCLUSTER_PORT_80_TCP_ADDR': '', 'TASKCLUSTER_INSTANCE_TYPE': 'm3.xlarge', 'TASKCLUSTER_WORKER_TYPE': 'gecko-t-linux-xlarge', 'MOZ_AUTOMATION': '1', 'LOGNAME': 'worker', 'USER': 'worker', 'HOME': '/builds/worker', 'PATH': '/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/docs/html/main/_venv/bin:/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/_virtualenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'RUN_ID': '0', 'SHLVL': '1', 'TASKCLUSTER_PORT': 'tcp://', 'TASKCLUSTER_NAME': '/happy_bhaskara/taskcluster', 'GECKO_HEAD_REPOSITORY': '', 'SCCACHE_DISABLE': '1', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'GECKO_HEAD_REV': 'b0baaec09caf3e1b30ec6b238f5c46ef9b3188be', 'MOZ_SCM_LEVEL': '3', 'GECKO_BASE_REPOSITORY': '', 'LC_ALL': 'en_US.UTF-8', '_': './mach', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'TASK_ID': 'DC2-pqQjRE2ySBKbNrrBFg', 'TASKCLUSTER_PORT_80_TCP': 'tcp://', 'OLDPWD': '/', 'HOSTNAME': 'taskcluster-worker', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'PWD': '/builds/worker/checkouts/gecko', 'TASKCLUSTER_WORKER_GROUP': 'us-east-1', 'TASKCLUSTER_PUBLIC_IP': ''}, argv=['./mach', 'doc', '--upload', '--no-open'])

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)

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’.
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)

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)

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.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.

KEEP = 1
queue_debug(*args, **kwds)
class mozbuild.configure.util.LineIO(callback, errors=u'strict')

Bases: object

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

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


Module contents

class mozbuild.configure.CombinedDependsFunction(sandbox, func, dependencies)

Bases: mozbuild.configure.DependsFunction

result = <functools.partial object>
exception mozbuild.configure.ConfigureError

Bases: exceptions.Exception

class mozbuild.configure.ConfigureSandbox(config, environ={'TASKCLUSTER_PORT_80_TCP_ADDR': '', 'TASKCLUSTER_INSTANCE_TYPE': 'm3.xlarge', 'TASKCLUSTER_WORKER_TYPE': 'gecko-t-linux-xlarge', 'MOZ_AUTOMATION': '1', 'LOGNAME': 'worker', 'USER': 'worker', 'HOME': '/builds/worker', 'PATH': '/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/docs/html/main/_venv/bin:/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/_virtualenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'RUN_ID': '0', 'SHLVL': '1', 'TASKCLUSTER_PORT': 'tcp://', 'TASKCLUSTER_NAME': '/happy_bhaskara/taskcluster', 'GECKO_HEAD_REPOSITORY': '', 'SCCACHE_DISABLE': '1', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'GECKO_HEAD_REV': 'b0baaec09caf3e1b30ec6b238f5c46ef9b3188be', 'MOZ_SCM_LEVEL': '3', 'GECKO_BASE_REPOSITORY': '', 'LC_ALL': 'en_US.UTF-8', '_': './mach', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'TASK_ID': 'DC2-pqQjRE2ySBKbNrrBFg', 'TASKCLUSTER_PORT_80_TCP': 'tcp://', 'OLDPWD': '/', 'HOSTNAME': 'taskcluster-worker', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'PWD': '/builds/worker/checkouts/gecko', 'TASKCLUSTER_WORKER_GROUP': 'us-east-1', 'TASKCLUSTER_PUBLIC_IP': ''}, argv=['./mach', 'doc', '--upload', '--no-open'], 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 processing.

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

option, include, set_config, set_define and imply_option are functions. depends, template, and imports are decorators. only_when is a context_manager.

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) do_stuff(config)
BUILTINS = {u'False': False, u'None': None, u'True': True, '__import__': <function forbidden_import at 0x7f1b42002050>, u'all': <built-in function all>, u'any': <built-in function any>, u'bool': <type 'bool'>, u'dict': <type 'dict'>, u'enumerate': <type 'enumerate'>, u'getattr': <built-in function getattr>, u'hasattr': <built-in function hasattr>, u'int': <type 'int'>, u'isinstance': <built-in function isinstance>, u'len': <built-in function len>, u'list': <type 'list'>, u'range': <built-in function range>, u'set': <type 'set'>, 'str': <type 'unicode'>, u'tuple': <type 'tuple'>, u'zip': <built-in function zip>}
OS = <ReadOnlyNamespace {'path': <ReadOnlyNamespace {'realpath': <function realpath>, 'join': <function join>, 'abspath': <function abspath>, 'isabs': <function isabs>, 'normcase': <function normcase>, 'normpath': <function normpath>, 'dirname': <function dirname>, 'basename': <function basename>, 'relpath': <function relpath>}>}>
RE_MODULE = <_sre.SRE_Pattern object>
depends_impl(*args, **kwargs)

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, when=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

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 one file in the sandbox. Users of this class probably want to use run instead.

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

include_impl(what, when=None)

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.

only_when_impl(*args, **kwds)

Implementation of only_when()

only_when is a context manager that essentially makes calls to other sandbox functions within the context block ignored.

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.


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, when=None)

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, when=None)

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).


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(sandbox, func, dependencies, when=None)

Bases: object

static and_impl(iterable)
static or_impl(iterable)
result = <functools.partial object>
class mozbuild.configure.SandboxDependsFunction(unsandboxed)

Bases: object

Sandbox-visible representation of @depends functions.

class mozbuild.configure.SandboxedGlobal

Bases: dict

Identifiable dict type for use as function global

class mozbuild.configure.TrivialDependsFunction(sandbox, func, dependencies, when=None)

Bases: mozbuild.configure.DependsFunction

Like a DependsFunction, but the linter won’t expect it to have a dependency on –help ever.

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