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

RE_FORMAT = re.compile('{([^|}]*)\\|([^|}]*)}')

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

mozbuild.configure.lint_util module


mozbuild.configure.options module

class mozbuild.configure.options.CommandLineHelper(environ=environ({'GECKO_BASE_REPOSITORY': '', 'MOZ_AUTOMATION': '1', 'USER': 'worker', 'HOSTNAME': 'taskcluster-worker', 'TASKCLUSTER_PORT': 'tcp://', 'SHLVL': '1', 'TASKCLUSTER_PROXY_URL': 'http://taskcluster', 'HOME': '/builds/worker', 'TASKCLUSTER_NAME': '/determined_kirch/taskcluster', 'MOZ_SCM_LEVEL': '3', 'TASKCLUSTER_PORT_80_TCP_ADDR': '', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'GECKO_HEAD_REV': 'cf48e59e88dec9bd29a53e2ed1a836537a439426', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'TASK_ID': 'cF8vdh6hSkyKXW-jE9lLuA', 'LOGNAME': 'worker', '_': './mach', 'TERM': 'xterm', 'PATH': '/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/docs/html/_venv/bin:/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/_virtualenvs/moztreedocs-A8BSWbM4/bin:/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/_virtualenvs/init_py3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'GECKO_PATH': '/builds/worker/checkouts/gecko', 'TASKCLUSTER_WORKER_GROUP': 'aws', 'TASKCLUSTER_PORT_80_TCP': 'tcp://', 'TASKCLUSTER_PUBLIC_IP': '', 'LANG': 'en_US.UTF-8', 'TASKCLUSTER_WORKER_TYPE': 't-linux-xlarge', 'SHELL': '/bin/bash', 'TASKCLUSTER_ROOT_URL': '', 'TASKCLUSTER_INSTANCE_TYPE': 'm3.xlarge', 'TASKCLUSTER_WORKER_LOCATION': '{"availabilityZone":"us-east-1e","cloud":"aws","region":"us-east-1"}', 'GECKO_HEAD_REPOSITORY': '', 'LC_ALL': 'en_US.UTF-8', 'PWD': '/builds/worker/checkouts/gecko', 'SCCACHE_DISABLE': '1', 'RUN_ID': '0', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'MACH_MAIN_PID': '16', 'VIRTUAL_ENV': '/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/docs/html/_venv', 'DOCUTILSCONFIG': '/builds/worker/checkouts/gecko/docs/docutils.conf'}), argv=['./mach', 'doc', '--upload', '--no-open', '--no-serve'])

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='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: Exception

class mozbuild.configure.options.NegativeOptionValue(origin='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, category=None, help=None, define_depth=0)

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

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

get_value(option=None, origin='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)

property maxargs
property minargs
property option
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='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)

static from_(value)
class mozbuild.configure.options.PositiveOptionValue(values=(), origin='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=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>, 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

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

class mozbuild.configure.util.LineIO(callback, errors='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(<bound method memoize.method_call of {}>, None)
exception mozbuild.configure.ConfigureError

Bases: Exception

class mozbuild.configure.ConfigureSandbox(config, environ=environ({'GECKO_BASE_REPOSITORY': '', 'MOZ_AUTOMATION': '1', 'USER': 'worker', 'HOSTNAME': 'taskcluster-worker', 'TASKCLUSTER_PORT': 'tcp://', 'SHLVL': '1', 'TASKCLUSTER_PROXY_URL': 'http://taskcluster', 'HOME': '/builds/worker', 'TASKCLUSTER_NAME': '/determined_kirch/taskcluster', 'MOZ_SCM_LEVEL': '3', 'TASKCLUSTER_PORT_80_TCP_ADDR': '', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'GECKO_HEAD_REV': 'cf48e59e88dec9bd29a53e2ed1a836537a439426', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'TASK_ID': 'cF8vdh6hSkyKXW-jE9lLuA', 'LOGNAME': 'worker', '_': './mach', 'TERM': 'xterm', 'PATH': '/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/docs/html/_venv/bin:/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/_virtualenvs/moztreedocs-A8BSWbM4/bin:/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/_virtualenvs/init_py3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'GECKO_PATH': '/builds/worker/checkouts/gecko', 'TASKCLUSTER_WORKER_GROUP': 'aws', 'TASKCLUSTER_PORT_80_TCP': 'tcp://', 'TASKCLUSTER_PUBLIC_IP': '', 'LANG': 'en_US.UTF-8', 'TASKCLUSTER_WORKER_TYPE': 't-linux-xlarge', 'SHELL': '/bin/bash', 'TASKCLUSTER_ROOT_URL': '', 'TASKCLUSTER_INSTANCE_TYPE': 'm3.xlarge', 'TASKCLUSTER_WORKER_LOCATION': '{"availabilityZone":"us-east-1e","cloud":"aws","region":"us-east-1"}', 'GECKO_HEAD_REPOSITORY': '', 'LC_ALL': 'en_US.UTF-8', 'PWD': '/builds/worker/checkouts/gecko', 'SCCACHE_DISABLE': '1', 'RUN_ID': '0', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'MACH_MAIN_PID': '16', 'VIRTUAL_ENV': '/builds/worker/checkouts/gecko/obj-x86_64-pc-linux-gnu/docs/html/_venv', 'DOCUTILSCONFIG': '/builds/worker/checkouts/gecko/docs/docutils.conf'}), argv=['./mach', 'doc', '--upload', '--no-open', '--no-serve'], stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>, 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 = {'AssertionError': <class 'AssertionError'>, 'False': False, 'None': None, 'True': True, '__build_class__': <built-in function __build_class__>, '__import__': <function forbidden_import>, 'all': <built-in function all>, 'any': <built-in function any>, 'bool': <class 'bool'>, 'dict': <class 'dict'>, 'enumerate': <class 'enumerate'>, 'getattr': <built-in function getattr>, 'hasattr': <built-in function hasattr>, 'int': <class 'int'>, 'isinstance': <built-in function isinstance>, 'len': <built-in function len>, 'list': <class 'list'>, 'range': <class 'range'>, 'set': <class 'set'>, 'str': <class 'str'>, 'tuple': <class 'tuple'>, 'zip': <class 'zip'>}
OS = <ReadOnlyNamespace {'path': <ReadOnlyNamespace {'abspath': <function abspath>, 'basename': <function basename>, 'dirname': <function dirname>, 'isabs': <function isabs>, 'join': <function join>, 'normcase': <function normcase>, 'normpath': <function normpath>, 'realpath': <function realpath>, 'relpath': <function relpath>}>}>
RE_MODULE = re.compile('^[a-zA-Z0-9_\\.]+$')
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


    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.


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)
property name
static or_impl(iterable)
result = functools.partial(<bound method memoize.method_call of {}>, None)
property sandboxed_dependencies
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)