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.

API

Functions

The following special functions are available to a mozconfig script.

ac_add_options

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

e.g.:

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

mk_add_options

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

e.g.:

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.

MOZ_OBJDIR

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": "CYysKjIQSpS35T90luwCkA"}]', 'MOZPYTHONHOME': '/builds/worker/fetches/python', 'GECKO_HEAD_REV': '291d187ba249c56d5c9dc88b5faaf04db2afe9c1', '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_PORT_80_TCP_PORT': '80', 'HOME': '/builds/worker', 'TASKCLUSTER_WORKER_GROUP': 'us-central1-c', 'LANG': 'en_US.UTF-8', 'TASKCLUSTER_NAME': '/sad_dijkstra/taskcluster', 'MOZ_PYTHON_HOME': '/builds/worker/fetches/python', 'TASKCLUSTER_INSTANCE_TYPE': 'projects/887720501152/machineTypes/n2-standard-4', 'GECKO_BASE_REPOSITORY': 'https://hg.mozilla.org/mozilla-unified', 'TASKCLUSTER_PORT': 'tcp://172.17.0.2:80', 'TASKCLUSTER_WORKER_LOCATION': '{"cloud":"google","region":"us-central1","zone":"us-central1-c"}', 'TERM': 'xterm', 'TASKCLUSTER_PUBLIC_IP': '34.121.142.53', '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:/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': 'aan5Vqk-Rkqa2UTYBIOvhQ', 'TASKCLUSTER_WORKER_TYPE': 't-linux-xlarge-source-gcp', 'TASKCLUSTER_PORT_80_TCP_ADDR': '172.17.0.2', 'DEBIAN_FRONTEND': 'noninteractive', 'TASKCLUSTER_PORT_80_TCP': 'tcp://172.17.0.2:80', '_': './mach', 'MACH_MAIN_PID': '19', '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_mozconfig(path=None)

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.