2016-03-04 11:31:10 +03:00
|
|
|
# -*- 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/.
|
|
|
|
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports('sys')
|
2016-03-25 10:30:42 +03:00
|
|
|
def die(*args):
|
2016-03-17 18:04:12 +03:00
|
|
|
'Print an error and terminate configure.'
|
2016-03-25 10:30:42 +03:00
|
|
|
log.error(*args)
|
2016-03-04 11:31:10 +03:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports(_from='mozbuild.configure', _import='ConfigureError')
|
2016-03-17 18:04:12 +03:00
|
|
|
def configure_error(message):
|
|
|
|
'''Raise a programming error and terminate configure.
|
|
|
|
Primarily for use in moz.configure templates to sanity check
|
|
|
|
their inputs from moz.configure usage.'''
|
|
|
|
raise ConfigureError(message)
|
|
|
|
|
|
|
|
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports('os')
|
2016-03-04 11:31:10 +03:00
|
|
|
def is_absolute_or_relative(path):
|
|
|
|
if os.altsep and os.altsep in path:
|
|
|
|
return True
|
|
|
|
return os.sep in path
|
|
|
|
|
|
|
|
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports(_import='mozpack.path', _as='mozpath')
|
2016-03-04 11:31:10 +03:00
|
|
|
def normsep(path):
|
|
|
|
return mozpath.normsep(path)
|
|
|
|
|
|
|
|
|
2016-04-15 05:11:58 +03:00
|
|
|
@imports(_from='which', _import='which')
|
|
|
|
@imports(_from='which', _import='WhichError')
|
2016-03-04 11:31:10 +03:00
|
|
|
def find_program(file):
|
|
|
|
if is_absolute_or_relative(file):
|
|
|
|
return os.path.abspath(file) if os.path.isfile(file) else None
|
|
|
|
try:
|
|
|
|
return normsep(which(file))
|
|
|
|
except WhichError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2016-03-04 12:02:39 +03:00
|
|
|
def unique_list(l):
|
|
|
|
result = []
|
|
|
|
for i in l:
|
|
|
|
if l not in result:
|
|
|
|
result.append(i)
|
|
|
|
return result
|
2016-03-09 11:41:40 +03:00
|
|
|
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports(_from='mozbuild.configure.util', _import='Version', _as='_Version')
|
2016-03-17 18:52:18 +03:00
|
|
|
def Version(v):
|
|
|
|
'A version number that can be compared usefully.'
|
|
|
|
return _Version(v)
|
2016-03-09 11:41:40 +03:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
@template
|
|
|
|
def deprecated_option(*args, **kwargs):
|
|
|
|
assert 'help' not in kwargs
|
|
|
|
kwargs['help'] = 'Deprecated'
|
|
|
|
opt = option(*args, **kwargs)
|
|
|
|
|
|
|
|
def decorator(func):
|
|
|
|
@depends(opt.option)
|
|
|
|
def deprecated(value):
|
|
|
|
if value.origin != 'default':
|
|
|
|
return func(value)
|
|
|
|
return deprecated
|
|
|
|
|
|
|
|
return decorator
|
Bug 1255305 - Move --host and --target to moz.configure. r=chmanchester
With all the things that still depend on all the variables derived from
--host and --target in both old-configure and moz.build, we still need
to keep variables such as OS_ARCH, OS_TARGET, CPU_ARCH, OS_TEST, etc.
Eventually, we'd settle on the output of split_triplet.
This /tries/ to preserve the current values for all these variables,
while also trying to make things a little more consistent. It also
effectively rejects OSes such as HPUX or AIX, because it is unclear
the decades old accumulated scripts related to them still do anything
useful, and we might as well have them start again from scratch, which,
in the coming weeks, will be even easier.
2016-03-11 16:57:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
# from mozbuild.util import ReadOnlyNamespace as namespace
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports(_from='mozbuild.util', _import='ReadOnlyNamespace')
|
Bug 1255305 - Move --host and --target to moz.configure. r=chmanchester
With all the things that still depend on all the variables derived from
--host and --target in both old-configure and moz.build, we still need
to keep variables such as OS_ARCH, OS_TARGET, CPU_ARCH, OS_TEST, etc.
Eventually, we'd settle on the output of split_triplet.
This /tries/ to preserve the current values for all these variables,
while also trying to make things a little more consistent. It also
effectively rejects OSes such as HPUX or AIX, because it is unclear
the decades old accumulated scripts related to them still do anything
useful, and we might as well have them start again from scratch, which,
in the coming weeks, will be even easier.
2016-03-11 16:57:15 +03:00
|
|
|
def namespace(**kwargs):
|
|
|
|
return ReadOnlyNamespace(**kwargs)
|
2016-03-22 08:21:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Some @depends function return namespaces, and one could want to use one
|
|
|
|
# specific attribute from such a namespace as a "value" given to functions
|
|
|
|
# such as `set_config`. But those functions do not take immediate values.
|
|
|
|
# The `delayed_getattr` function allows access to attributes from the result
|
|
|
|
# of a @depends function in a non-immediate manner.
|
|
|
|
# @depends('--option')
|
|
|
|
# def option(value)
|
|
|
|
# return namespace(foo=value)
|
|
|
|
# set_config('FOO', delayed_getattr(option, 'foo')
|
|
|
|
@template
|
|
|
|
def delayed_getattr(func, key):
|
|
|
|
@depends(func)
|
|
|
|
def result(value):
|
2016-03-28 01:29:08 +03:00
|
|
|
# The @depends function we're being passed may have returned
|
|
|
|
# None, or an object that simply doesn't have the wanted key.
|
|
|
|
# In that case, just return None.
|
|
|
|
return getattr(value, key, None)
|
2016-03-22 08:21:32 +03:00
|
|
|
return result
|
2016-03-24 09:26:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Like @depends, but the decorated function is only called if one of the
|
|
|
|
# arguments it would be called with has a positive value (bool(value) is True)
|
|
|
|
@template
|
|
|
|
def depends_if(*args):
|
|
|
|
def decorator(func):
|
|
|
|
@depends(*args)
|
|
|
|
def wrapper(*args):
|
|
|
|
if any(arg for arg in args):
|
|
|
|
return func(*args)
|
|
|
|
return wrapper
|
|
|
|
return decorator
|