Source code

Revision control

Copy as Markdown

Other Tools

# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at
option("--enable-simple", help="Enable simple")
# Setting MOZ_WITH_ENV in the environment has the same effect as passing
# --enable-with-env.
option("--enable-with-env", env="MOZ_WITH_ENV", help="Enable with env")
# Optional values
option("--enable-values", nargs="*", help="Enable values")
# Optional values from a set of choices
option("--enable-choices", nargs="*", choices=("a", "b", "c"), help="Enable choices")
# Everything supported in the Option class is supported in option(). Assume
# the tests of the Option class are extensive about this.
# Alternatively to --enable/--disable, there also is --with/--without. The
# difference is semantic only. Behavior is the same as --enable/--disable.
# When the option name starts with --disable/--without, the default is for
# the option to be enabled.
option("--without-thing", help="Build without thing")
# A --enable/--with option with a default of False is equivalent to a
# --disable/--without option. This can be used to change the defaults
# depending on e.g. the target or the built application.
option("--with-stuff", default=False, help="Build with stuff")
# Other kinds of arbitrary options are also allowed. This is effectively
# equivalent to --enable/--with, with no possibility of --disable/--without.
option("--option", env="MOZ_OPTION", help="Option")
# It is also possible to pass options through the environment only.
option(env="CC", nargs=1, help="C Compiler")
# Call the function when the --enable-simple option is processed, with its
# OptionValue as argument.
def simple(simple):
if simple:
return simple
set_config("ENABLED_SIMPLE", simple)
# There can be multiple functions depending on the same option.
def simple(simple):
return simple
set_config("SIMPLE", simple)
def with_env(with_env):
return with_env
set_config("WITH_ENV", with_env)
# It doesn't matter if the dependency is on --enable or --disable
def with_env2(values):
return values
set_config("VALUES", with_env2)
# It is possible to @depends on environment-only options.
def is_gcc(cc):
return cc and "gcc" in cc[0]
set_config("IS_GCC", is_gcc)
# It is possible to depend on the result from another function.
def with_env3(values):
return values
set_config("VALUES2", with_env3)
# @depends functions can also return results for use as input to another
# @depends.
def with_env4(values):
return values
def with_env5(values):
return values
set_config("VALUES3", with_env5)
# The result from @depends functions can also be used as input to options.
# The result must be returned, not implied.
def simple(simple):
return "simple" if simple else "not-simple"
option("--with-returned-default", default=simple, help="Returned default")
def default(value):
return value
set_config("DEFAULTED", default)
def other_default(simple):
return bool(simple)
# When the default comes from the result of a @depends function, the help
# string can be picked between two variants automatically.
"--with-other-default", default=other_default, help="{With|Without} other default"
def choices(values):
if len(values):
return {
"alpha": ("a", "b", "c"),
"numeric": ("0", "1", "2"),
option("--returned-choices", choices=choices, help="Choices")
def returned_choices(values):
return values
set_config("CHOICES", returned_choices)
# Unusual case: an option can default to enabled, but still allow for optional
# values. In that case, both --disable and --enable options will be shown in
# configure --help, and the help message needs to include both variants.
option("--disable-foo", nargs="*", choices=("x", "y"), help="{Enable|Disable} Foo")
# All options must be referenced by some @depends function.
# It is possible to depend on multiple options/functions
def remainder(*args):
return args
set_config("REMAINDER", remainder)
# It is possible to include other files to extend the configuration script.
# It is also possible for the include file path to come from the result of a
# @depends function.
option("--enable-include", nargs=1, help="Include")
def include_path(path):
return path[0] if path else None
# Sandboxed functions can import from modules through the use of the @imports
# decorator.
# The order of the decorators matter: @imports needs to appear after other
# decorators.
option("--with-imports", nargs="?", help="Imports")
# A limited set of functions from os.path are exposed by default.
def with_imports(value):
if len(value):
return hasattr(os.path, "abspath")
set_config("HAS_ABSPATH", with_imports)
# It is still possible to import the full set from os.path.
# It is also possible to cherry-pick builtins.
def with_imports(value):
if len(value):
return hasattr(os.path, "getatime")
set_config("HAS_GETATIME", with_imports)
def with_imports(value):
if len(value):
return hasattr(os.path, "getatime")
set_config("HAS_GETATIME2", with_imports)
# This option should be attributed to this file in the --help output even though
# included.configure is the actual file that defines the option.
indirectly_define_option("--indirect-option", help="Indirectly defined option")
def indirect_option(option):
return option