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, env=environ({'TERM_PROGRAM': 'Apple_Terminal', 'TERM': 'xterm-256color', 'SHELL': '/bin/zsh', 'TMPDIR': '/var/folders/yt/2kyz65ds4qv_65pqwdb40x8h0000gn/T/', 'TERM_PROGRAM_VERSION': '440', 'TERM_SESSION_ID': '44D43395-B15B-4C30-B407-FB0B82511DC0', 'USER': 'davidp', 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.OpTkbPBPcK/Listeners', 'PATH': '/Users/davidp/moz/mozilla-unified/obj-x86_64-apple-darwin20.6.0/docs/html/_venv/common/bin:/Users/davidp/moz/mozilla-unified/obj-x86_64-apple-darwin20.6.0/_virtualenvs/docs/bin:/Users/davidp/moz/mozilla-unified/node_modules/.bin:/Users/davidp/.mozbuild/node/bin:/Users/davidp/.mozbuild/srcdirs/mozilla-unified-5358a99862ea/_virtualenvs/mach/bin:/Users/davidp/bin:/Users/davidp/.cargo/bin:/Users/davidp/bin:/Users/davidp/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin', 'LaunchInstanceID': '0489829A-0BCB-4917-9DE6-08D311C69421', '__CFBundleIdentifier': 'com.apple.Terminal', 'PWD': '/Users/davidp/moz/mozilla-unified', 'LANG': 'en_US.UTF-8', 'XPC_FLAGS': '0x0', 'XPC_SERVICE_NAME': '0', 'HOME': '/Users/davidp', 'SHLVL': '1', 'LOGNAME': 'davidp', 'SECURITYSESSIONID': '186a8', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', 'PLAT': 'macosx-11-x86_64', 'VIRTUAL_ENV': '/Users/davidp/moz/mozilla-unified/obj-x86_64-apple-darwin20.6.0/docs/html/_venv/common', 'MACH_MAIN_PID': '4015', 'MACH_STDOUT_ISATTY': '1', 'DOCUTILSCONFIG': '/Users/davidp/moz/mozilla-unified/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.