author Dorel Luca <>
Sat, 12 Jan 2019 01:28:30 +0200
changeset 453578 c45da646fc61
parent 453573 24243f13c895
child 453582 6685e8b9d867
permissions -rw-r--r--
Backed out changeset 24243f13c895 (bug 1519308) for build bustage in mozbuild/mozbuild/test/configure/ CLOSED TREE

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

def pkg_config(compile_env):
    if compile_env:
        return ('pkg-config',)

pkg_config = check_prog('PKG_CONFIG', pkg_config, allow_missing=True)

@checking('for pkg-config version')
def pkg_config_version(pkg_config):
    return Version(check_cmd_output(pkg_config, '--version').rstrip())

# Locates the given module using pkg-config.
# - `var` determines the name of variables to set when the package is found.
#   <var>_CFLAGS and <var>_LIBS are set with corresponding values.
# - `package_desc` package name and version requirement string, list of
#   strings describing packages to locate, or depends function that will
#   resolve to such a string or list of strings.
# - `when` a depends function that will determine whether to perform
#   any checks (default is to always perform checks).
# - `allow_missing` If set, failure to fulfill the package description
#   will not result in an error or logged message, and any error message
#   will be returned to the caller.
#   Returns `True` when the package description is fulfilled.

def pkg_check_modules(var, package_desc, when=always,
    if isinstance(package_desc, (tuple, list)):
        package_desc = ' '.join(package_desc)
    package_desc = dependable(package_desc)
    allow_missing = dependable(allow_missing)

    @depends(when, '--enable-compile-environment')
    def when_and_compile_environment(when, compile_environment):
        return when and compile_environment

    @depends(pkg_config, pkg_config_version,
    def check_pkg_config(pkg_config, version):
        min_version = '0.9.0'
        if pkg_config is None:
            die("*** The pkg-config script could not be found. Make sure it is\n"
                "*** in your path, or set the PKG_CONFIG environment variable\n"
                "*** to the full path to pkg-config.")
        if version < min_version:
            die("*** Your version of pkg-config is too old. You need version %s or newer.",

    @depends(pkg_config, package_desc, allow_missing, when=when_and_compile_environment)
    @imports(_from='mozbuild.configure.util', _import='LineIO')
    def package(pkg_config, package_desc, allow_missing):
        # package_desc may start as a depends function, so we can't use
        # @checking here."checking for %s... " % package_desc)
        with log.queue_debug():
                subprocess.check_output([pkg_config, '--errors-to-stdout',
                                         '--print-errors', package_desc])
                return True
            except subprocess.CalledProcessError as e:
                log_writer = log.warning if allow_missing else log.error
                with LineIO(lambda l: log_writer(l), 'replace') as o:
                if not allow_missing:

    @depends(pkg_config, package_desc, when=package)
    @checking('%s_CFLAGS' % var, callback=lambda t: ' '.join(t))
    def pkg_cflags(pkg_config, package_desc):
        flags = check_cmd_output(pkg_config, '--cflags', package_desc)
        return tuple(flags.split())

    @depends(pkg_config, package_desc, when=package)
    @checking('%s_LIBS' % var, callback=lambda t: ' '.join(t))
    def pkg_libs(pkg_config, package_desc):
        libs = check_cmd_output(pkg_config, '--libs', package_desc)
        # Remove evil flags like -Wl,--export-dynamic
        return tuple(libs.replace('-Wl,--export-dynamic', '').split())

    @depends(pkg_cflags, pkg_libs, when=package)
    def pkg_info(cflags, libs):
        return namespace(cflags=cflags, libs=libs)

    set_config('%s_CFLAGS' % var, pkg_cflags)
    set_config('%s_LIBS' % var, pkg_libs)

    return pkg_info