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

class mozbuild.configure.constants.Abi(value)

Bases: EnumString

POSSIBLE_VALUES = ('msvc', 'mingw')
class mozbuild.configure.constants.CPU(value)

Bases: EnumString

POSSIBLE_VALUES = dict_keys(['aarch64', 'Alpha', 'arm', 'hppa', 'ia64', 'loongarch64', 'm68k', 'mips32', 'mips64', 'ppc', 'ppc64', 'riscv64', 's390', 's390x', 'sh4', 'sparc', 'sparc64', 'x86', 'x86_64', 'wasm32'])
class mozbuild.configure.constants.CompilerType(value)

Bases: EnumString

POSSIBLE_VALUES = ('clang', 'clang-cl', 'gcc', 'msvc')
class mozbuild.configure.constants.Endianness(value)

Bases: EnumString

POSSIBLE_VALUES = ('big', 'little')
class mozbuild.configure.constants.Kernel(value)

Bases: EnumString

POSSIBLE_VALUES = ('Darwin', 'DragonFly', 'FreeBSD', 'kFreeBSD', 'Linux', 'NetBSD', 'OpenBSD', 'SunOS', 'WINNT', 'WASI')
class mozbuild.configure.constants.OS(value)

Bases: EnumString

POSSIBLE_VALUES = ('Android', 'DragonFly', 'FreeBSD', 'GNU', 'iOS', 'NetBSD', 'OpenBSD', 'OSX', 'SunOS', 'WINNT', 'WASI')
class mozbuild.configure.constants.RaiseErrorOnUse(msg)

Bases: str

class mozbuild.configure.constants.WindowsBinaryType(value)

Bases: EnumString

POSSIBLE_VALUES = ('win32', 'win64')

mozbuild.configure.help module

class mozbuild.configure.help.HelpFormatter(argv0)

Bases: object

RE_FORMAT = re.compile('{([^|}]*)\\|([^|}]*)}')
add(option)
format_help(option)
format_options_by_category(options_by_category)
usage(out)

mozbuild.configure.lint module

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

Bases: ConfigureSandbox

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

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

unwrap(func)
wraps(func)
mozbuild.configure.lint.code_replace(code, co_filename, co_name, co_firstlineno)

mozbuild.configure.options module

class mozbuild.configure.options.CommandLineHelper(environ=environ({'SHELL': '/bin/bash', 'MOZ_FETCHES': '[{"artifact": "public/build/node-modules.tar.zst", "extract": true, "task": "OajyGWQIRCKUlcPB9iu2Gw"}, {"artifact": "public/build/node.tar.zst", "extract": true, "task": "KuZT2N-QTvaXh03iaRDQXg"}, {"artifact": "public/build/python.tar.zst", "extract": true, "task": "AKtCY5T_SfufFqf9_8_fIQ"}]', 'MOZPYTHONHOME': '/builds/worker/fetches/python', 'GECKO_HEAD_REV': 'a6629e81c818e845cad7b578f147cc60fd531bb8', 'HOSTNAME': 'taskcluster-worker', 'MOZ_AUTOMATION': '1', 'TASKCLUSTER_ROOT_URL': 'https://firefox-ci-tc.services.mozilla.com', 'PWD': '/builds/worker/checkouts/gecko', 'LOGNAME': 'worker', 'GECKO_PATH': '/builds/worker/checkouts/gecko', 'TASKCLUSTER_WORKER_POOL': 'gecko-3/b-linux-medium-gcp', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'HOME': '/builds/worker', 'TASKCLUSTER_WORKER_GROUP': 'us-west1-b', 'LANG': 'en_US.UTF-8', 'TASKCLUSTER_NAME': '/cranky_satoshi/taskcluster', 'MOZ_PYTHON_HOME': '/builds/worker/fetches/python', 'TASKCLUSTER_INSTANCE_TYPE': 'projects/970387039909/machineTypes/c2-standard-8', 'GECKO_BASE_REPOSITORY': 'https://hg.mozilla.org/mozilla-unified', 'TASKCLUSTER_PORT': 'tcp://172.17.0.3:80', 'TASKCLUSTER_WORKER_LOCATION': '{"cloud":"google","region":"us-west1","zone":"us-west1-b"}', 'TERM': 'xterm', 'TASKCLUSTER_PUBLIC_IP': '34.127.125.138', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'USER': 'worker', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'MOZ_SCM_LEVEL': '3', 'SHLVL': '0', 'TASKCLUSTER_PROXY_URL': 'http://taskcluster', 'GECKO_HEAD_REPOSITORY': 'https://hg.mozilla.org/mozilla-central', 'SCCACHE_DISABLE': '1', 'LC_ALL': 'C', 'MOZ_SOURCE_DOCS_USE_GOOGLE': '1', 'MOZ_FETCHES_DIR': '/builds/worker/fetches', 'PATH': '/builds/worker/checkouts/gecko/node_modules/.bin:/builds/worker/fetches/node/bin:/builds/worker/.mozbuild/srcdirs/gecko-8a5b87fe5d69/_virtualenvs/docs/bin:/builds/worker/fetches/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'RUN_ID': '0', 'TASK_ID': 'Vp7keMHATr2Da4yiXLR3Tw', 'TASKCLUSTER_WORKER_TYPE': 'b-linux-medium-gcp', 'TASKCLUSTER_PORT_80_TCP_ADDR': '172.17.0.3', 'DEBIAN_FRONTEND': 'noninteractive', 'TASKCLUSTER_PORT_80_TCP': 'tcp://172.17.0.3:80', '_': './mach', 'MACH_MAIN_PID': '16', 'VIRTUAL_ENV': '/builds/worker/.mozbuild/srcdirs/gecko-8a5b87fe5d69/_virtualenvs/docs', 'DOCUTILSCONFIG': '/builds/worker/checkouts/gecko/docs/docutils.conf'}), argv=['./mach', 'doc', '--upload', '--no-open', '--no-serve', '--write-url', '/builds/worker/firefox-source-docs-url.txt', '--dump-trees=/builds/worker/artifacts/trees.json'])

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)
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: InvalidOptionError

exception mozbuild.configure.options.InvalidOptionError

Bases: Exception

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

Bases: 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, metavar=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 a NegativeOptionValue (disabled). When it starts with ‘–disable-’ or ‘–without-’, the implied default is an empty PositiveOptionValue (enabled).

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

category
choices
default
define_depth
env
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)

help
id
property maxargs
metavar
property minargs
name
nargs
property option
possible_origins
prefix
static split_option(option, values_separator=',')

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 values_separator. If values_separator is None, there is at most one value.

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)

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

Bases: 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=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, maxlen=20)

Bases: 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)

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.

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

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

Bases: LooseVersion

A simple subclass of looseversion.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

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

Bases: DependsFunction

dependencies
result()
sandbox
sandboxed
when
exception mozbuild.configure.ConfigureError

Bases: Exception

class mozbuild.configure.ConfigureSandbox(config, environ=environ({'SHELL': '/bin/bash', 'MOZ_FETCHES': '[{"artifact": "public/build/node-modules.tar.zst", "extract": true, "task": "OajyGWQIRCKUlcPB9iu2Gw"}, {"artifact": "public/build/node.tar.zst", "extract": true, "task": "KuZT2N-QTvaXh03iaRDQXg"}, {"artifact": "public/build/python.tar.zst", "extract": true, "task": "AKtCY5T_SfufFqf9_8_fIQ"}]', 'MOZPYTHONHOME': '/builds/worker/fetches/python', 'GECKO_HEAD_REV': 'a6629e81c818e845cad7b578f147cc60fd531bb8', 'HOSTNAME': 'taskcluster-worker', 'MOZ_AUTOMATION': '1', 'TASKCLUSTER_ROOT_URL': 'https://firefox-ci-tc.services.mozilla.com', 'PWD': '/builds/worker/checkouts/gecko', 'LOGNAME': 'worker', 'GECKO_PATH': '/builds/worker/checkouts/gecko', 'TASKCLUSTER_WORKER_POOL': 'gecko-3/b-linux-medium-gcp', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'HOME': '/builds/worker', 'TASKCLUSTER_WORKER_GROUP': 'us-west1-b', 'LANG': 'en_US.UTF-8', 'TASKCLUSTER_NAME': '/cranky_satoshi/taskcluster', 'MOZ_PYTHON_HOME': '/builds/worker/fetches/python', 'TASKCLUSTER_INSTANCE_TYPE': 'projects/970387039909/machineTypes/c2-standard-8', 'GECKO_BASE_REPOSITORY': 'https://hg.mozilla.org/mozilla-unified', 'TASKCLUSTER_PORT': 'tcp://172.17.0.3:80', 'TASKCLUSTER_WORKER_LOCATION': '{"cloud":"google","region":"us-west1","zone":"us-west1-b"}', 'TERM': 'xterm', 'TASKCLUSTER_PUBLIC_IP': '34.127.125.138', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'USER': 'worker', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'MOZ_SCM_LEVEL': '3', 'SHLVL': '0', 'TASKCLUSTER_PROXY_URL': 'http://taskcluster', 'GECKO_HEAD_REPOSITORY': 'https://hg.mozilla.org/mozilla-central', 'SCCACHE_DISABLE': '1', 'LC_ALL': 'C', 'MOZ_SOURCE_DOCS_USE_GOOGLE': '1', 'MOZ_FETCHES_DIR': '/builds/worker/fetches', 'PATH': '/builds/worker/checkouts/gecko/node_modules/.bin:/builds/worker/fetches/node/bin:/builds/worker/.mozbuild/srcdirs/gecko-8a5b87fe5d69/_virtualenvs/docs/bin:/builds/worker/fetches/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'RUN_ID': '0', 'TASK_ID': 'Vp7keMHATr2Da4yiXLR3Tw', 'TASKCLUSTER_WORKER_TYPE': 'b-linux-medium-gcp', 'TASKCLUSTER_PORT_80_TCP_ADDR': '172.17.0.3', 'DEBIAN_FRONTEND': 'noninteractive', 'TASKCLUSTER_PORT_80_TCP': 'tcp://172.17.0.3:80', '_': './mach', 'MACH_MAIN_PID': '16', 'VIRTUAL_ENV': '/builds/worker/.mozbuild/srcdirs/gecko-8a5b87fe5d69/_virtualenvs/docs', 'DOCUTILSCONFIG': '/builds/worker/checkouts/gecko/docs/docutils.conf'}), argv=['./mach', 'doc', '--upload', '--no-open', '--no-serve', '--write-url', '/builds/worker/firefox-source-docs-url.txt', '--dump-trees=/builds/worker/artifacts/trees.json'], 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 moz.build 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) sandbox.run(path) 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'>, 'max': <built-in function max>, 'min': <built-in function min>, 'range': <class 'range'>, 'reversed': <class 'reversed'>, 'set': <class 'set'>, 'sorted': <built-in function sorted>, '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.

static get_compiled_source(source, 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

(–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 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(when)

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.

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

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.

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

Bases: object

static and_impl(iterable)
dependencies
property name
static or_impl(iterable)
result()
sandbox
sandboxed
property sandboxed_dependencies
when
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: DependsFunction

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

dependencies
sandbox
sandboxed
when
mozbuild.configure.forbidden_import(*args, **kwargs)