Beispiel #1
0
	def sig_vars(self):
		bld=self.generator.bld
		env=self.env
		upd=self.m.update
		if getattr(self.generator,'fun',None):
			upd(Utils.h_fun(self.generator.fun))
		if getattr(self.generator,'subst_fun',None):
			upd(Utils.h_fun(self.generator.subst_fun))
		vars=self.generator.bld.raw_deps.get(self.uid(),[])
		act_sig=bld.hash_env_vars(env,vars)
		upd(act_sig)
		lst=[getattr(self.generator,x,'')for x in vars]
		upd(Utils.h_list(lst))
		return self.m.digest()
Beispiel #2
0
 def sig_vars(self):
     bld = self.generator.bld
     env = self.env
     upd = self.m.update
     if getattr(self.generator, 'fun', None):
         upd(Utils.h_fun(self.generator.fun))
     if getattr(self.generator, 'subst_fun', None):
         upd(Utils.h_fun(self.generator.subst_fun))
     vars = self.generator.bld.raw_deps.get(self.uid(), [])
     act_sig = bld.hash_env_vars(env, vars)
     upd(act_sig)
     lst = [getattr(self.generator, x, '') for x in vars]
     upd(Utils.h_list(lst))
     return self.m.digest()
Beispiel #3
0
    def __init__(cls, name, bases, dict):
        super(store_task_type, cls).__init__(name, bases, dict)
        name = cls.__name__

        if name.endswith("_task"):
            name = name.replace("_task", "")
        if name != "evil" and name != "TaskBase":
            global classes

            if getattr(cls, "run_str", None):
                # if a string is provided, convert it to a method
                (f, dvars) = compile_fun(cls.run_str, cls.shell)
                cls.hcode = cls.run_str
                cls.run_str = None
                cls.run = f
                cls.vars = list(set(cls.vars + dvars))
                cls.vars.sort()
            elif getattr(cls, "run", None) and not "hcode" in cls.__dict__:
                # getattr(cls, 'hcode') would look in the upper classes
                cls.hcode = Utils.h_fun(cls.run)

            if not getattr(cls, "nocache", None):
                cls = cache_outputs(cls)

            classes[name] = cls
Beispiel #4
0
	def __init__(cls, name, bases, dict):
		super(store_task_type, cls).__init__(name, bases, dict)
		name = cls.__name__

		if name.endswith('_task'):
			name = name.replace('_task', '')
		if name != 'evil' and name != 'TaskBase':
			global classes

			if getattr(cls, 'run_str', None):
				# if a string is provided, convert it to a method
				(f, dvars) = compile_fun(cls.run_str, cls.shell)
				cls.hcode = cls.run_str
				cls.orig_run_str = cls.run_str
				# change the name of run_str or it is impossible to subclass with a function
				cls.run_str = None
				cls.run = f
				cls.vars = list(set(cls.vars + dvars))
				cls.vars.sort()
			elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
				# getattr(cls, 'hcode') would look in the upper classes
				cls.hcode = Utils.h_fun(cls.run)

			if sys.hexversion > 0x3000000:
				cls.hcode = cls.hcode.encode('iso8859-1', 'xmlcharrefreplace')

			# be creative
			getattr(cls, 'register', classes)[name] = cls
Beispiel #5
0
	def __init__(cls, name, bases, dict):
		super(store_task_type, cls).__init__(name, bases, dict)
		name = cls.__name__

		if name.endswith('_task'):
			name = name.replace('_task', '')
		if name != 'evil' and name != 'TaskBase':
			global classes

			if getattr(cls, 'run_str', None):
				# if a string is provided, convert it to a method
				(f, dvars) = compile_fun(cls.run_str, cls.shell)
				cls.hcode = cls.run_str
				cls.orig_run_str = cls.run_str
				# change the name of run_str or it is impossible to subclass with a function
				cls.run_str = None
				cls.run = f
				cls.vars = list(set(cls.vars + dvars))
				cls.vars.sort()
			elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
				# getattr(cls, 'hcode') would look in the upper classes
				cls.hcode = Utils.h_fun(cls.run)

			if sys.hexversion > 0x3000000:
				cls.hcode = cls.hcode.encode('iso8859-1', 'xmlcharrefreplace')

			# be creative
			getattr(cls, 'register', classes)[name] = cls
Beispiel #6
0
    def __init__(cls, name, bases, dict):
        super(store_task_type, cls).__init__(name, bases, dict)
        name = cls.__name__

        if name.endswith('_task'):
            name = name.replace('_task', '')
        if name != 'evil' and name != 'TaskBase':
            global classes

            if getattr(cls, 'run_str', None):
                # if a string is provided, convert it to a method
                (f, dvars) = compile_fun(cls.run_str, cls.shell)
                cls.hcode = cls.run_str
                cls.run_str = None
                cls.run = f
                cls.vars = list(set(cls.vars + dvars))
                cls.vars.sort()
            elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
                # getattr(cls, 'hcode') would look in the upper classes
                cls.hcode = Utils.h_fun(cls.run)

            if not getattr(cls, 'nocache', None):
                cls = cache_outputs(cls)

            # be creative
            getattr(cls, 'register', classes)[name] = cls
	def __init__(cls, name, bases, dict):
		super(store_task_type, cls).__init__(name, bases, dict)
		name = cls.__name__

		if name.endswith('_task'):
			name = name.replace('_task', '')
		if name != 'evil' and name != 'TaskBase':
			global classes

			if getattr(cls, 'run_str', None):
				# if a string is provided, convert it to a method
				(f, dvars) = compile_fun(cls.run_str, cls.shell)
				cls.hcode = cls.run_str
				cls.run_str = None
				cls.run = f
				cls.vars = list(set(cls.vars + dvars))
				cls.vars.sort()
			elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
				# getattr(cls, 'hcode') would look in the upper classes
				cls.hcode = Utils.h_fun(cls.run)

			if not getattr(cls, 'nocache', None):
				cls = cache_outputs(cls)

			# be creative
			getattr(cls, 'register', classes)[name] = cls
Beispiel #8
0
def add_scan_in_signature(ctx):
    ''' By default in waf, tasks are not re-run when their scan method
        changes. This is an issue that caused real bugs in our project when
        switching branches.
        The purpose of this code is to take the scan method of tasks in the
        tasks signatures, like it's done for the run method.

        Note: https://gitlab.com/ita1024/waf/issues/2209 was open to fix this
              bug in waf, but it was rejected.
    '''
    for (_, task) in waflib.Task.classes.items():
        if task.scan:
            task.hcode += Utils.h_fun(task.scan).encode('utf-8')
Beispiel #9
0
    def sig_vars(self):
        """
		Compute a hash (signature) of the variables used in the substitution
		"""
        bld = self.generator.bld
        env = self.env
        upd = self.m.update

        if getattr(self.generator, 'fun', None):
            upd(Utils.h_fun(self.generator.fun).encode())
        if getattr(self.generator, 'subst_fun', None):
            upd(Utils.h_fun(self.generator.subst_fun).encode())

        # raw_deps: persistent custom values returned by the scanner
        vars = self.generator.bld.raw_deps.get(self.uid(), [])

        # hash both env vars and task generator attributes
        act_sig = bld.hash_env_vars(env, vars)
        upd(act_sig)

        lst = [getattr(self.generator, x, '') for x in vars]
        upd(Utils.h_list(lst))

        return self.m.digest()
Beispiel #10
0
	def sig_vars(self):
		"""
		Compute a hash (signature) of the variables used in the substitution
		"""
		bld = self.generator.bld
		env = self.env
		upd = self.m.update

		if getattr(self.generator, 'fun', None):
			upd(Utils.h_fun(self.generator.fun).encode())
		if getattr(self.generator, 'subst_fun', None):
			upd(Utils.h_fun(self.generator.subst_fun).encode())

		# raw_deps: persistent custom values returned by the scanner
		vars = self.generator.bld.raw_deps.get(self.uid(), [])

		# hash both env vars and task generator attributes
		act_sig = bld.hash_env_vars(env, vars)
		upd(act_sig)

		lst = [getattr(self.generator, x, '') for x in vars]
		upd(Utils.h_list(lst))

		return self.m.digest()
Beispiel #11
0
 def __init__(cls, name, bases, dict):
     super(store_task_type, cls).__init__(name, bases, dict)
     name = cls.__name__
     if name.endswith('_task'):
         name = name.replace('_task', '')
     if name != 'evil' and name != 'TaskBase':
         global classes
         if getattr(cls, 'run_str', None):
             (f, dvars) = compile_fun(cls.run_str, cls.shell)
             cls.hcode = cls.run_str
             cls.run_str = None
             cls.run = f
             cls.vars = list(set(cls.vars + dvars))
             cls.vars.sort()
         elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
             cls.hcode = Utils.h_fun(cls.run)
         getattr(cls, 'register', classes)[name] = cls
Beispiel #12
0
	def __init__(cls,name,bases,dict):
		super(store_task_type,cls).__init__(name,bases,dict)
		name=cls.__name__
		if name.endswith('_task'):
			name=name.replace('_task','')
		if name!='evil'and name!='TaskBase':
			global classes
			if getattr(cls,'run_str',None):
				(f,dvars)=compile_fun(cls.run_str,cls.shell)
				cls.hcode=cls.run_str
				cls.run_str=None
				cls.run=f
				cls.vars=list(set(cls.vars+dvars))
				cls.vars.sort()
			elif getattr(cls,'run',None)and not'hcode'in cls.__dict__:
				cls.hcode=Utils.h_fun(cls.run)
			getattr(cls,'register',classes)[name]=cls
Beispiel #13
0
	def __init__(cls,name,bases,dict):
		super(store_task_type,cls).__init__(name,bases,dict)
		name=cls.__name__
		if name.endswith('_task'):
			name=name.replace('_task','')
		if name!='evil'and name!='TaskBase':
			global classes
			if getattr(cls,'run_str',None):
				(f,dvars)=compile_fun(cls.run_str,cls.shell)
				cls.hcode=cls.run_str
				cls.run_str=None
				cls.run=f
				cls.vars.extend(dvars)
			elif getattr(cls,'run',None)and not getattr(cls,'hcode',None):
				cls.hcode=Utils.h_fun(cls.run)
			if not getattr(cls,'nocache',None):
				cls=cache_outputs(cls)
			classes[name]=cls
Beispiel #14
0
Datei: Task.py Projekt: zsx/waf
	def __init__(cls, name, bases, dict):
		super(store_task_type, cls).__init__(name, bases, dict)
		name = cls.__name__

		if name.endswith('_task'):
			name = name.replace('_task', '')
		if name != 'evil' and name != 'TaskBase':
			global classes
			classes[name] = cls

			if getattr(cls, 'run_str', None):
				# if a string is provided, convert it to a method
				(f, dvars) = compile_fun(cls.run_str, cls.shell)
				cls.hcode = cls.run_str
				cls.run = f
				cls.vars.extend(dvars)
			elif getattr(cls, 'run', None) and not getattr(cls, 'hcode', None):
				cls.hcode = Utils.h_fun(cls.run)
Beispiel #15
0
 def __init__(cls, name, bases, dict):
     super(store_task_type, cls).__init__(name, bases, dict)
     name = cls.__name__
     if name.endswith("_task"):
         name = name.replace("_task", "")
     if name != "evil" and name != "TaskBase":
         global classes
         if getattr(cls, "run_str", None):
             (f, dvars) = compile_fun(cls.run_str, cls.shell)
             cls.hcode = cls.run_str
             cls.run_str = None
             cls.run = f
             cls.vars.extend(dvars)
         elif getattr(cls, "run", None) and not "hcode" in cls.__dict__:
             cls.hcode = Utils.h_fun(cls.run)
         if not getattr(cls, "nocache", None):
             cls = cache_outputs(cls)
         classes[name] = cls
Beispiel #16
0
 def __init__(cls, name, bases, dict):
     super(store_task_type, cls).__init__(name, bases, dict)
     name = cls.__name__
     if name.endswith('_task'):
         name = name.replace('_task', '')
     if name != 'evil' and name != 'TaskBase':
         global classes
         if getattr(cls, 'run_str', None):
             (f, dvars) = compile_fun(cls.run_str, cls.shell)
             cls.hcode = cls.run_str
             cls.run_str = None
             cls.run = f
             cls.vars.extend(dvars)
         elif getattr(cls, 'run', None) and not 'hcode' in cls.__dict__:
             cls.hcode = Utils.h_fun(cls.run)
         if not getattr(cls, 'nocache', None):
             cls = cache_outputs(cls)
         classes[name] = cls
Beispiel #17
0
def run_build(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, and you should not rely
	on it too much (read the note on the cache below).
	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 features a cache which can be enabled by 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

	"""
    buf = []
    for key in sorted(kw.keys()):
        v = kw[key]
        if hasattr(v, '__call__'):
            buf.append(Utils.h_fun(v))
        else:
            buf.append(str(v))
    h = Utils.h_list(buf)
    dir = self.bldnode.abspath() + os.sep + (
        not Utils.is_win32 and '.' or '') + 'conf_check_' + Utils.to_hex(h)

    cachemode = kw.get('confcache', getattr(Options.options, 'confcache',
                                            None))

    if not cachemode and os.path.exists(dir):
        shutil.rmtree(dir)

    try:
        os.makedirs(dir)
    except OSError:
        pass

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

    if cachemode == 1:
        try:
            proj = ConfigSet.ConfigSet(os.path.join(dir, 'cache_run_build'))
        except EnvironmentError:
            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)

    cls_name = kw.get('run_build_cls') or getattr(self, 'run_build_cls',
                                                  'build')
    self.test_bld = bld = Context.create_context(cls_name,
                                                 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)  # not really necessary
    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' % traceback.format_exc()
            self.fatal(ret)
        else:
            ret = getattr(bld, 'retval', 0)
    finally:
        if cachemode:
            # cache the results each time
            proj = ConfigSet.ConfigSet()
            proj['cache_run_build'] = ret
            proj.store(os.path.join(dir, 'cache_run_build'))
        else:
            shutil.rmtree(dir)
    return ret
Beispiel #18
0
def run_build(self, *k, **kw):
    buf = []
    for key in sorted(kw.keys()):
        v = kw[key]
        if isinstance(v, ConfigSet.ConfigSet):
            continue
        elif hasattr(v, '__call__'):
            buf.append(Utils.h_fun(v))
        else:
            buf.append(str(v))
    h = Utils.h_list(buf)
    dir = self.bldnode.abspath() + os.sep + (
        not Utils.is_win32 and '.' or '') + 'conf_check_' + Utils.to_hex(h)
    cachemode = kw.get('confcache', getattr(Options.options, 'confcache',
                                            None))
    if not cachemode and os.path.exists(dir):
        shutil.rmtree(dir)
    try:
        os.makedirs(dir)
    except OSError:
        pass
    try:
        os.stat(dir)
    except OSError:
        self.fatal('cannot use the configuration test folder %r' % dir)
    if cachemode == 1:
        try:
            proj = ConfigSet.ConfigSet(os.path.join(dir, 'cache_run_build'))
        except EnvironmentError:
            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)
    cls_name = kw.get('run_build_cls') or getattr(self, 'run_build_cls',
                                                  'build')
    self.test_bld = bld = Context.create_context(cls_name,
                                                 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' % traceback.format_exc()
            self.fatal(ret)
        else:
            ret = getattr(bld, 'retval', 0)
    finally:
        if cachemode:
            proj = ConfigSet.ConfigSet()
            proj['cache_run_build'] = ret
            proj.store(os.path.join(dir, 'cache_run_build'))
        else:
            shutil.rmtree(dir)
    return ret