diff options
Diffstat (limited to 'waftools/checks')
-rw-r--r-- | waftools/checks/__init__.py | 0 | ||||
-rw-r--r-- | waftools/checks/custom.py | 153 | ||||
-rw-r--r-- | waftools/checks/generic.py | 204 |
3 files changed, 0 insertions, 357 deletions
diff --git a/waftools/checks/__init__.py b/waftools/checks/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/waftools/checks/__init__.py +++ /dev/null diff --git a/waftools/checks/custom.py b/waftools/checks/custom.py deleted file mode 100644 index 36c1d85d06..0000000000 --- a/waftools/checks/custom.py +++ /dev/null @@ -1,153 +0,0 @@ -from waftools import inflector -from waftools.checks.generic import * -from waflib import Utils -from distutils.version import StrictVersion -import os - -__all__ = ["check_pthreads", "check_iconv", "check_lua", - "check_cocoa", "check_wl_protocols", "check_swift", - "check_egl_provider"] - -pthreads_program = load_fragment('pthreads.c') - -def check_pthread_flag(ctx, dependency_identifier): - checks = [ - check_cc(fragment = pthreads_program, cflags = '-pthread'), - check_cc(fragment = pthreads_program, cflags = '-pthread', - linkflags = '-pthread') ] - - for fn in checks: - if fn(ctx, dependency_identifier): - return True - return False - -def check_pthreads(ctx, dependency_identifier): - if ctx.dependency_satisfied('win32-internal-pthreads'): - h = ctx.path.find_node('osdep/win32/include').abspath() - # define IN_WINPTHREAD to workaround mingw stupidity (we never want it - # to define features specific to its own pthread stuff) - ctx.env.CFLAGS += ['-isystem', h, '-I', h, '-DIN_WINPTHREAD'] - return True - if check_pthread_flag(ctx, dependency_identifier): - return True - platform_cflags = { - 'linux': '-D_REENTRANT', - 'freebsd': '-D_THREAD_SAFE', - 'netbsd': '-D_THREAD_SAFE', - 'openbsd': '-D_THREAD_SAFE', - }.get(ctx.env.DEST_OS, '') - libs = ['pthreadGC2', 'pthread'] - checkfn = check_cc(fragment=pthreads_program, cflags=platform_cflags) - checkfn_nocflags = check_cc(fragment=pthreads_program) - for fn in [checkfn, checkfn_nocflags]: - if check_libs(libs, fn)(ctx, dependency_identifier): - return True - return False - -def check_iconv(ctx, dependency_identifier): - iconv_program = load_fragment('iconv.c') - libdliconv = " ".join(ctx.env.LIB_LIBDL + ['iconv']) - libs = ['iconv', libdliconv] - args = {'fragment': iconv_program} - if ctx.env.DEST_OS == 'openbsd' or ctx.env.DEST_OS == 'freebsd': - args['cflags'] = '-I/usr/local/include' - args['linkflags'] = '-L/usr/local/lib' - elif ctx.env.DEST_OS == 'win32': - args['linkflags'] = " ".join(['-L' + x for x in ctx.env.LIBRARY_PATH]) - checkfn = check_cc(**args) - return check_libs(libs, checkfn)(ctx, dependency_identifier) - -def check_lua(ctx, dependency_identifier): - lua_versions = [ - ( '52', 'lua >= 5.2.0 lua < 5.3.0' ), - ( '52arch', 'lua52 >= 5.2.0'), # Arch - ( '52deb', 'lua5.2 >= 5.2.0'), # debian - ( '52fbsd', 'lua-5.2 >= 5.2.0'), # FreeBSD - ( 'luajit', 'luajit >= 2.0.0' ), - ( '51', 'lua >= 5.1.0 lua < 5.2.0'), - ( '51obsd', 'lua51 >= 5.1.0'), # OpenBSD - ( '51deb', 'lua5.1 >= 5.1.0'), # debian - ( '51fbsd', 'lua-5.1 >= 5.1.0'), # FreeBSD - ] - - if ctx.options.LUA_VER: - lua_versions = \ - [lv for lv in lua_versions if lv[0] == ctx.options.LUA_VER] - - for lua_version, pkgconfig_query in lua_versions: - if check_pkg_config(pkgconfig_query, uselib_store=lua_version) \ - (ctx, dependency_identifier): - # XXX: this is a bit of a hack, ask waf developers if I can copy - # the uselib_store to 'lua' - ctx.mark_satisfied(lua_version) - ctx.add_optional_message(dependency_identifier, - 'version found: ' + lua_version) - return True - return False - -def check_wl_protocols(ctx, dependency_identifier): - def fn(ctx, dependency_identifier): - ret = check_pkg_config_datadir("wayland-protocols", ">= 1.15") - ret = ret(ctx, dependency_identifier) - if ret != None: - ctx.env.WL_PROTO_DIR = ret.split()[0] - return ret - return fn(ctx, dependency_identifier) - -def check_cocoa(ctx, dependency_identifier): - fn = check_cc( - fragment = load_fragment('cocoa.m'), - compile_filename = 'test.m', - framework_name = ['Cocoa', 'IOKit', 'OpenGL', 'QuartzCore'], - includes = [ctx.srcnode.abspath()], - linkflags = '-fobjc-arc') - - res = fn(ctx, dependency_identifier) - if res and ctx.env.MACOS_SDK: - # on macOS we explicitly need to set the SDK path, otherwise it can lead - # to linking warnings or errors - ctx.env.append_value('LAST_LINKFLAGS', [ - '-isysroot', ctx.env.MACOS_SDK, - '-L/usr/lib', - '-L/usr/local/lib' - ]) - - return res - -def check_swift(ctx, dependency_identifier): - minVer = StrictVersion("3.0.2") - if ctx.env.SWIFT_VERSION: - if StrictVersion(ctx.env.SWIFT_VERSION) >= minVer: - ctx.add_optional_message(dependency_identifier, - 'version found: ' + str(ctx.env.SWIFT_VERSION)) - return True - ctx.add_optional_message(dependency_identifier, - "'swift >= " + str(minVer) + "' not found, found " + - str(ctx.env.SWIFT_VERSION or None)) - return False - -def check_egl_provider(minVersion=None, name='egl', check=None): - def fn(ctx, dependency_identifier, **kw): - if not hasattr(ctx, 'egl_provider'): - egl_provider_check = check or check_pkg_config(name) - if egl_provider_check(ctx, dependency_identifier): - ctx.egl_provider = name - for ver in ['1.5', '1.4', '1.3', '1.2', '1.1', '1.0']: - stmt = 'int x[EGL_VERSION_{0}]'.format(ver.replace('.','_')) - check_stmt = check_statement(['EGL/egl.h'], stmt) - if check_stmt(ctx, dependency_identifier): - ctx.egl_provider_version = StrictVersion(ver) - break - return True - else: - return False - else: - minVersionSV = minVersion and StrictVersion(minVersion) - if not minVersionSV or ctx.egl_provider_version and \ - ctx.egl_provider_version >= minVersionSV: - defkey = inflector.define_key(dependency_identifier) - ctx.define(defkey, 1) - return True - else: - return False - return fn diff --git a/waftools/checks/generic.py b/waftools/checks/generic.py deleted file mode 100644 index 4e27f5114a..0000000000 --- a/waftools/checks/generic.py +++ /dev/null @@ -1,204 +0,0 @@ -import os -import inflector -from distutils.version import StrictVersion -from waflib.ConfigSet import ConfigSet -from waflib import Utils - -__all__ = [ - "check_pkg_config", "check_pkg_config_mixed", "check_pkg_config_mixed_all", - "check_pkg_config_cflags", "check_cc", "check_statement", "check_libs", - "check_headers", "compose_checks", "any_check", "check_true", "any_version", - "load_fragment", "check_stub", "check_ctx_vars", "check_program", - "check_pkg_config_datadir", "check_macos_sdk"] - -any_version = None - -def even(n): - return n % 2 == 0 - -def __define_options__(dependency_identifier): - return inflector.define_dict(dependency_identifier) - -def __merge_options__(dependency_identifier, *args): - options_accu = inflector.storage_dict(dependency_identifier) - options_accu['mandatory'] = False - [options_accu.update(arg) for arg in args if arg] - return options_accu - -def _filter_cc_arguments(ctx, opts): - if ctx.env.DEST_OS != Utils.unversioned_sys_platform(): - # cross compiling, remove execute=True if present - if opts.get('execute'): - opts['execute'] = False - return opts - -def check_program(name, var): - def fn(ctx, dependency_identifier): - return ctx.find_program(name, var=var, mandatory=False) - return fn - -def check_libs(libs, function): - libs = [None] + libs - def fn(ctx, dependency_identifier): - for lib in libs: - kwargs = lib and {'lib': lib} or {} - if function(ctx, dependency_identifier, **kwargs): - return True - return False - return fn - -def check_statement(header, statement, **kw_ext): - def fn(ctx, dependency_identifier, **kw): - headers = header - if not isinstance(headers, list): - headers = [header] - hs = "\n".join(["#include <{0}>".format(h) for h in headers]) - fragment = ("{0}\n" - "int main(int argc, char **argv)\n" - "{{ {1}; return 0; }}").format(hs, statement) - opts = __merge_options__(dependency_identifier, - {'fragment':fragment}, - __define_options__(dependency_identifier), - kw_ext, kw) - return ctx.check_cc(**_filter_cc_arguments(ctx, opts)) - return fn - -def check_cc(**kw_ext): - def fn(ctx, dependency_identifier, **kw): - options = __merge_options__(dependency_identifier, - __define_options__(dependency_identifier), - kw_ext, kw) - return ctx.check_cc(**_filter_cc_arguments(ctx, options)) - return fn - -def check_pkg_config(*args, **kw_ext): - return _check_pkg_config([], ["--libs", "--cflags"], *args, **kw_ext) - -def check_pkg_config_mixed(_dyn_libs, *args, **kw_ext): - return _check_pkg_config([_dyn_libs], ["--libs", "--cflags"], *args, **kw_ext) - -def check_pkg_config_mixed_all(*all_args, **kw_ext): - args = [all_args[i] for i in [n for n in range(0, len(all_args)) if n % 3]] - return _check_pkg_config(all_args[::3], ["--libs", "--cflags"], *args, **kw_ext) - -def check_pkg_config_cflags(*args, **kw_ext): - return _check_pkg_config([], ["--cflags"], *args, **kw_ext) - -def check_pkg_config_datadir(*args, **kw_ext): - return _check_pkg_config([], ["--variable=pkgdatadir"], *args, **kw_ext) - -def _check_pkg_config(_dyn_libs, _pkgc_args, *args, **kw_ext): - def fn(ctx, dependency_identifier, **kw): - argsl = list(args) - packages = args[::2] - verchecks = args[1::2] - sargs = [] - pkgc_args = _pkgc_args - dyn_libs = {} - for i in range(0, len(packages)): - if i < len(verchecks): - sargs.append(packages[i] + ' ' + verchecks[i]) - else: - sargs.append(packages[i]) - if _dyn_libs and _dyn_libs[i]: - dyn_libs[packages[i]] = _dyn_libs[i] - if ctx.dependency_satisfied('static-build') and not dyn_libs: - pkgc_args += ["--static"] - - defaults = { - 'path': ctx.env.PKG_CONFIG, - 'package': " ".join(packages), - 'args': sargs + pkgc_args } - opts = __merge_options__(dependency_identifier, defaults, kw_ext, kw) - - # Warning! Megahack incoming: when parsing flags in `parse_flags` waf - # uses append_unique. This appends the flags only if they aren't - # already present in the list. This causes breakage if one checks for - # multiple pkg-config packages in a single call as stuff like -lm is - # added only at its first occurrence. - original_append_unique = ConfigSet.append_unique - ConfigSet.append_unique = ConfigSet.append_value - result = ctx.check_cfg(**opts) - ConfigSet.append_unique = original_append_unique - - defkey = inflector.define_key(dependency_identifier) - if result: - ctx.define(defkey, 1) - for x in dyn_libs.keys(): - ctx.env['LIB_'+x] += dyn_libs[x] - else: - ctx.add_optional_message(dependency_identifier, - "'{0}' not found".format(" ".join(sargs))) - ctx.undefine(defkey) - return result - return fn - -def check_headers(*headers, **kw_ext): - def undef_others(ctx, headers, found): - not_found_hs = set(headers) - {found} - for not_found_h in not_found_hs: - ctx.undefine(inflector.define_key(not_found_h)) - - def fn(ctx, dependency_identifier): - for header in headers: - defaults = {'header_name': header, 'features': 'c cprogram'} - options = __merge_options__(dependency_identifier, defaults, kw_ext) - if ctx.check(**options): - undef_others(ctx, headers, header) - ctx.define(inflector.define_key(dependency_identifier), 1) - return True - undef_others(ctx, headers, None) - return False - return fn - -def check_true(ctx, dependency_identifier): - ctx.define(inflector.define_key(dependency_identifier), 1) - return True - -def check_ctx_vars(*variables): - def fn(ctx, dependency_identifier): - missing = [] - for variable in variables: - if variable not in ctx.env: - missing.append(variable) - - if any(missing): - ctx.add_optional_message(dependency_identifier, - 'missing {0}'.format(', '.join(missing))) - return False - else: - return True - - return fn - -def check_stub(ctx, dependency_identifier): - ctx.undefine(inflector.define_key(dependency_identifier)) - return False - -def compose_checks(*checks): - def fn(ctx, dependency_identifier): - return all([check(ctx, dependency_identifier) for check in checks]) - return fn - -def any_check(*checks): - def fn(ctx, dependency_identifier): - return any(check(ctx, dependency_identifier) for check in checks) - return fn - -def load_fragment(fragment): - file_path = os.path.join(os.path.dirname(__file__), '..', 'fragments', - fragment) - fp = open(file_path,"r") - fragment_code = fp.read() - fp.close() - return fragment_code - -def check_macos_sdk(version): - def fn(ctx, dependency_identifier): - if ctx.env.MACOS_SDK_VERSION: - if StrictVersion(ctx.env.MACOS_SDK_VERSION) >= StrictVersion(version): - ctx.define(inflector.define_key(dependency_identifier), 1) - return True - return False - - return fn |