Пример #1
0
def configure(conf):

    # Which mkspec should we use, by default, use the cxx_default
    # that simply fallbacks to use waf auto detect of compiler etc.
    mkspec = "cxx_default"

    if conf.has_tool_option('cxx_mkspec'):
        mkspec = conf.get_tool_option('cxx_mkspec')

    conf.msg('Using the mkspec:', mkspec)

    # Find and call the mkspec function on the conf object
    if hasattr(conf, mkspec):
        getattr(conf, mkspec)()
    else:
        conf.fatal("The mkspec is not available: {0}".format(mkspec))

    # Additional flags for C/C++ compiler and linker
    if conf.has_tool_option('cflags'):
        conf.env['CFLAGS'] += conf.get_tool_option('cflags').split(';')
    if conf.has_tool_option('cxxflags'):
        conf.env['CXXFLAGS'] += conf.get_tool_option('cxxflags').split(';')
    if conf.has_tool_option('linkflags'):
        conf.env['LINKFLAGS'] += conf.get_tool_option('linkflags').split(';')

    # Common flags to be set for C/C++ compiler and linker
    if conf.has_tool_option('commonflags'):
        conf.env['CFLAGS'] += conf.get_tool_option('commonflags').split(';')
        conf.env['CXXFLAGS'] += conf.get_tool_option('commonflags').split(';')
        conf.env['LINKFLAGS'] += conf.get_tool_option('commonflags').split(';')
Пример #2
0
def check_with(conf, check, what, *args, **kwargs):
    """
    Perform `check`, also looking at directories specified by the --with-X 
    commandline option and X_HOME environment variable (X = what.upper())
    
    The extra_args
    """
    import os
    from os.path import abspath
    
    with_dir = getattr(conf.options, "with_" + what, None)
    env_dir = os.environ.get(what.upper() + "_HOME", None)
    paths = [with_dir, env_dir] + kwargs.pop("extra_paths", [])
    
    WHAT = what.upper()
    kwargs["uselib_store"] = kwargs.get("uselib_store", WHAT)
    kwargs["use"] = kwargs.get("use", []) + [kwargs["uselib_store"]]
        
    for path in [abspath(p) for p in paths if p]:
        conf.to_log("Checking for %s in %s" % (what, path))
        if conf.find_at(check, WHAT, path, **kwargs):
            conf.msg("Found %s at" % what, path, color="WHITE")
            return
    
    check(**kwargs)
    conf.msg("Found %s at" % what, "(local environment)", color="WHITE")
Пример #3
0
def set_variant(conf, variant, env):
    conf.msg('----------------------------------------', '----{ %s' % variant)
    conf.setenv(variant, env=env)
    compiler = FLAGS[conf.env.COMPILER_CXX]
    arch = 'arch_%d' % TARGETS[conf.env.TARGET]['arch']
    compiler_target = compiler[arch] if arch in compiler else None

    # Compiler options
    conf.env.CXXFLAGS = compiler['common'] + compiler[variant]
    if compiler_target and 'cxxflags' in compiler_target:
        conf.env.CXXFLAGS += compiler_target['cxxflags']

    # Linker options
    conf.env.LINKFLAGS = compiler['link_' + variant]
    if compiler_target and 'linkflags' in compiler_target:
        conf.env.LINKFLAGS += compiler_target['linkflags']

    # Includes and defines
    if conf.env.TARGET == 'windows_x86':
        conf.define('WIN32_LEAN_AND_MEAN', 1)
    if compiler_target and 'env' in compiler_target:
        for key, value in compiler_target['env'].items():
            conf.env[key] = value

    conf.env.MSVC_MANIFEST = False
Пример #4
0
def find_at(conf, check, what, where, **kwargs):
    if not exists(where):
        conf.msg("Specified path for %s" % what, "doesn't exist: %s" % where, color="RED")
        return False
        
    pkgp = os.getenv("PKG_CONFIG_PATH", "")
    try:
        conf.env.stash()
        conf.env[what + "_HOME"] = where
        conf.env.append_value('PATH',  pjoin(where, "bin"))
        conf.env.append_value('RPATH', pjoin(where, "lib"))
        pkgconf_path = pjoin(where, "lib/pkgconfig")
        conf.env.append_value('PKG_CONFIG_PATH', pkgconf_path)
        conf.to_log("Pkg config path: %s" % conf.env.PKG_CONFIG_PATH)
        
        if pkgp: pkgp = pkgp + ":"
        os.environ["PKG_CONFIG_PATH"] = pkgconf_path + pkgp
        
        conf.parse_flags("-I%s/include -L%s/lib" % (where, where),
                         uselib=kwargs["uselib_store"])
        this_kwargs = kwargs.copy()
        this_kwargs['check_path'] = where
        check(**this_kwargs)
        return True
    except conf.errors.ConfigurationError:
        raise
        os.environ["PKG_CONFIG_PATH"] = pkgp
        conf.end_msg("failed", color="YELLOW")
        conf.env.revert()
        return False
Пример #5
0
def check_python_version(conf, minver=None):
    assert minver is None or isinstance(minver, tuple)
    pybin = conf.env["PYTHON"]
    if not pybin:
        conf.fatal("could not find the python executable")
    cmd = pybin + ["-c", "import sys\nfor x in sys.version_info: print(str(x))"]
    debug("python: Running python command %r" % cmd)
    lines = conf.cmd_and_log(cmd).split()
    assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))
    result = (minver is None) or (pyver_tuple >= minver)
    if result:
        pyver = ".".join([str(x) for x in pyver_tuple[:2]])
        conf.env["PYTHON_VERSION"] = pyver
        if "PYTHONDIR" in conf.environ:
            pydir = conf.environ["PYTHONDIR"]
        else:
            if Utils.is_win32:
                (python_LIBDEST, pydir) = conf.get_python_variables(
                    [
                        "get_config_var('LIBDEST') or ''",
                        "get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env["PREFIX"],
                    ],
                    ["from distutils.sysconfig import get_config_var, get_python_lib"],
                )
            else:
                python_LIBDEST = None
                (pydir,) = conf.get_python_variables(
                    ["get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env["PREFIX"]],
                    ["from distutils.sysconfig import get_python_lib"],
                )
            if python_LIBDEST is None:
                if conf.env["LIBDIR"]:
                    python_LIBDEST = os.path.join(conf.env["LIBDIR"], "python" + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env["PREFIX"], "lib", "python" + pyver)
        if "PYTHONARCHDIR" in conf.environ:
            pyarchdir = conf.environ["PYTHONARCHDIR"]
        else:
            (pyarchdir,) = conf.get_python_variables(
                ["get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''" % conf.env["PREFIX"]],
                ["from distutils.sysconfig import get_python_lib"],
            )
            if not pyarchdir:
                pyarchdir = pydir
        if hasattr(conf, "define"):
            conf.define("PYTHONDIR", pydir)
            conf.define("PYTHONARCHDIR", pyarchdir)
        conf.env["PYTHONDIR"] = pydir
        conf.env["PYTHONARCHDIR"] = pyarchdir
    pyver_full = ".".join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.msg("Checking for python version", pyver_full)
    else:
        minver_str = ".".join(map(str, minver))
        conf.msg("Checking for python version", pyver_tuple, ">= %s" % (minver_str,) and "GREEN" or "YELLOW")
    if not result:
        conf.fatal("The python version is too old, expecting %r" % (minver,))
Пример #6
0
def configure(conf):
    arduino_path = getattr(Options.options, 'ARDUINO_DIR', None)

    if (arduino_path and os.path.exists(arduino_path)):
        conf.env.ARDUINO_DIR = arduino_path
    else:
        conf.env.ARDUINO_DIR = os.environ.get('ARDUINO_DIR', DEFAULT_ARDUINO_DIR)

    conf.msg('Arduino root path', conf.env.ARDUINO_DIR)

    board = getattr(Options.options, 'BOARD', 'uno')
    conf.check_board(board);
Пример #7
0
def configure(conf):
	# Check that the NDK path was given on the command-line
	conf.msg("NDK path configured with --ndk", conf.options.ndk != None)
	if not conf.options.ndk:
		raise "no NDK path"
	
	conf.load('android-gcc', tooldir="waf-tools")
	conf.find_android_gxx()
	conf.load('android-ar', tooldir="waf-tools")
	conf.android_gxx_common_flags()
	conf.android_gxx_modifier_platform()
	conf.cxx_load_tools()
	conf.cxx_add_flags()
	conf.link_add_flags()
Пример #8
0
def check_python_version(conf,minver=None):
	assert minver is None or isinstance(minver,tuple)
	pybin=conf.env['PYTHON']
	if not pybin:
		conf.fatal('could not find the python executable')
	cmd=pybin+['-c','import sys\nfor x in sys.version_info: print(str(x))']
	Logs.debug('python: Running python command %r'%cmd)
	lines=conf.cmd_and_log(cmd).split()
	assert len(lines)==5,"found %i lines, expected 5: %r"%(len(lines),lines)
	pyver_tuple=(int(lines[0]),int(lines[1]),int(lines[2]),lines[3],int(lines[4]))
	result=(minver is None)or(pyver_tuple>=minver)
	if result:
		pyver='.'.join([str(x)for x in pyver_tuple[:2]])
		conf.env['PYTHON_VERSION']=pyver
		if'PYTHONDIR'in conf.env:
			pydir=conf.env['PYTHONDIR']
		elif'PYTHONDIR'in conf.environ:
			pydir=conf.environ['PYTHONDIR']
		else:
			if Utils.is_win32:
				(python_LIBDEST,pydir)=conf.get_python_variables(["get_config_var('LIBDEST') or ''","get_python_lib(standard_lib=0) or ''"])
			else:
				python_LIBDEST=None
				(pydir,)=conf.get_python_variables(["get_python_lib(standard_lib=0) or ''"])
			if python_LIBDEST is None:
				if conf.env['LIBDIR']:
					python_LIBDEST=os.path.join(conf.env['LIBDIR'],"python"+pyver)
				else:
					python_LIBDEST=os.path.join(conf.env['PREFIX'],"lib","python"+pyver)
		if'PYTHONARCHDIR'in conf.env:
			pyarchdir=conf.env['PYTHONARCHDIR']
		elif'PYTHONARCHDIR'in conf.environ:
			pyarchdir=conf.environ['PYTHONARCHDIR']
		else:
			(pyarchdir,)=conf.get_python_variables(["get_python_lib(plat_specific=1, standard_lib=0) or ''"])
			if not pyarchdir:
				pyarchdir=pydir
		if hasattr(conf,'define'):
			conf.define('PYTHONDIR',pydir)
			conf.define('PYTHONARCHDIR',pyarchdir)
		conf.env['PYTHONDIR']=pydir
		conf.env['PYTHONARCHDIR']=pyarchdir
	pyver_full='.'.join(map(str,pyver_tuple[:3]))
	if minver is None:
		conf.msg('Checking for python version',pyver_full)
	else:
		minver_str='.'.join(map(str,minver))
		conf.msg('Checking for python version',pyver_tuple,">= %s"%(minver_str,)and'GREEN'or'YELLOW')
	if not result:
		conf.fatal('The python version is too old, expecting %r'%(minver,))
Пример #9
0
def lp_lib (conf):
    # Set env variable with the prefix of plugins which handle lp
    conf.env.LPLIB_PLUGIN_PREFIX = LPLIB_PLUGIN_PREFIX

    Logs.pprint ("BLUE", "Configuration of the library for LP")

    if conf.options.LP_LIB is None:
        conf.fatal ("The lp_lib_none plugin is not available.")

    conf.msg ("Library for LP", conf.options.LP_LIB)
    lplib_dirname = LPLIB_PLUGIN_PREFIX + conf.options.LP_LIB
    plugin_node = conf.path.find_node ("plugins")
    lplib_node = plugin_node.find_node (lplib_dirname)

    # Recurse on the plugin
    conf.recurse (os.path.join ("plugins", lplib_dirname))

    # Add lplib_dir to INCLUDES
    conf.env.append_unique ("INCLUDES_LP_LIB", lplib_node.abspath())

    # check that mandatory files exist
    for f in [ "ibex_LPWrapper.cpp_" ]:
        if lplib_node.find_node (f) is None:
            conf.fatal ("A LP plugin must contain a file named %s" % f)

    # The following variables must be defined in env by the plugin called to
    # handle the LP library.
    for var in [ "LP_LIB", "IBEX_LP_LIB_INCLUDES",
                 "IBEX_LP_LIB_EXTRA_ATTRIBUTES" ]:
        if not var in conf.env:
            err = "%s must be defined in env by the plugin %s" % (var, lplib_dirname)
            conf.fatal (err)

    # Copy in _IBEX_DEPS some important variables from _LP_LIB
    # The plugin must use the store LP_LIB (uselib_store argument with
    # conf.check* functions).
    conf.env.append_unique ("CXXFLAGS_IBEX_DEPS", conf.env.CXXFLAGS_LP_LIB)
    if conf.env.ENABLE_SHARED:
        # if shared lib is used, 3rd party libs are compiled as static lib with
        # -fPIC and are contained in libibex
        for lib in conf.env.LIB_LP_LIB:
            if not lib in conf.env.LIB_3RD_LIST:
                conf.env.append_unique ("LIB_IBEX_DEPS", lib)
    else:
        conf.env.append_unique ("LIB_IBEX_DEPS", conf.env.LIB_LP_LIB)

    # Add info on the LP library used to the settings
    conf.setting_define ("LP_LIB", conf.env["LP_LIB"])
Пример #10
0
def check_swig_version(conf, minver=None):
	"""
	Check if the swig tool is found matching a given minimum version.
	minver should be a tuple, eg. to check for swig >= 1.3.28 pass (1,3,28) as minver.

	If successful, SWIG_VERSION is defined as 'MAJOR.MINOR'
	(eg. '1.3') of the actual swig version found.

	:param minver: minimum version
	:type minver: tuple of int
	:return: swig version
	:rtype: tuple of int
	"""
	assert minver is None or isinstance(minver, tuple)
	swigbin = conf.env['SWIG']
	if not swigbin:
		conf.fatal('could not find the swig executable')

	# Get swig version string
	cmd = swigbin + ['-version']
	Logs.debug('swig: Running swig command %r', cmd)
	reg_swig = re.compile(r'SWIG Version\s(.*)', re.M)
	swig_out = conf.cmd_and_log(cmd)
	swigver_tuple = tuple([int(s) for s in reg_swig.findall(swig_out)[0].split('.')])

	# Compare swig version with the minimum required
	result = (minver is None) or (swigver_tuple >= minver)

	if result:
		# Define useful environment variables
		swigver = '.'.join([str(x) for x in swigver_tuple[:2]])
		conf.env['SWIG_VERSION'] = swigver

	# Feedback
	swigver_full = '.'.join(map(str, swigver_tuple[:3]))
	if minver is None:
		conf.msg('Checking for swig version', swigver_full)
	else:
		minver_str = '.'.join(map(str, minver))
		conf.msg('Checking for swig version >= %s' % (minver_str,), swigver_full, color=result and 'GREEN' or 'YELLOW')

	if not result:
		conf.fatal('The swig version is too old, expecting %r' % (minver,))

	return swigver_tuple
Пример #11
0
def check_python_version(conf, minver=None):
	"""
	Check if the python interpreter is found matching a given minimum version.
	minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.

	If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR'
	(eg. '2.4') of the actual python version found, and PYTHONDIR is
	defined, pointing to the site-packages directory appropriate for
	this python version, where modules/packages/extensions should be
	installed.

	:param minver: minimum version
	:type minver: tuple of int
	"""
	assert minver is None or isinstance(minver, tuple)
	pybin = conf.env['PYTHON']
	if not pybin:
		conf.fatal('could not find the python executable')

	# Get python version string
	cmd = pybin + ['-c', 'import sys\nfor x in sys.version_info: print(str(x))']
	debug('python: Running python command %r' % cmd)
	lines = conf.cmd_and_log(cmd).split()
	assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
	pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))

	# compare python version with the minimum required
	result = (minver is None) or (pyver_tuple >= minver)

	if result:
		# define useful environment variables
		pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
		conf.env['PYTHON_VERSION'] = pyver

	# Feedback
	pyver_full = '.'.join(map(str, pyver_tuple[:3]))
	if minver is None:
		conf.msg('Checking for python version', pyver_full)
	else:
		minver_str = '.'.join(map(str, minver))
		conf.msg('Checking for python version', pyver_tuple, ">= %s" % (minver_str,) and 'GREEN' or 'YELLOW')

	if not result:
		conf.fatal('The python version is too old, expecting %r' % (minver,))
Пример #12
0
def configure(conf):
    conf.env.TARGET = platform.system().lower() + '_' + platform.machine().lower()
    conf.msg('Setting target to', conf.env.TARGET)

    conf.define('GTEST_LANG_CXX11', 1)
    conf.define('BOOSTTHREAD_USE_LIB', 1)
    conf.define('BOOSTTHREAD_VERSION', 4)
    for key, value in TARGETS[conf.env.TARGET].items():
        conf.env[key] = value

    conf.load('cpplint waf_unit_test compiler_cxx boost qt5')

    env = conf.env.derive()
    conf.set_variant('release', env)
    conf.check_libs()

    conf.set_variant('debug', env)
    conf.check_libs()

    Logs.info('---------------------------------------- :')
    conf.check_cpp14()
Пример #13
0
def apply_patch (conf, patch_abspath):
	conf.msg ("Applying patch", os.path.basename (patch_abspath))
	p = patch.fromfile (patch_abspath)
	if not p.apply (root = conf.bldnode.make_node ("3rd").abspath()):
		conf.fatal ("Cannot apply patch %s" % patch_abspath)
Пример #14
0
def check_python_version(conf, minver=None):
    """
	Check if the python interpreter is found matching a given minimum version.
	minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.

	If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR'
	(eg. '2.4') of the actual python version found, and PYTHONDIR is
	defined, pointing to the site-packages directory appropriate for
	this python version, where modules/packages/extensions should be
	installed.

	:param minver: minimum version
	:type minver: tuple of int
	"""
    assert minver is None or isinstance(minver, tuple)
    python = conf.env["PYTHON"]
    if not python:
        conf.fatal("could not find the python executable")

        # Get python version string
    cmd = [python, "-c", "import sys\nfor x in sys.version_info: print(str(x))"]
    debug("python: Running python command %r" % cmd)
    lines = conf.cmd_and_log(cmd).split()
    assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))

    # compare python version with the minimum required
    result = (minver is None) or (pyver_tuple >= minver)

    if result:
        # define useful environment variables
        pyver = ".".join([str(x) for x in pyver_tuple[:2]])
        conf.env["PYTHON_VERSION"] = pyver

        if "PYTHONDIR" in conf.environ:
            pydir = conf.environ["PYTHONDIR"]
        else:
            if sys.platform == "win32":
                (python_LIBDEST, pydir) = conf.get_python_variables(
                    python,
                    ["get_config_var('LIBDEST')", "get_python_lib(standard_lib=0, prefix=%r)" % conf.env["PREFIX"]],
                    ["from distutils.sysconfig import get_config_var, get_python_lib"],
                )
            else:
                python_LIBDEST = None
                (pydir,) = conf.get_python_variables(
                    python,
                    ["get_python_lib(standard_lib=0, prefix=%r)" % conf.env["PREFIX"]],
                    ["from distutils.sysconfig import get_config_var, get_python_lib"],
                )
            if python_LIBDEST is None:
                if conf.env["LIBDIR"]:
                    python_LIBDEST = os.path.join(conf.env["LIBDIR"], "python" + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env["PREFIX"], "lib", "python" + pyver)

        if hasattr(conf, "define"):  # conf.define is added by the C tool, so may not exist
            conf.define("PYTHONDIR", pydir)
        conf.env["PYTHONDIR"] = pydir

        # Feedback
    pyver_full = ".".join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.msg("Checking for python version", pyver_full)
    else:
        minver_str = ".".join(map(str, minver))
        conf.msg("Checking for python version", pyver_tuple, ">= %s" % (minver_str,) and "GREEN" or "YELLOW")

    if not result:
        conf.fatal("The python version is too old, expecting %r" % (minver,))
Пример #15
0
def check_python_version(conf, minver=None):
    assert minver is None or isinstance(minver, tuple)
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal('could not find the python executable')
    cmd = pybin + [
        '-c', 'import sys\nfor x in sys.version_info: print(str(x))'
    ]
    Logs.debug('python: Running python command %r', cmd)
    lines = conf.cmd_and_log(cmd).split()
    assert len(lines) == 5, "found %r lines, expected 5: %r" % (len(lines),
                                                                lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3],
                   int(lines[4]))
    result = (minver is None) or (pyver_tuple >= minver)
    if result:
        pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
        conf.env.PYTHON_VERSION = pyver
        if 'PYTHONDIR' in conf.env:
            pydir = conf.env.PYTHONDIR
        elif 'PYTHONDIR' in conf.environ:
            pydir = conf.environ['PYTHONDIR']
        else:
            if Utils.is_win32:
                (python_LIBDEST, pydir) = conf.get_python_variables([
                    "get_config_var('LIBDEST') or ''",
                    "get_python_lib(standard_lib=0) or ''"
                ])
            else:
                python_LIBDEST = None
                (pydir, ) = conf.get_python_variables([
                    "get_python_lib(standard_lib=0, prefix=%r) or ''" %
                    conf.env.PREFIX
                ])
            if python_LIBDEST is None:
                if conf.env.LIBDIR:
                    python_LIBDEST = os.path.join(conf.env.LIBDIR,
                                                  'python' + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env.PREFIX, 'lib',
                                                  'python' + pyver)
        if 'PYTHONARCHDIR' in conf.env:
            pyarchdir = conf.env.PYTHONARCHDIR
        elif 'PYTHONARCHDIR' in conf.environ:
            pyarchdir = conf.environ['PYTHONARCHDIR']
        else:
            (pyarchdir, ) = conf.get_python_variables([
                "get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''"
                % conf.env.PREFIX
            ])
            if not pyarchdir:
                pyarchdir = pydir
        if hasattr(conf, 'define'):
            conf.define('PYTHONDIR', pydir)
            conf.define('PYTHONARCHDIR', pyarchdir)
        conf.env.PYTHONDIR = pydir
        conf.env.PYTHONARCHDIR = pyarchdir
    pyver_full = '.'.join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.msg('Checking for python version', pyver_full)
    else:
        minver_str = '.'.join(map(str, minver))
        conf.msg('Checking for python version >= %s' % (minver_str, ),
                 pyver_full,
                 color=result and 'GREEN' or 'YELLOW')
    if not result:
        conf.fatal('The python version is too old, expecting %r' % (minver, ))
Пример #16
0
def check_python_version(conf, minver=None):
	"""
	Check if the python interpreter is found matching a given minimum version.
	minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.

	If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR'
	(eg. '2.4') of the actual python version found, and PYTHONDIR is
	defined, pointing to the site-packages directory appropriate for
	this python version, where modules/packages/extensions should be
	installed.

	:param minver: minimum version
	:type minver: tuple of int
	"""
	assert minver is None or isinstance(minver, tuple)
	pybin = conf.env['PYTHON']
	if not pybin:
		conf.fatal('could not find the python executable')

	# Get python version string
	cmd = pybin + ['-c', 'import sys\nfor x in sys.version_info: print(str(x))']
	Logs.debug('python: Running python command %r' % cmd)
	lines = conf.cmd_and_log(cmd).split()
	assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
	pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))

	# compare python version with the minimum required
	result = (minver is None) or (pyver_tuple >= minver)

	if result:
		# define useful environment variables
		pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
		conf.env['PYTHON_VERSION'] = pyver

		if 'PYTHONDIR' in conf.environ:
			pydir = conf.environ['PYTHONDIR']
		else:
			if Utils.is_win32:
				(python_LIBDEST, pydir) = conf.get_python_variables(
					  ["get_config_var('LIBDEST') or ''",
					   "get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']])
			else:
				python_LIBDEST = None
				(pydir,) = conf.get_python_variables( ["get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']])
			if python_LIBDEST is None:
				if conf.env['LIBDIR']:
					python_LIBDEST = os.path.join(conf.env['LIBDIR'], "python" + pyver)
				else:
					python_LIBDEST = os.path.join(conf.env['PREFIX'], "lib", "python" + pyver)


		if 'PYTHONARCHDIR' in conf.environ:
			pyarchdir = conf.environ['PYTHONARCHDIR']
		else:
			(pyarchdir, ) = conf.get_python_variables( ["get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']])
			if not pyarchdir:
				pyarchdir = pydir

		if hasattr(conf, 'define'): # conf.define is added by the C tool, so may not exist
			conf.define('PYTHONDIR', pydir)
			conf.define('PYTHONARCHDIR', pyarchdir)

		conf.env['PYTHONDIR'] = pydir
		conf.env['PYTHONARCHDIR'] = pyarchdir

	# Feedback
	pyver_full = '.'.join(map(str, pyver_tuple[:3]))
	if minver is None:
		conf.msg('Checking for python version', pyver_full)
	else:
		minver_str = '.'.join(map(str, minver))
		conf.msg('Checking for python version', pyver_tuple, ">= %s" % (minver_str,) and 'GREEN' or 'YELLOW')

	if not result:
		conf.fatal('The python version is too old, expecting %r' % (minver,))
Пример #17
0
def check_python_version(conf, minver=None):
    """
	Check if the python interpreter is found matching a given minimum version.
	minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.

	If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR' (eg. '2.4')
	of the actual python version found, and PYTHONDIR and PYTHONARCHDIR
	are defined, pointing to the site-packages directories appropriate for
	this python version, where modules/packages/extensions should be
	installed.

	:param minver: minimum version
	:type minver: tuple of int
	"""
    assert minver is None or isinstance(minver, tuple)
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal('could not find the python executable')

    # Get python version string
    cmd = pybin + [
        '-c', 'import sys\nfor x in sys.version_info: print(str(x))'
    ]
    Logs.debug('python: Running python command %r', cmd)
    lines = conf.cmd_and_log(cmd).split()
    assert len(lines) == 5, "found %r lines, expected 5: %r" % (len(lines),
                                                                lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3],
                   int(lines[4]))

    # Compare python version with the minimum required
    result = (minver is None) or (pyver_tuple >= minver)

    if result:
        # define useful environment variables
        pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
        conf.env.PYTHON_VERSION = pyver

        if 'PYTHONDIR' in conf.env:
            # Check if --pythondir was specified
            pydir = conf.env.PYTHONDIR
        elif 'PYTHONDIR' in conf.environ:
            # Check environment for PYTHONDIR
            pydir = conf.environ['PYTHONDIR']
        else:
            # Finally, try to guess
            if Utils.is_win32:
                (python_LIBDEST, pydir) = conf.get_python_variables([
                    "get_config_var('LIBDEST') or ''",
                    "get_python_lib(standard_lib=0) or ''"
                ])
            else:
                python_LIBDEST = None
                (pydir, ) = conf.get_python_variables([
                    "get_python_lib(standard_lib=0, prefix=%r) or ''" %
                    conf.env.PREFIX
                ])
            if python_LIBDEST is None:
                if conf.env.LIBDIR:
                    python_LIBDEST = os.path.join(conf.env.LIBDIR,
                                                  'python' + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env.PREFIX, 'lib',
                                                  'python' + pyver)

        if 'PYTHONARCHDIR' in conf.env:
            # Check if --pythonarchdir was specified
            pyarchdir = conf.env.PYTHONARCHDIR
        elif 'PYTHONARCHDIR' in conf.environ:
            # Check environment for PYTHONDIR
            pyarchdir = conf.environ['PYTHONARCHDIR']
        else:
            # Finally, try to guess
            (pyarchdir, ) = conf.get_python_variables([
                "get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''"
                % conf.env.PREFIX
            ])
            if not pyarchdir:
                pyarchdir = pydir

        if hasattr(conf, 'define'
                   ):  # conf.define is added by the C tool, so may not exist
            conf.define('PYTHONDIR', pydir)
            conf.define('PYTHONARCHDIR', pyarchdir)

        conf.env.PYTHONDIR = pydir
        conf.env.PYTHONARCHDIR = pyarchdir

    # Feedback
    pyver_full = '.'.join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.msg('Checking for python version', pyver_full)
    else:
        minver_str = '.'.join(map(str, minver))
        conf.msg('Checking for python version >= %s' % (minver_str, ),
                 pyver_full,
                 color=result and 'GREEN' or 'YELLOW')

    if not result:
        conf.fatal('The python version is too old, expecting %r' % (minver, ))