Exemplo n.º 1
0
def check_jni_headers(conf):
    if not conf.env.CC_NAME and not conf.env.CXX_NAME:
        conf.fatal('load a compiler first (gcc, g++, ..)')
    if not conf.env.JAVA_HOME:
        conf.fatal('set JAVA_HOME in the system environment')
    javaHome = conf.env['JAVA_HOME'][0]
    b = Build.BuildContext()
    b.load_dirs(conf.srcdir, conf.blddir)
    dir = b.root.find_dir(conf.env.JAVA_HOME[0] + '/include')
    f = dir.ant_glob('**/(jni|jni_md).h', flat=False)
    incDirs = [x.parent.abspath() for x in f]
    dir = b.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob('**/*jvm.(so|dll)', flat=False)
    libDirs = [x.parent.abspath() for x in f] or [javaHome]
    for i, d in enumerate(libDirs):
        if conf.check(header_name='jni.h',
                      define_name='HAVE_JNI_H',
                      lib='jvm',
                      libpath=d,
                      includes=incDirs,
                      uselib_store='JAVA',
                      uselib='JAVA'):
            break
    else:
        conf.fatal('could not find lib jvm in %r (see config.log)' % libDirs)
Exemplo n.º 2
0
	def setUp(self):
		'''setup the foundations needed for tests'''
		self._bld = Build.BuildContext()
		# define & create temporary testing directories - 
		# needed to make sure it will run in same manner always 
		self._test_dir_root = tempfile.mkdtemp("", ".waf-testing_")
		self._wscript_file_path = os.path.join(self._test_dir_root, WSCRIPT_FILE)
		os.chdir(self._test_dir_root)
Exemplo n.º 3
0
 def make_bld(self):
     Options.commands['configure'] = False
     env = Environment.Environment()
     bld = Build.bld = Build.BuildContext()
     bld.set_env('default', env)
     blddir = os.path.join(self._test_dir_root, 'b')
     bld.load_dirs(self._test_dir_root, blddir)
     return bld
Exemplo n.º 4
0
    def test_white_no_sources_specified(self):
        # white-box test: no sources were specified

        # add apply_verif to taskgen
        import Tools.ccroot

        Options.commands['configure'] = False
        env = Environment.Environment()
        bld = Build.bld = Build.BuildContext()
        bld.set_env('default', env)
        blddir = os.path.join(self._test_dir_root, 'b')
        bld.load_dirs(self._test_dir_root, blddir)

        obj = TaskGen.task_gen(bld=bld)
        # TODO: make sure it works with apply_core too
        self.failUnlessRaises(Utils.WafError, obj.apply_verif)
Exemplo n.º 5
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)

    dest = open(os.path.join(subdir, 'liblc1.c'), 'w')
    dest.write(
        '#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n'
    )
    dest.close()

    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='cc 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
Exemplo n.º 6
0
    def test_incorrect_version(self):
        # white-box test: configured with old version
        Options.commands['configure'] = False

        bld = Build.BuildContext()
        bld.blddir = os.path.join(self._test_dir_root, 'b')

        # this will create the cachedir...
        self.failUnlessRaises(Utils.WafError, bld.load_dirs, bld.blddir,
                              bld.blddir)
        os.makedirs(bld.cachedir)

        # create build cache file with OLD version
        cachefile = os.path.join(bld.cachedir, 'build.config.py')
        file = open(cachefile, 'w')
        file.writelines("version = 0.0")
        file.close()

        self.failUnlessRaises(Utils.WafError, bld.load)
Exemplo n.º 7
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)

    dest = open(os.path.join(subdir, 'lib1.c'), 'w')
    dest.write('int lib_func(void) { return 42; }\n')
    dest.close()

    dest = open(os.path.join(dir, 'main.c'), 'w')
    dest.write('int main(void) {return !(lib_func() == 42);}\n')
    dest.close()

    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())
        dest = open(os.path.join(dir,'vscript'), 'w')
        dest.write('TEST_1.0A2 { global: *; };\n')
        dest.close()

    bld(features='cc cshlib',
        source='libdir/lib1.c',
        target='libdir/lib1',
        ldflags=ldflags,
        name='lib1')

    o = bld(features='cc 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.pproc.Popen([lastprog] + args, stdout=Utils.pproc.PIPE, stderr=Utils.pproc.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
Exemplo n.º 8
0
def run_c_code(self,*k,**kw):
	test_f_name=kw['compile_filename']
	k=0
	while k<10000:
		dir=os.path.join(self.blddir,'.conf_check_%d'%k)
		try:
			shutil.rmtree(dir)
		except OSError:
			pass
		try:
			os.stat(dir)
		except OSError:
			break
		k+=1
	try:
		os.makedirs(dir)
	except:
		self.fatal('cannot create a configuration test folder %r'%dir)
	try:
		os.stat(dir)
	except:
		self.fatal('cannot use the configuration test folder %r'%dir)
	bdir=os.path.join(dir,'testbuild')
	if not os.path.exists(bdir):
		os.makedirs(bdir)
	env=kw['env']
	dest=open(os.path.join(dir,test_f_name),'w')
	dest.write(kw['code'])
	dest.close()
	back=os.path.abspath('.')
	bld=Build.BuildContext()
	bld.log=self.log
	bld.all_envs.update(self.all_envs)
	bld.all_envs['default']=env
	bld.lst_variants=bld.all_envs.keys()
	bld.load_dirs(dir,bdir)
	os.chdir(dir)
	bld.rescan(bld.srcnode)
	o=bld(features=[kw['compile_mode'],kw['type']],source=test_f_name,target='testprog')
	for k,v in kw.iteritems():
		setattr(o,k,v)
	self.log.write("==>\n%s\n<==\n"%kw['code'])
	try:
		bld.compile()
	except Utils.WafError:
		ret=Utils.ex_stack()
	else:
		ret=0
	os.chdir(back)
	if ret:
		self.log.write('command returned %r'%ret)
		self.fatal(str(ret))
	if kw['execute']:
		lastprog=o.link_task.outputs[0].abspath(env)
	if kw['execute']:
		args=Utils.to_list(kw.get('exec_args',[]))
		try:
			data=Utils.cmd_output([lastprog]+args).strip()
		except ValueError,e:
			self.fatal(Utils.ex_stack())
		ret=data
Exemplo n.º 9
0
def run_c_code(self, *k, **kw):
    test_f_name = kw['compile_filename']

    k = 0
    while k < 10000:
        # make certain to use a fresh folder - necessary for win32
        dir = os.path.join(self.blddir, '.conf_check_%d' % k)

        # if the folder already exists, remove it
        try:
            shutil.rmtree(dir)
        except OSError:
            pass

        try:
            os.stat(dir)
        except OSError:
            break

        k += 1

    try:
        os.makedirs(dir)
    except:
        self.fatal('cannot create a configuration test folder %r' % dir)

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

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

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

    env = kw['env']

    dest = open(os.path.join(dir, test_f_name), 'w')
    dest.write(kw['code'])
    dest.close()

    back = os.path.abspath('.')

    bld = Build.BuildContext()
    bld.log = self.log
    bld.all_envs.update(self.all_envs)
    bld.all_envs['default'] = env
    bld.lst_variants = bld.all_envs.keys()
    bld.load_dirs(dir, bdir)

    os.chdir(dir)

    bld.rescan(bld.srcnode)

    if not 'features' in kw:
        # conf.check(features='cc cprogram pyext', ...)
        kw['features'] = [kw['compile_mode'], kw['type']]  # "cprogram cc"

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

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

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

    # compile the program
    try:
        bld.compile()
    except Utils.WafError:
        ret = Utils.ex_stack()
    else:
        ret = 0

    # chdir before returning
    os.chdir(back)

    if ret:
        self.log.write('command returned %r' % ret)
        self.fatal(str(ret))

    # if we need to run the program, try to get its result
    # keep the name of the program to execute
    if kw['execute']:
        lastprog = o.link_task.outputs[0].abspath(env)

        args = Utils.to_list(kw.get('exec_args', []))
        proc = Utils.pproc.Popen([lastprog] + args,
                                 stdout=Utils.pproc.PIPE,
                                 stderr=Utils.pproc.PIPE)
        (out, err) = proc.communicate()
        w = self.log.write
        w(str(out))
        w('\n')
        w(str(err))
        w('\n')
        w('returncode %r' % proc.returncode)
        w('\n')
        if proc.returncode:
            self.fatal(Utils.ex_stack())
        ret = out

    return ret
Exemplo n.º 10
0
 def test_white_build_fails_blddir_is_srcdir(self):
     # white-box test: build fail if blddir == srcdir
     bld = Build.BuildContext()
     blddir = os.path.join(self._test_dir_root, 'blddir')
     self.failUnlessRaises(Utils.WafError, bld.load_dirs, blddir, blddir)