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/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': 'a5c9e4f1c8859c3a069e7b88e3f71bd04c13d7c9', '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-1/b-linux-medium-gcp', 'TASKCLUSTER_PORT_80_TCP_PORT': '80', 'HOME': '/builds/worker', 'TASKCLUSTER_WORKER_GROUP': 'us-central1-b', 'LANG': 'en_US.UTF-8', 'TASKCLUSTER_NAME': '/musing_engelbart/taskcluster', 'TRY_SELECTOR': 'fuzzy', 'MOZ_PYTHON_HOME': '/builds/worker/fetches/python', 'TASKCLUSTER_INSTANCE_TYPE': 'projects/887720501152/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-central1","zone":"us-central1-b"}', 'TERM': 'xterm', 'TASKCLUSTER_PUBLIC_IP': '34.135.65.144', 'HG_STORE_PATH': '/builds/worker/checkouts/hg-store', 'USER': 'worker', 'TASKCLUSTER_PORT_80_TCP_PROTO': 'tcp', 'MOZ_SCM_LEVEL': '1', 'SHLVL': '0', 'TASKCLUSTER_PROXY_URL': 'http://taskcluster', 'GECKO_HEAD_REPOSITORY': 'https://hg.mozilla.org/try', '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': 'aErnlXoqQ6a2AD6k2SLt7w', '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': '27', '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.
If ENV[MOZCONFIG] is set, use that
If $TOPSRCDIR/mozconfig or $TOPSRCDIR/.mozconfig exists, use it.
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.