mozconfig Files

mozconfig files are used to configure how a build works.

mozconfig files are actually shell scripts. They are executed in a special context with specific variables and functions exposed to them.



The following special functions are available to a mozconfig script.


This function is used to declare extra options/arguments to pass into configure.


ac_add_options --disable-tests
ac_add_options --enable-optimize


This function is used to inject statements into for execution. It is typically used to define variables, notably the object directory.


mk_add_options AUTOCLOBBER=1

Special mk_add_options Variables

For historical reasons, the method for communicating certain well-defined variables is via mk_add_options(). In this section, we document what those special variables are.


This variable is used to define the object directory for the current build.

Finding the active mozconfig

Multiple mozconfig files can exist to provide different configuration options for different tasks. The rules for finding the active mozconfig are defined in the mozboot.mozconfig.find_mozconfig() method.

mozboot.mozconfig.find_mozconfig(topsrcdir: str | Path, env=environ({'SHELL': '/bin/bash', 'MOZ_FETCHES': '[{"artifact": "public/build/python.tar.zst", "extract": true, "task": "Gz3Ipp1DRZyRuD1JxtLcWw"}]', 'MOZPYTHONHOME': '/builds/worker/fetches/python', 'GECKO_HEAD_REV': '9d97f4d08fef38d8640c91dc134b3aa2d4372105', 'HOSTNAME': 'taskcluster-worker', 'MOZ_AUTOMATION': '1', 'TASKCLUSTER_ROOT_URL': '', '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': '/mystifying_nobel/taskcluster', 'MOZ_PYTHON_HOME': '/builds/worker/fetches/python', 'TASKCLUSTER_INSTANCE_TYPE': 'projects/970387039909/machineTypes/c2-standard-8', 'GECKO_BASE_REPOSITORY': '', 'TASKCLUSTER_PORT': 'tcp://', 'TASKCLUSTER_WORKER_LOCATION': '{"cloud":"google","region":"us-west1","zone":"us-west1-b"}', 'TERM': 'xterm', 'TASKCLUSTER_PUBLIC_IP': '', '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': '', '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:/usr/local/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': 'dX5VhgUMRbKCjT3T4MT_jw', 'TASKCLUSTER_WORKER_TYPE': 'b-linux-medium-gcp', 'TASKCLUSTER_PORT_80_TCP_ADDR': '', 'DEBIAN_FRONTEND': 'noninteractive', 'TASKCLUSTER_PORT_80_TCP': 'tcp://', '_': './mach', 'MACH_MAIN_PID': '21', 'VIRTUAL_ENV': '/builds/worker/.mozbuild/srcdirs/gecko-8a5b87fe5d69/_virtualenvs/docs', 'DOCUTILSCONFIG': '/builds/worker/checkouts/gecko/docs/docutils.conf'}))

Find the active mozconfig file for the current environment.

This emulates the logic in mozconfig-find.

  1. If ENV[MOZCONFIG] is set, use that

  2. If $TOPSRCDIR/mozconfig or $TOPSRCDIR/.mozconfig exists, use it.

  3. If both exist or if there are legacy locations detected, error out.

The absolute path to the found mozconfig will be returned on success. None will be returned if no mozconfig could be found. A MozconfigFindException will be raised if there is a bad state, including conditions from #3 above.

Loading the active mozconfig

class mozbuild.mozconfig.MozconfigLoader(topsrcdir)

Handles loading and parsing of mozconfig files.


Read the contents of a mozconfig into a data structure.

This takes the path to a mozconfig to load. If the given path is AUTODETECT, will try to find a mozconfig from the environment using find_mozconfig().

mozconfig files are shell scripts. So, we can’t just parse them. Instead, we run the shell script in a wrapper which allows us to record state from execution. Thus, the output from a mozconfig is a friendly static data structure.