author Chris Pearce <>
Wed, 16 Mar 2016 13:49:26 +0800
changeset 288911 49aa9281700cdacc521a7fa851abfc019831f1eb
parent 288617 08c0e38543e746eff8ab537b5aa2eb3dd597a16f
child 289358 a5bd947546623f30a25113b0bb996d781ff938f2
permissions -rw-r--r--
Bug 1256065. r=gerald

# -*- 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

def warn(*args):
    import sys
    print(*args, file=sys.stderr)

def error(*args):
    import sys
    print(*args, file=sys.stderr)

def is_absolute_or_relative(path):
    import os
    if os.altsep and os.altsep in path:
        return True
    return os.sep in path

def normsep(path):
    import mozpack.path as mozpath
    return mozpath.normsep(path)

def find_program(file):
    if is_absolute_or_relative(file):
        return os.path.abspath(file) if os.path.isfile(file) else None
    from which import which, WhichError
        return normsep(which(file))
    except WhichError:
        return None

def _defines(help):
    ret = {}
    set_config('DEFINES', ret)
    return ret

def set_define(name, value):
    def _add_define(defines):
        from mozbuild.configure import ConfigureError
        if name in defines:
            raise ConfigureError("'%s' is already defined" % name)
        defines[name] = value

del _defines

def unique_list(l):
    result = []
    for i in l:
        if l not in result:
    return result

# Denotes a deprecated option. Combines option() and @depends:
# @deprecated_option('--option')
# def option(value):
#     ...
# @deprecated_option() takes the same arguments as option(), except `help`.
# The function may handle the option like a typical @depends function would,
# but it is recommended it emits a deprecation error message suggesting an
# alternative option to use if there is one.
def deprecated_option(*args, **kwargs):
    assert 'help' not in kwargs
    kwargs['help'] = 'Deprecated'
    opt = option(*args, **kwargs)

    def decorator(func):
        def deprecated(value):
            if value.origin != 'default':
                return func(value)
        return deprecated

    return decorator

# from mozbuild.util import ReadOnlyNamespace as namespace
def namespace(**kwargs):
    from mozbuild.util import ReadOnlyNamespace
    return ReadOnlyNamespace(**kwargs)