python/mozbuild/mozbuild/test/configure/data/included.configure
author Mike Hommey <mh+mozilla@glandium.org>
Tue, 22 Mar 2016 14:21:32 +0900
changeset 313930 9d2b6f4c3ee8366365c16cee6cbda90c4688c743
parent 310958 85ead00f0a39583ccb7fcce767017d1ec6877094
child 314706 89b86fc355d7611a3a43872ee047bd32d651ddd1
permissions -rw-r--r--
Bug 1257823 - Move set_config() to the global scope. r=nalexander The way set_config is set currently makes it difficult to introspect moz.configure files to know what configuration items are being set, because they're hidden in the control flow of functions. This makes some of the moz.configure more convoluted, but this is why there are templates, and we can improve the recurring cases afterwards.

# -*- Mode: python; c-basic-offset: 4; 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 http://mozilla.org/MPL/2.0/.

# For more complex and repetitive things, we can create templates
@template
def check_compiler_flag(flag):
    @depends(is_gcc)
    def check(value):
        if value:
            return [flag]
    set_config('CFLAGS', check)
    return check


check_compiler_flag('-Werror=foobar')

# A template that doesn't return functions can be used in @depends functions.
@template
def fortytwo():
    return 42

@template
def twentyone():
    yield 21

@depends(is_gcc)
def check(value):
    if value:
        return fortytwo()

set_config('TEMPLATE_VALUE', check)

@depends(is_gcc)
def check(value):
    if value:
        for val in twentyone():
            return val

set_config('TEMPLATE_VALUE_2', check)

# Templates can use @advanced too to import modules and get the full set of
# builtins.
@template
@advanced
def platform():
    import sys
    return sys.platform

option('--enable-advanced-template', help='Advanced template')
@depends('--enable-advanced-template')
def check(value):
    if value:
        return platform()

set_config('PLATFORM', check)