def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True, boolean=False): '''run a command and return result''' if msg is None: msg = 'Checking %s' % ' '.join(cmd) conf.COMPOUND_START(msg) cmd = cmd[:] if on_target: cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg)) try: ret = Utils.cmd_output(cmd).decode('utf8') except: conf.COMPOUND_END(False) return False if boolean: conf.COMPOUND_END('ok') if define: conf.DEFINE(define, '1') else: ret = ret.strip() conf.COMPOUND_END(ret) if define: conf.DEFINE(define, ret, quote=True) return ret
def run_app(self): args = conf.SAMBA_CROSS_ARGS(msg=msg) env = dict(os.environ) env['LD_LIBRARY_PATH'] = self.inputs[0].parent.abspath( ) + os.pathsep + env.get('LD_LIBRARY_PATH', '') self.generator.bld.cmd_and_log([self.inputs[0].abspath()] + args, env=env)
def CHECK_CODE(conf, code, define, always=False, execute=False, addmain=True, add_headers=True, mandatory=False, headers=None, msg=None, cflags='', includes='# .', local_include=True, lib=None, link=True, define_ret=False, quote=False, on_target=True, strict=False): '''check if some code compiles and/or runs''' if CONFIG_SET(conf, define): return True if headers is not None: CHECK_HEADERS(conf, headers=headers, lib=lib) if add_headers: hdrs = header_list(conf, headers=headers, lib=lib) else: hdrs = '' if execute: execute = 1 else: execute = 0 if addmain: fragment = '%s\n int main(void) { %s; return 0; }\n' % (hdrs, code) else: fragment = '%s\n%s\n' % (hdrs, code) if msg is None: msg = "Checking for %s" % define cflags = TO_LIST(cflags) # Be strict when relying on a compiler check # Some compilers (e.g. xlc) ignore non-supported features as warnings if strict: if 'WERROR_CFLAGS' in conf.env: cflags.extend(conf.env['WERROR_CFLAGS']) if local_include: cflags.append('-I%s' % conf.path.abspath()) if not link: type = 'nolink' else: type = 'cprogram' uselib = TO_LIST(lib) (ccflags, ldflags, cpppath) = library_flags(conf, uselib) includes = TO_LIST(includes) includes.extend(cpppath) uselib = [l.upper() for l in uselib] cflags.extend(ccflags) if on_target: test_args = conf.SAMBA_CROSS_ARGS(msg=msg) else: test_args = [] conf.COMPOUND_START(msg) try: ret = conf.check(fragment=fragment, execute=execute, define_name=define, cflags=cflags, ldflags=ldflags, includes=includes, uselib=uselib, type=type, msg=msg, quote=quote, test_args=test_args, define_ret=define_ret) except Exception: if always: conf.DEFINE(define, 0) else: conf.undefine(define) conf.COMPOUND_END(False) if mandatory: raise return False else: # Success is indicated by ret but we should unset # defines set by WAF's c_config.check() because it # defines it to int(ret) and we want to undefine it if not ret: conf.undefine(define) conf.COMPOUND_END(False) return False if not define_ret: conf.DEFINE(define, 1) conf.COMPOUND_END(True) else: conf.DEFINE(define, ret, quote=quote) conf.COMPOUND_END(ret) return True
def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None): '''see if the platform supports building libraries''' if msg is None: if rpath: msg = "rpath library support" else: msg = "building library support" dir = find_config_dir(conf) bdir = os.path.join(dir, 'testbuild') if not os.path.exists(bdir): os.makedirs(bdir) env = conf.env subdir = os.path.join(dir, "libdir") os.makedirs(subdir) Utils.writef(os.path.join(subdir, 'lib1.c'), 'int lib_func(void) { return 42; }\n') Utils.writef( os.path.join(dir, 'main.c'), 'int lib_func(void);\n' 'int main(void) {return !(lib_func() == 42);}\n') bld = Build.BuildContext() bld.log = conf.log bld.all_envs.update(conf.all_envs) bld.all_envs['default'] = env bld.lst_variants = bld.all_envs.keys() bld.load_dirs(dir, bdir) bld.rescan(bld.srcnode) ldflags = [] if version_script: ldflags.append("-Wl,--version-script=%s/vscript" % bld.path.abspath()) Utils.writef(os.path.join(dir, 'vscript'), 'TEST_1.0A2 { global: *; };\n') bld(features='c cshlib', source='libdir/lib1.c', target='libdir/lib1', ldflags=ldflags, name='lib1') o = bld(features='c cprogram', source='main.c', target='prog1', uselib_local='lib1') if rpath: o.rpath = os.path.join(bdir, 'default/libdir') # compile the program try: bld.compile() except: conf.check_message(msg, '', False) return False # path for execution lastprog = o.link_task.outputs[0].abspath(env) if not rpath: if 'LD_LIBRARY_PATH' in os.environ: old_ld_library_path = os.environ['LD_LIBRARY_PATH'] else: old_ld_library_path = None ADD_LD_LIBRARY_PATH(os.path.join(bdir, 'default/libdir')) # we need to run the program, try to get its result args = conf.SAMBA_CROSS_ARGS(msg=msg) proc = Utils.subprocess.Popen([lastprog] + args, stdout=Utils.subprocess.PIPE, stderr=Utils.subprocess.PIPE) (out, err) = proc.communicate() w = conf.log.write w(str(out)) w('\n') w(str(err)) w('\nreturncode %r\n' % proc.returncode) ret = (proc.returncode == 0) if not rpath: os.environ['LD_LIBRARY_PATH'] = old_ld_library_path or '' conf.check_message(msg, '', ret) return ret