Beispiel #1
0
    def exec_command(self, cmd, **kw):
        Logs.debug('runner: %r', cmd)
        if getattr(Options.options, 'dump_test_scripts', False):
            script_code = SCRIPT_TEMPLATE % {
                'python': sys.executable,
                'env': self.get_test_env(),
                'cwd': self.get_cwd().abspath(),
                'cmd': cmd
            }
            script_file = self.inputs[0].abspath() + '_run.py'
            Utils.writef(script_file, script_code)
            os.chmod(script_file, Utils.O755)
            if Logs.verbose > 1:
                Logs.info('Test debug file written as %r' % script_file)

        proc = Utils.subprocess.Popen(cmd,
                                      cwd=self.get_cwd().abspath(),
                                      env=self.get_test_env(),
                                      stderr=Utils.subprocess.PIPE,
                                      stdout=Utils.subprocess.PIPE,
                                      shell=isinstance(cmd, str))
        (stdout, stderr) = proc.communicate()
        self.waf_unit_test_results = tup = (self.inputs[0].abspath(),
                                            proc.returncode, stdout, stderr)
        testlock.acquire()
        try:
            return self.generator.add_test_results(tup)
        finally:
            testlock.release()
Beispiel #2
0
def check_java_class(self, classname, with_classpath=None):
	"""
	Checks if the specified java class exists

	:param classname: class to check, like java.util.HashMap
	:type classname: string
	:param with_classpath: additional classpath to give
	:type with_classpath: string
	"""
	javatestdir = '.waf-javatest'

	classpath = javatestdir
	if self.env.CLASSPATH:
		classpath += os.pathsep + self.env.CLASSPATH
	if isinstance(with_classpath, str):
		classpath += os.pathsep + with_classpath

	shutil.rmtree(javatestdir, True)
	os.mkdir(javatestdir)

	Utils.writef(os.path.join(javatestdir, 'Test.java'), class_check_source)

	# Compile the source
	self.exec_command(self.env.JAVAC + [os.path.join(javatestdir, 'Test.java')], shell=False)

	# Try to run the app
	cmd = self.env.JAVA + ['-cp', classpath, 'Test', classname]
	self.to_log("%s\n" % str(cmd))
	found = self.exec_command(cmd, shell=False)

	self.msg('Checking for java class %s' % classname, not found)

	shutil.rmtree(javatestdir, True)

	return found
Beispiel #3
0
	def store(self):
		data = {}
		for x in Build.SAVED_ATTRS:
			data[x] = getattr(self, x)
		db = os.path.join(self.variant_dir, Context.DBFILE + self.store_key)

		with waflib.Node.pickle_lock:
			waflib.Node.Nod3 = self.node_class
			try:
				x = Build.cPickle.dumps(data, Build.PROTOCOL)
			except Build.cPickle.PicklingError:
				root = data['root']
				for node_deps in data['node_deps'].values():
					for idx, node in enumerate(node_deps):
						# there may be more cross-context Node objects to fix,
						# but this should be the main source
						node_deps[idx] = root.find_node(node.abspath())
				x = Build.cPickle.dumps(data, Build.PROTOCOL)

		Logs.debug('rev_use: storing %s', db)
		Utils.writef(db + '.tmp', x, m='wb')
		try:
			st = os.stat(db)
			os.remove(db)
			if not Utils.is_win32:
				os.chown(db + '.tmp', st.st_uid, st.st_gid)
		except (AttributeError, OSError):
			pass
		os.rename(db + '.tmp', db)
Beispiel #4
0
def check_java_class(self, classname, with_classpath=None):
	"""
	Checks if the specified java class exists

	:param classname: class to check, like java.util.HashMap
	:type classname: string
	:param with_classpath: additional classpath to give
	:type with_classpath: string
	"""
	javatestdir = '.waf-javatest'

	classpath = javatestdir
	if self.env.CLASSPATH:
		classpath += os.pathsep + self.env.CLASSPATH
	if isinstance(with_classpath, str):
		classpath += os.pathsep + with_classpath

	shutil.rmtree(javatestdir, True)
	os.mkdir(javatestdir)

	Utils.writef(os.path.join(javatestdir, 'Test.java'), class_check_source)

	# Compile the source
	self.exec_command(self.env.JAVAC + [os.path.join(javatestdir, 'Test.java')], shell=False)

	# Try to run the app
	cmd = self.env.JAVA + ['-cp', classpath, 'Test', classname]
	self.to_log("%s\n" % str(cmd))
	found = self.exec_command(cmd, shell=False)

	self.msg('Checking for java class %s' % classname, not found)

	shutil.rmtree(javatestdir, True)

	return found
    def store(self):
        """
		Store data for next runs, set the attributes listed in :py:const:`waflib.Build.SAVED_ATTRS`. Uses a temporary
		file to avoid problems on ctrl+c.
		"""
        data = {}
        for x in SAVED_ATTRS:
            data[x] = getattr(self, x)
        db = os.path.join(self.variant_dir, Context.DBFILE)

        try:
            Node.pickle_lock.acquire()
            Node.Nod3 = self.node_class
            x = cPickle.dumps(data, PROTOCOL)
        finally:
            Node.pickle_lock.release()

        Utils.writef(db + '.tmp', x, m='wb')

        try:
            st = os.stat(db)
            os.remove(db)
            if not Utils.is_win32:  # win32 has no chown but we're paranoid
                os.chown(db + '.tmp', st.st_uid, st.st_gid)
        except (AttributeError, OSError):
            pass

        # do not use shutil.move (copy is not thread-safe)
        os.rename(db + '.tmp', db)
Beispiel #6
0
	def store(self, filename):
		"""
		Write the :py:class:`ConfigSet` data into a file. See :py:meth:`ConfigSet.load` for reading such files.

		:param filename: file to use
		:type filename: string
		"""
		try:
			os.makedirs(os.path.split(filename)[0])
		except OSError:
			pass

		buf = []
		merged_table = self.get_merged_dict()
		keys = list(merged_table.keys())
		keys.sort()

		try:
			fun = ascii
		except NameError:
			fun = repr

		for k in keys:
			if k != 'undo_stack':
				buf.append('%s = %s\n' % (k, fun(merged_table[k])))
		Utils.writef(filename, ''.join(buf))
Beispiel #7
0
    def store(self, filename):
        """
		Write the :py:class:`ConfigSet` data into a file. See :py:meth:`ConfigSet.load` for reading such files.

		:param filename: file to use
		:type filename: string
		"""
        try:
            os.makedirs(os.path.split(filename)[0])
        except OSError:
            pass

        buf = []
        merged_table = self.get_merged_dict()
        keys = list(merged_table.keys())
        keys.sort()

        try:
            fun = ascii
        except NameError:
            fun = repr

        for k in keys:
            if k != 'undo_stack':
                buf.append('%s = %s\n' % (k, fun(merged_table[k])))
        Utils.writef(filename, ''.join(buf))
Beispiel #8
0
	def store(self):
		"""
		Store data for next runs, set the attributes listed in :py:const:`waflib.Build.SAVED_ATTRS`. Uses a temporary
		file to avoid problems on ctrl+c.
		"""
		data = {}
		for x in SAVED_ATTRS:
			data[x] = getattr(self, x)
		db = os.path.join(self.variant_dir, Context.DBFILE)

		try:
			Node.pickle_lock.acquire()
			Node.Nod3 = self.node_class
			x = cPickle.dumps(data, PROTOCOL)
		finally:
			Node.pickle_lock.release()

		Utils.writef(db + '.tmp', x, m='wb')

		try:
			st = os.stat(db)
			os.remove(db)
			if not Utils.is_win32: # win32 has no chown but we're paranoid
				os.chown(db + '.tmp', st.st_uid, st.st_gid)
		except (AttributeError, OSError):
			pass

		# do not use shutil.move (copy is not thread-safe)
		os.rename(db + '.tmp', db)
Beispiel #9
0
 def store_pickle(self, filename):
     dirname, basename = os.path.split(filename)
     if basename == Options.lockfile:
         return store_orig(self, filename)
     Utils.check_dir(dirname)
     table = sorted(kv for kv in self.get_merged_dict().iteritems()
                    if kv[0] != 'undo_stack')
     Utils.writef(filename, pickle.dumps(table, 2), m='wb')
Beispiel #10
0
 def store_pickle(self, filename):
     dirname, basename = os.path.split(filename)
     if basename == Options.lockfile:
         return store_orig(self, filename)
     Utils.check_dir(dirname)
     table = sorted(
             kv
             for kv in self.get_merged_dict().iteritems()
                 if kv[0] != 'undo_stack'
             )
     Utils.writef(filename, pickle.dumps(table, 2), m='wb')
Beispiel #11
0
    def write_to_db(db, contents):
        Utils.writef(db + '.tmp', contents, m='wb')

        try:
            st = os.stat(db)
            os.remove(db)
            if not Utils.is_win32:  # win32 has no chown but we're paranoid
                os.chown(db + '.tmp', st.st_uid, st.st_gid)
        except (AttributeError, OSError):
            pass

        # do not use shutil.move (copy is not thread-safe)
        os.rename(db + '.tmp', db)
Beispiel #12
0
 def store(self, filename):
     try:
         os.makedirs(os.path.split(filename)[0])
     except OSError:
         pass
     buf = []
     merged_table = self.get_merged_dict()
     keys = list(merged_table.keys())
     keys.sort()
     for k in keys:
         if k != 'undo_stack':
             buf.append('%s = %r\n' % (k, merged_table[k]))
     Utils.writef(filename, ''.join(buf))
Beispiel #13
0
    def write(self, data, flags='w', encoding='ISO8859-1'):
        """
		Write some text to the physical file represented by this node::

			def build(bld):
				bld.path.make_node('foo.txt').write('Hello, world!')

		:type  data: string
		:param data: data to write
		:type  flags: string
		:param flags: Write mode
		"""
        Utils.writef(self.abspath(), data, flags, encoding)
	def store(self,filename):
		try:
			os.makedirs(os.path.split(filename)[0])
		except OSError:
			pass
		buf=[]
		merged_table=self.get_merged_dict()
		keys=list(merged_table.keys())
		keys.sort()
		for k in keys:
			if k!='undo_stack':
				buf.append('%s = %r\n'%(k,merged_table[k]))
		Utils.writef(filename,''.join(buf))
Beispiel #15
0
	def write(self, data, flags='w', encoding='ISO8859-1'):
		"""
		Write some text to the physical file represented by this node::

			def build(bld):
				bld.path.make_node('foo.txt').write('Hello, world!')

		:type  data: string
		:param data: data to write
		:type  flags: string
		:param flags: Write mode
		"""
		Utils.writef(self.abspath(), data, flags, encoding)
Beispiel #16
0
def CHECK_PERL_MANPAGE(conf, msg=None, section=None):
    '''work out what extension perl uses for manpages'''

    if msg is None:
        if section:
            msg = "perl man%s extension" % section
        else:
            msg = "perl manpage generation"

    conf.start_msg(msg)

    dir = find_config_dir(conf)

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

    Utils.writef(
        os.path.join(bdir, 'Makefile.PL'), """
use ExtUtils::MakeMaker;
WriteMakefile(
    'NAME'    => 'WafTest',
    'EXE_FILES' => [ 'WafTest' ]
);
""")
    back = os.path.abspath('.')
    os.chdir(bdir)
    proc = Utils.subprocess.Popen(['perl', 'Makefile.PL'],
                                  stdout=Utils.subprocess.PIPE,
                                  stderr=Utils.subprocess.PIPE)
    (out, err) = proc.communicate()
    os.chdir(back)

    ret = (proc.returncode == 0)
    if not ret:
        conf.end_msg('not found', color='YELLOW')
        return

    if section:
        man = Utils.readf(os.path.join(bdir, 'Makefile'))
        m = re.search('MAN%sEXT\s+=\s+(\w+)' % section, man)
        if not m:
            conf.end_msg('not found', color='YELLOW')
            return
        ext = m.group(1)
        conf.end_msg(ext)
        return ext

    conf.end_msg('ok')
    return True
Beispiel #17
0
	def write(self, data, flags='w', encoding='ISO8859-1'):
		"""
		Writes data to the file represented by this node, see :py:func:`waflib.Utils.writef`::

			def build(bld):
				bld.path.make_node('foo.txt').write('Hello, world!')

		:param data: data to write
		:type  data: string
		:param flags: Write mode
		:type  flags: string
		:param encoding: encoding value for Python3
		:type encoding: string
		"""
		Utils.writef(self.abspath(), data, flags, encoding)
Beispiel #18
0
Datei: Node.py Projekt: ralic/waf
	def write(self, data, flags='w', encoding='ISO8859-1'):
		"""
		Writes data to the file represented by this node, see :py:func:`waflib.Utils.writef`::

			def build(bld):
				bld.path.make_node('foo.txt').write('Hello, world!')

		:param data: data to write
		:type  data: string
		:param flags: Write mode
		:type  flags: string
		:param encoding: encoding value for Python3
		:type encoding: string
		"""
		Utils.writef(self.abspath(), data, flags, encoding)
Beispiel #19
0
def check_java_class(self,classname,with_classpath=None):
	javatestdir='.waf-javatest'
	classpath=javatestdir
	if self.env['CLASSPATH']:
		classpath+=os.pathsep+self.env['CLASSPATH']
	if isinstance(with_classpath,str):
		classpath+=os.pathsep+with_classpath
	shutil.rmtree(javatestdir,True)
	os.mkdir(javatestdir)
	Utils.writef(os.path.join(javatestdir,'Test.java'),class_check_source)
	self.exec_command(self.env['JAVAC']+[os.path.join(javatestdir,'Test.java')],shell=False)
	cmd=self.env['JAVA']+['-cp',classpath,'Test',classname]
	self.to_log("%s\n"%str(cmd))
	found=self.exec_command(cmd,shell=False)
	self.msg('Checking for java class %s'%classname,not found)
	shutil.rmtree(javatestdir,True)
	return found
Beispiel #20
0
def check_java_class(self, classname, with_classpath=None):
    javatestdir = ".waf-javatest"
    classpath = javatestdir
    if self.env["CLASSPATH"]:
        classpath += os.pathsep + self.env["CLASSPATH"]
    if isinstance(with_classpath, str):
        classpath += os.pathsep + with_classpath
    shutil.rmtree(javatestdir, True)
    os.mkdir(javatestdir)
    Utils.writef(os.path.join(javatestdir, "Test.java"), class_check_source)
    self.exec_command(self.env["JAVAC"] + [os.path.join(javatestdir, "Test.java")], shell=False)
    cmd = self.env["JAVA"] + ["-cp", classpath, "Test", classname]
    self.to_log("%s\n" % str(cmd))
    found = self.exec_command(cmd, shell=False)
    self.msg("Checking for java class %s" % classname, not found)
    shutil.rmtree(javatestdir, True)
    return found
Beispiel #21
0
 def store(self, filename):
     try:
         os.makedirs(os.path.split(filename)[0])
     except OSError:
         pass
     buf = []
     merged_table = self.get_merged_dict()
     keys = list(merged_table.keys())
     keys.sort()
     try:
         fun = ascii
     except NameError:
         fun = repr
     for k in keys:
         if k != "undo_stack":
             buf.append("%s = %s\n" % (k, fun(merged_table[k])))
     Utils.writef(filename, "".join(buf))
Beispiel #22
0
def check_java_class(self,classname,with_classpath=None):
	javatestdir='.waf-javatest'
	classpath=javatestdir
	if self.env['CLASSPATH']:
		classpath+=os.pathsep+self.env['CLASSPATH']
	if isinstance(with_classpath,str):
		classpath+=os.pathsep+with_classpath
	shutil.rmtree(javatestdir,True)
	os.mkdir(javatestdir)
	Utils.writef(os.path.join(javatestdir,'Test.java'),class_check_source)
	self.exec_command(self.env['JAVAC']+[os.path.join(javatestdir,'Test.java')],shell=False)
	cmd=self.env['JAVA']+['-cp',classpath,'Test',classname]
	self.to_log("%s\n"%str(cmd))
	found=self.exec_command(cmd,shell=False)
	self.msg('Checking for java class %s'%classname,not found)
	shutil.rmtree(javatestdir,True)
	return found
Beispiel #23
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 #24
0
 def store(self):
     data = {}
     for x in SAVED_ATTRS:
         data[x] = getattr(self, x)
     db = os.path.join(self.variant_dir, Context.DBFILE)
     try:
         waflib.Node.pickle_lock.acquire()
         waflib.Node.Nod3 = self.node_class
         x = cPickle.dumps(data, -1)
     finally:
         waflib.Node.pickle_lock.release()
     Utils.writef(db + '.tmp', x, m='wb')
     try:
         st = os.stat(db)
         os.remove(db)
         if not Utils.is_win32:
             os.chown(db + '.tmp', st.st_uid, st.st_gid)
     except (AttributeError, OSError):
         pass
     os.rename(db + '.tmp', db)
Beispiel #25
0
	def store(self):
		data={}
		for x in SAVED_ATTRS:
			data[x]=getattr(self,x)
		db=os.path.join(self.variant_dir,Context.DBFILE)
		try:
			Node.pickle_lock.acquire()
			Node.Nod3=self.node_class
			x=cPickle.dumps(data,PROTOCOL)
		finally:
			Node.pickle_lock.release()
		Utils.writef(db+'.tmp',x,m='wb')
		try:
			st=os.stat(db)
			os.remove(db)
			if not Utils.is_win32:
				os.chown(db+'.tmp',st.st_uid,st.st_gid)
		except(AttributeError,OSError):
			pass
		os.rename(db+'.tmp',db)
Beispiel #26
0
	def setup_private_ssh_key(self):
		"""
		When WAF_SSH_KEY points to a private key, a .ssh directory will be created in the build directory
		Make sure that the ssh key does not prompt for a password
		"""
		key = os.environ.get('WAF_SSH_KEY', '')
		if not key:
			return
		if not os.path.isfile(key):
			self.fatal('Key in WAF_SSH_KEY must point to a valid file')
		self.ssh_dir = os.path.join(self.path.abspath(), 'build', '.ssh')
		self.ssh_hosts = os.path.join(self.ssh_dir, 'known_hosts')
		self.ssh_key = os.path.join(self.ssh_dir, os.path.basename(key))
		self.ssh_config = os.path.join(self.ssh_dir, 'config')
		for x in self.ssh_hosts, self.ssh_key, self.ssh_config:
			if not os.path.isfile(x):
				if not os.path.isdir(self.ssh_dir):
					os.makedirs(self.ssh_dir)
				Utils.writef(self.ssh_key, Utils.readf(key), 'wb')
				os.chmod(self.ssh_key, 448)

				Utils.writef(self.ssh_hosts, '\n'.join(self.get_ssh_hosts()))
				os.chmod(self.ssh_key, 448)

				Utils.writef(self.ssh_config, 'UserKnownHostsFile %s' % self.ssh_hosts, 'wb')
				os.chmod(self.ssh_config, 448)
		self.env.SSH_OPTS = ['-F', self.ssh_config, '-i', self.ssh_key]
		self.env.append_value('RSYNC_SEND_OPTS', '--exclude=build/.ssh')
    def setup_private_ssh_key(self):
        """
        When WAF_SSH_KEY points to a private key, a .ssh directory will be created in the build directory
        Make sure that the ssh key does not prompt for a password
        """
        key = os.environ.get("WAF_SSH_KEY", "")
        if not key:
            return
        if not os.path.isfile(key):
            self.fatal("Key in WAF_SSH_KEY must point to a valid file")
        self.ssh_dir = os.path.join(self.path.abspath(), "build", ".ssh")
        self.ssh_hosts = os.path.join(self.ssh_dir, "known_hosts")
        self.ssh_key = os.path.join(self.ssh_dir, os.path.basename(key))
        self.ssh_config = os.path.join(self.ssh_dir, "config")
        for x in self.ssh_hosts, self.ssh_key, self.ssh_config:
            if not os.path.isfile(x):
                if not os.path.isdir(self.ssh_dir):
                    os.makedirs(self.ssh_dir)
                Utils.writef(self.ssh_key, Utils.readf(key), "wb")
                os.chmod(self.ssh_key, 448)

                Utils.writef(self.ssh_hosts, "\n".join(self.get_ssh_hosts()))
                os.chmod(self.ssh_key, 448)

                Utils.writef(self.ssh_config,
                             "UserKnownHostsFile %s" % self.ssh_hosts, "wb")
                os.chmod(self.ssh_config, 448)
        self.env.SSH_OPTS = ["-F", self.ssh_config, "-i", self.ssh_key]
        self.env.append_value("RSYNC_SEND_OPTS", "--exclude=build/.ssh")
Beispiel #28
0
    def setup_private_ssh_key(self):
        """
		When WAF_SSH_KEY points to a private key, a .ssh directory will be created in the build directory
		Make sure that the ssh key does not prompt for a password
		"""
        key = os.environ.get('WAF_SSH_KEY', '')
        if not key:
            return
        if not os.path.isfile(key):
            self.fatal('Key in WAF_SSH_KEY must point to a valid file')
        self.ssh_dir = os.path.join(self.path.abspath(), 'build', '.ssh')
        self.ssh_hosts = os.path.join(self.ssh_dir, 'known_hosts')
        self.ssh_key = os.path.join(self.ssh_dir, os.path.basename(key))
        self.ssh_config = os.path.join(self.ssh_dir, 'config')
        for x in self.ssh_hosts, self.ssh_key, self.ssh_config:
            if not os.path.isfile(x):
                if not os.path.isdir(self.ssh_dir):
                    os.makedirs(self.ssh_dir)
                Utils.writef(self.ssh_key, Utils.readf(key), 'wb')
                os.chmod(self.ssh_key, 448)

                Utils.writef(self.ssh_hosts, '\n'.join(self.get_ssh_hosts()))
                os.chmod(self.ssh_key, 448)

                Utils.writef(self.ssh_config,
                             'UserKnownHostsFile %s' % self.ssh_hosts, 'wb')
                os.chmod(self.ssh_config, 448)
        self.env.SSH_OPTS = ['-F', self.ssh_config, '-i', self.ssh_key]
        self.env.append_value('RSYNC_SEND_OPTS', '--exclude=build/.ssh')
Beispiel #29
0
    def store(self):
        data = {}
        for x in Build.SAVED_ATTRS:
            data[x] = getattr(self, x)
        db = os.path.join(self.variant_dir, Context.DBFILE + self.store_key)

        try:
            waflib.Node.pickle_lock.acquire()
            waflib.Node.Nod3 = self.node_class
            x = Build.cPickle.dumps(data, Build.PROTOCOL)
        finally:
            waflib.Node.pickle_lock.release()

        Logs.debug("rev_use: storing %s", db)
        Utils.writef(db + ".tmp", x, m="wb")
        try:
            st = os.stat(db)
            os.remove(db)
            if not Utils.is_win32:
                os.chown(db + ".tmp", st.st_uid, st.st_gid)
        except (AttributeError, OSError):
            pass
        os.rename(db + ".tmp", db)
Beispiel #30
0
	def store(self):
		data = {}
		for x in Build.SAVED_ATTRS:
			data[x] = getattr(self, x)
		db = os.path.join(self.variant_dir, Context.DBFILE + self.store_key)

		try:
			waflib.Node.pickle_lock.acquire()
			waflib.Node.Nod3 = self.node_class
			x = Build.cPickle.dumps(data, Build.PROTOCOL)
		finally:
			waflib.Node.pickle_lock.release()

		Logs.debug('rev_use: storing %s', db)
		Utils.writef(db + '.tmp', x, m='wb')
		try:
			st = os.stat(db)
			os.remove(db)
			if not Utils.is_win32:
				os.chown(db + '.tmp', st.st_uid, st.st_gid)
		except (AttributeError, OSError):
			pass
		os.rename(db + '.tmp', db)
Beispiel #31
0
	def exec_command(self, cmd, **kw):
		Logs.debug('runner: %r', cmd)
		if getattr(Options.options, 'dump_test_scripts', False):
			script_code = SCRIPT_TEMPLATE % {
				'python': sys.executable,
				'env': self.get_test_env(),
				'cwd': self.get_cwd().abspath(),
				'cmd': cmd
			}
			script_file = self.inputs[0].abspath() + '_run.py'
			Utils.writef(script_file, script_code)
			os.chmod(script_file, Utils.O755)
			if Logs.verbose > 1:
				Logs.info('Test debug file written as %r' % script_file)

		proc = Utils.subprocess.Popen(cmd, cwd=self.get_cwd().abspath(), env=self.get_test_env(),
			stderr=Utils.subprocess.PIPE, stdout=Utils.subprocess.PIPE, shell=isinstance(cmd,str))
		(stdout, stderr) = proc.communicate()
		self.waf_unit_test_results = tup = (self.inputs[0].abspath(), proc.returncode, stdout, stderr)
		testlock.acquire()
		try:
			return self.generator.add_test_results(tup)
		finally:
			testlock.release()
Beispiel #32
0
 def write(self, data, flags='w'):
     Utils.writef(self.abspath(), data, flags)
Beispiel #33
0
 def write(self, data, flags='w', encoding='ISO8859-1'):
     Utils.writef(self.abspath(), data, flags, encoding)
Beispiel #34
0
    def store_tstamps(self):
        # Called after a build is finished
        # For each task generator, record all files involved in task objects
        # optimization: done only if there was something built
        do_store = False
        try:
            f_deps = self.f_deps
        except AttributeError:
            f_deps = self.f_deps = {}
            self.f_tstamps = {}

        allfiles = set()
        for g in self.groups:
            for tg in g:
                try:
                    staleness = tg.staleness
                except AttributeError:
                    staleness = DIRTY

                if staleness != DIRTY:
                    # DONE case: there was nothing built
                    # NEEDED case: the tg was brought in because of 'use' propagation
                    # but nothing really changed for them, there may be incomplete
                    # tasks (object files) and in this case it is best to let the next build
                    # figure out if an input/output file changed
                    continue

                do_cache = False
                for tsk in tg.tasks:
                    if tsk.hasrun == Task.SUCCESS:
                        do_cache = True
                        pass
                    elif tsk.hasrun == Task.SKIPPED:
                        pass
                    else:
                        # one failed task, clear the cache for this tg
                        try:
                            del f_deps[(tg.path.abspath(), tg.idx)]
                        except KeyError:
                            pass
                        else:
                            # just store the new state because there is a change
                            do_store = True

                        # skip the rest because there is no valid cache possible
                        break
                else:
                    if not do_cache:
                        # all skipped, but is there anything in cache?
                        try:
                            f_deps[(tg.path.abspath(), tg.idx)]
                        except KeyError:
                            # probably cleared because a wscript file changed
                            # store it
                            do_cache = True

                    if do_cache:

                        # there was a rebuild, store the data structure too
                        tg.bld.store()

                        # all tasks skipped but no cache
                        # or a successful task build
                        do_store = True
                        st = set()
                        for tsk in tg.tasks:
                            st.update(tsk.inputs)
                            st.update(self.node_deps.get(tsk.uid(), []))

                        # TODO do last/when loading the tgs?
                        lst = []
                        for k in ('wscript', 'wscript_build'):
                            n = tg.path.find_node(k)
                            if n:
                                n.get_bld_sig()
                                lst.append(n.abspath())

                        lst.extend(sorted(x.abspath() for x in st))
                        allfiles.update(lst)
                        f_deps[(tg.path.abspath(), tg.idx)] = lst

        for x in allfiles:
            # f_tstamps has everything, while md5_tstamp can be relatively empty on partial builds
            self.f_tstamps[x] = self.hashes_md5_tstamp[x][0]

        if do_store:
            dbfn = os.path.join(self.variant_dir, TSTAMP_DB)
            Logs.debug('rev_use: storing %s', dbfn)
            dbfn_tmp = dbfn + '.tmp'
            x = Build.cPickle.dumps([self.f_tstamps, f_deps], Build.PROTOCOL)
            Utils.writef(dbfn_tmp, x, m='wb')
            os.rename(dbfn_tmp, dbfn)
            Logs.debug('rev_use: stored %s', dbfn)
Beispiel #35
0
	def write(self,data,flags='w'):
		Utils.writef(self.abspath(),data,flags)
	def write(self,data,flags='w',encoding='ISO8859-1'):
		Utils.writef(self.abspath(),data,flags,encoding)
Beispiel #37
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
Beispiel #38
0
	def store_tstamps(self):
		# Called after a build is finished
		# For each task generator, record all files involved in task objects
		# optimization: done only if there was something built
		do_store = False
		try:
			f_deps = self.f_deps
		except AttributeError:
			f_deps = self.f_deps = {}
			self.f_tstamps = {}

		allfiles = set()
		for g in self.groups:
			for tg in g:
				try:
					staleness = tg.staleness
				except AttributeError:
					staleness = DIRTY

				if staleness != DIRTY:
					# DONE case: there was nothing built
					# NEEDED case: the tg was brought in because of 'use' propagation
					# but nothing really changed for them, there may be incomplete
					# tasks (object files) and in this case it is best to let the next build
					# figure out if an input/output file changed
					continue

				do_cache = False
				for tsk in tg.tasks:
					if tsk.hasrun == Task.SUCCESS:
						do_cache = True
						pass
					elif tsk.hasrun == Task.SKIPPED:
						pass
					else:
						# one failed task, clear the cache for this tg
						try:
							del f_deps[(tg.path.abspath(), tg.idx)]
						except KeyError:
							pass
						else:
							# just store the new state because there is a change
							do_store = True

						# skip the rest because there is no valid cache possible
						break
				else:
					if not do_cache:
						# all skipped, but is there anything in cache?
						try:
							f_deps[(tg.path.abspath(), tg.idx)]
						except KeyError:
							# probably cleared because a wscript file changed
							# store it
							do_cache = True

					if do_cache:

						# there was a rebuild, store the data structure too
						tg.bld.store()

						# all tasks skipped but no cache
						# or a successful task build
						do_store = True
						st = set()
						for tsk in tg.tasks:
							st.update(tsk.inputs)
							st.update(self.node_deps.get(tsk.uid(), []))

						# TODO do last/when loading the tgs?
						lst = []
						for k in ('wscript', 'wscript_build'):
							n = tg.path.find_node(k)
							if n:
								n.get_bld_sig()
								lst.append(n.abspath())

						lst.extend(sorted(x.abspath() for x in st))
						allfiles.update(lst)
						f_deps[(tg.path.abspath(), tg.idx)] = lst

		for x in allfiles:
			# f_tstamps has everything, while md5_tstamp can be relatively empty on partial builds
			self.f_tstamps[x] = self.hashes_md5_tstamp[x][0]

		if do_store:
			dbfn = os.path.join(self.variant_dir, TSTAMP_DB)
			Logs.debug('rev_use: storing %s', dbfn)
			dbfn_tmp = dbfn + '.tmp'
			x = Build.cPickle.dumps([self.f_tstamps, f_deps], Build.PROTOCOL)
			Utils.writef(dbfn_tmp, x, m='wb')
			os.rename(dbfn_tmp, dbfn)
			Logs.debug('rev_use: stored %s', dbfn)
Beispiel #39
0
 def write(self, data, flags="w", encoding="ISO8859-1"):
     Utils.writef(self.abspath(), data, flags, encoding)