Beispiel #1
0
 def run(self):
     conf = self.conf
     bld = Build.BuildContext(top_dir=conf.srcnode.abspath(),
                              out_dir=conf.bldnode.abspath())
     bld.env = conf.env
     bld.init_dirs()
     bld.in_msg = 1
     bld.logger = self.logger
     bld.multicheck_task = self
     args = self.args
     try:
         if 'func' in args:
             bld.test(
                 build_fun=args['func'],
                 msg=args.get('msg', ''),
                 okmsg=args.get('okmsg', ''),
                 errmsg=args.get('errmsg', ''),
             )
         else:
             args['multicheck_mandatory'] = args.get('mandatory', True)
             args['mandatory'] = True
             try:
                 bld.check(**args)
             finally:
                 args['mandatory'] = args['multicheck_mandatory']
     except Exception:
         return 1
Beispiel #2
0
 def run(self):
     conf = self.conf
     bld = Build.BuildContext(top_dir=conf.srcnode.abspath(),
                              out_dir=conf.bldnode.abspath())
     bld.env = conf.env
     bld.init_dirs()
     bld.in_msg = 1  # suppress top-level start_msg
     bld.logger = self.logger
     bld.multicheck_task = self
     args = self.args
     try:
         if "func" in args:
             bld.test(
                 build_fun=args["func"],
                 msg=args.get("msg", ""),
                 okmsg=args.get("okmsg", ""),
                 errmsg=args.get("errmsg", ""),
             )
         else:
             args["multicheck_mandatory"] = args.get("mandatory", True)
             args["mandatory"] = True
             try:
                 bld.check(**args)
             finally:
                 args["mandatory"] = args["multicheck_mandatory"]
     except Exception:
         return 1
Beispiel #3
0
def run_c_code(self, *k, **kw):
    lst = [str(v) for (p, v) in kw.items() if p != 'env']
    h = Utils.h_list(lst)
    dir = self.bldnode.abspath() + os.sep + (
        sys.platform != 'win32' and '.'
        or '') + 'conf_check_' + Utils.to_hex(h)
    try:
        os.makedirs(dir)
    except:
        pass
    try:
        os.stat(dir)
    except:
        self.fatal('cannot use the configuration test folder %r' % dir)
    cachemode = getattr(Options.options, 'confcache', None)
    if cachemode == CACHE_RESULTS:
        try:
            proj = ConfigSet.ConfigSet(os.path.join(dir, 'cache_run_c_code'))
            ret = proj['cache_run_c_code']
        except:
            pass
        else:
            if isinstance(ret, str) and ret.startswith('Test does not build'):
                self.fatal(ret)
            return ret
    bdir = os.path.join(dir, 'testbuild')
    if not os.path.exists(bdir):
        os.makedirs(bdir)
    self.test_bld = bld = Build.BuildContext(top_dir=dir, out_dir=bdir)
    bld.init_dirs()
    bld.progress_bar = 0
    bld.targets = '*'
    if kw['compile_filename']:
        node = bld.srcnode.make_node(kw['compile_filename'])
        node.write(kw['code'])
    bld.logger = self.logger
    bld.all_envs.update(self.all_envs)
    bld.env = kw['env']
    o = bld(features=kw['features'],
            source=kw['compile_filename'],
            target='testprog')
    for k, v in kw.items():
        setattr(o, k, v)
    self.to_log("==>\n%s\n<==" % kw['code'])
    bld.targets = '*'
    ret = -1
    try:
        try:
            bld.compile()
        except Errors.WafError:
            ret = 'Test does not build: %s' % Utils.ex_stack()
            self.fatal(ret)
        else:
            ret = getattr(bld, 'retval', 0)
    finally:
        proj = ConfigSet.ConfigSet()
        proj['cache_run_c_code'] = ret
        proj.store(os.path.join(dir, 'cache_run_c_code'))
    return ret
Beispiel #4
0
def run_build(self, *k, **kw):
    lst = [str(v) for (p, v) in kw.items() if p != 'env']
    h = Utils.h_list(lst)
    dir = self.bldnode.abspath() + os.sep + (
        not Utils.is_win32 and '.' or '') + 'conf_check_' + Utils.to_hex(h)
    try:
        os.makedirs(dir)
    except OSError:
        pass
    try:
        os.stat(dir)
    except OSError:
        self.fatal('cannot use the configuration test folder %r' % dir)
    cachemode = getattr(Options.options, 'confcache', None)
    if cachemode == 1:
        try:
            proj = ConfigSet.ConfigSet(os.path.join(dir, 'cache_run_build'))
        except OSError:
            pass
        except IOError:
            pass
        else:
            ret = proj['cache_run_build']
            if isinstance(ret, str) and ret.startswith('Test does not build'):
                self.fatal(ret)
            return ret
    bdir = os.path.join(dir, 'testbuild')
    if not os.path.exists(bdir):
        os.makedirs(bdir)
    self.test_bld = bld = Build.BuildContext(top_dir=dir, out_dir=bdir)
    bld.init_dirs()
    bld.progress_bar = 0
    bld.targets = '*'
    bld.logger = self.logger
    bld.all_envs.update(self.all_envs)
    bld.env = kw['env']
    bld.kw = kw
    bld.conf = self
    kw['build_fun'](bld)
    ret = -1
    try:
        try:
            bld.compile()
        except Errors.WafError:
            ret = 'Test does not build: %s' % Utils.ex_stack()
            self.fatal(ret)
        else:
            ret = getattr(bld, 'retval', 0)
    finally:
        if cachemode == 1:
            proj = ConfigSet.ConfigSet()
            proj['cache_run_build'] = ret
            proj.store(os.path.join(dir, 'cache_run_build'))
        else:
            shutil.rmtree(dir)
    return ret
Beispiel #5
0
	def run(self):
		conf=self.conf
		bld=Build.BuildContext(top_dir=conf.srcnode.abspath(),out_dir=conf.bldnode.abspath())
		bld.env=conf.env
		bld.init_dirs()
		bld.in_msg=1
		bld.logger=self.logger
		try:
			bld.check(**self.args)
		except:
			return 1
Beispiel #6
0
	def run(self):
		conf = self.conf
		bld = Build.BuildContext(top_dir=conf.srcnode.abspath(), out_dir=conf.bldnode.abspath())
		bld.env = conf.env
		bld.init_dirs()
		bld.in_msg = 1 # suppress top-level start_msg
		bld.logger = self.logger
		try:
			bld.check(**self.args)
		except Exception:
			return 1
Beispiel #7
0
def CHECK_NEED_LC(conf, msg):
    '''check if we need -lc'''

    dir = find_config_dir(conf)

    env = conf.env

    bdir = os.path.join(dir, 'testbuild2')
    if not os.path.exists(bdir):
        os.makedirs(bdir)

    subdir = os.path.join(dir, "liblctest")

    os.makedirs(subdir)

    Utils.writef(
        os.path.join(subdir, 'liblc1.c'),
        '#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\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)

    bld(features='c cshlib',
        source='liblctest/liblc1.c',
        ldflags=conf.env['EXTRA_LDFLAGS'],
        target='liblc',
        name='liblc')

    try:
        bld.compile()
        conf.check_message(msg, '', True)
        return True
    except:
        conf.check_message(msg, '', False)
        return False
Beispiel #8
0
def run_c_code(self, *k, **kw):
    """
	Create a temporary build context to execute a build. A reference to that build
	context is kept on self.test_bld for debugging purposes.
	The parameters given in the arguments to this function are passed as arguments for
	a single task generator created in the build. Only three parameters are obligatory:

	:param features: features to pass to a task generator created in the build
	:type features: list of string
	:param compile_filename: file to create for the compilation (default: *test.c*)
	:type compile_filename: string
	:param code: code to write in the filename to compile
	:type code: string

	Though this function returns *0* by default, the build may set an attribute named *retval* on the
	build context object to return a particular value. See :py:func:`waflib.Tools.c_config.test_exec_fun` for example.

	This function also provides a limited cache. To use it, provide the following option::

		def options(opt):
			opt.add_option('--confcache', dest='confcache', default=0,
				action='count', help='Use a configuration cache')

	And execute the configuration with the following command-line::

		$ waf configure --confcache

	"""

    lst = [str(v) for (p, v) in kw.items() if p != 'env']
    h = Utils.h_list(lst)
    dir = self.bldnode.abspath() + os.sep + (
        not Utils.is_win32 and '.' or '') + 'conf_check_' + Utils.to_hex(h)

    try:
        os.makedirs(dir)
    except:
        pass

    try:
        os.stat(dir)
    except:
        self.fatal('cannot use the configuration test folder %r' % dir)

    cachemode = getattr(Options.options, 'confcache', None)
    if cachemode == CACHE_RESULTS:
        try:
            proj = ConfigSet.ConfigSet(os.path.join(dir, 'cache_run_c_code'))
            ret = proj['cache_run_c_code']
        except:
            pass
        else:
            if isinstance(ret, str) and ret.startswith('Test does not build'):
                self.fatal(ret)
            return ret

    bdir = os.path.join(dir, 'testbuild')

    if not os.path.exists(bdir):
        os.makedirs(bdir)

    self.test_bld = bld = Build.BuildContext(top_dir=dir, out_dir=bdir)
    bld.init_dirs()
    bld.progress_bar = 0
    bld.targets = '*'

    if kw['compile_filename']:
        node = bld.srcnode.make_node(kw['compile_filename'])
        node.write(kw['code'])

    bld.logger = self.logger
    bld.all_envs.update(self.all_envs)  # not really necessary
    bld.env = kw['env']

    o = bld(features=kw['features'],
            source=kw['compile_filename'],
            target='testprog')

    for k, v in kw.items():
        setattr(o, k, v)

    self.to_log("==>\n%s\n<==" % kw['code'])

    # compile the program
    bld.targets = '*'

    ret = -1
    try:
        try:
            bld.compile()
        except Errors.WafError:
            ret = 'Test does not build: %s' % Utils.ex_stack()
            self.fatal(ret)
        else:
            ret = getattr(bld, 'retval', 0)
    finally:
        # cache the results each time
        proj = ConfigSet.ConfigSet()
        proj['cache_run_c_code'] = ret
        proj.store(os.path.join(dir, 'cache_run_c_code'))

    return ret
Beispiel #9
0
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