Ejemplo n.º 1
0
def set_main_module(file_path):
	"""
	Read the main wscript file into :py:const:`waflib.Context.Context.g_module` and
	bind default functions such as ``init``, ``dist``, ``distclean`` if not defined.
	Called by :py:func:`waflib.Scripting.waf_entry_point` during the initialization.

	:param file_path: absolute path representing the top-level wscript file
	:type file_path: string
	"""
	Context.g_module = Context.load_module(file_path)
	Context.g_module.root_path = file_path

	# note: to register the module globally, use the following:
	# sys.modules['wscript_main'] = g_module

	def set_def(obj):
		name = obj.__name__
		if not name in Context.g_module.__dict__:
			setattr(Context.g_module, name, obj)
	for k in (update, dist, distclean, distcheck):
		set_def(k)
	# add dummy init and shutdown functions if they're not defined
	if not 'init' in Context.g_module.__dict__:
		Context.g_module.init = Utils.nada
	if not 'shutdown' in Context.g_module.__dict__:
		Context.g_module.shutdown = Utils.nada
	if not 'options' in Context.g_module.__dict__:
		Context.g_module.options = Utils.nada
Ejemplo n.º 2
0
def set_main_module(file_path):
    """
	Read the main wscript file into :py:const:`waflib.Context.Context.g_module` and
	bind default functions such as ``init``, ``dist``, ``distclean`` if not defined.
	Called by :py:func:`waflib.Scripting.waf_entry_point` during the initialization.

	:param file_path: absolute path representing the top-level wscript file
	:type file_path: string
	"""
    Context.g_module = Context.load_module(file_path)
    Context.g_module.root_path = file_path

    # note: to register the module globally, use the following:
    # sys.modules['wscript_main'] = g_module

    def set_def(obj):
        name = obj.__name__
        if not name in Context.g_module.__dict__:
            setattr(Context.g_module, name, obj)

    for k in (update, dist, distclean, distcheck, update):
        set_def(k)
    # add dummy init and shutdown functions if they're not defined
    if not 'init' in Context.g_module.__dict__:
        Context.g_module.init = Utils.nada
    if not 'shutdown' in Context.g_module.__dict__:
        Context.g_module.shutdown = Utils.nada
    if not 'options' in Context.g_module.__dict__:
        Context.g_module.options = Utils.nada
Ejemplo n.º 3
0
    def post_recurse(self, node):
        super(TestContext, self).post_recurse(node)

        scope = self.pop()
        duration = (bench_time() - self.start_time) * 1000.0
        is_top = str(node.parent) == str(Context.top_dir)

        wscript_module = Context.load_module(node.abspath())
        if not hasattr(wscript_module, 'test'):
            os.chdir(self.original_dir)
            return

        Logs.info('')
        self.log_good('=' * 10, '%d tests from %s ran (%d ms total)',
                      scope.n_total, scope.name, duration)

        if not self.env.NO_COVERAGE:
            if is_top:
                self.gen_coverage()

            if os.path.exists('coverage/index.html'):
                self.log_good('REPORT', '<file://%s>',
                              os.path.abspath('coverage/index.html'))

        successes = scope.n_total - scope.n_failed
        Logs.pprint('GREEN', '[  PASSED  ] %d tests' % successes)
        if scope.n_failed > 0:
            Logs.pprint('RED', '[  FAILED  ] %d tests' % scope.n_failed)

        Logs.info("\nWaf: Leaving directory `%s'" % os.getcwd())
        os.chdir(self.original_dir)
Ejemplo n.º 4
0
def start(cwd, version, wafdir):
	# this is the entry point of our small build system

	Logs.init_log()
	Context.waf_dir = wafdir
	Context.out_dir = Context.top_dir = Context.run_dir = cwd
	Context.g_module = Context.load_module(cwd + os.sep + 'wscript')
	Context.g_module.configure = configure
	Context.g_module.root_path = cwd
	Context.Context.recurse = recurse_rep

	Context.g_module.top = Context.g_module.out = '.' # no build directory

	# just parse the options and execute a build
	Options.OptionsContext().execute()

	conf = Context.create_context('configure')
	conf.options = Options.options
	conf.execute()

	bld = Context.create_context('build')
	bld.env = conf.env
	bld.options = Options.options
	bld.environ = os.environ
	bld.execute()
Ejemplo n.º 5
0
def start(cwd, version, wafdir):
    # this is the entry point of our small build system

    Logs.init_log()
    Context.waf_dir = wafdir
    Context.out_dir = Context.top_dir = Context.run_dir = cwd
    Context.g_module = Context.load_module(cwd + os.sep + 'wscript')
    Context.g_module.configure = configure
    Context.g_module.root_path = cwd
    Context.Context.recurse = recurse_rep

    Context.g_module.top = Context.g_module.out = '.'  # no build directory

    # just parse the options and execute a build
    Options.OptionsContext().execute()

    conf = Context.create_context('configure')
    conf.options = Options.options
    conf.execute()

    bld = Context.create_context('build')
    bld.env = conf.env
    bld.options = Options.options
    bld.environ = os.environ
    bld.execute()
Ejemplo n.º 6
0
def subdir(path):
    currpackages = Package.packages()
    currglobal = Package.globalpackage
    Package.initPackages()

    def src(p):
        return os.path.join(os.path.abspath(path), p)

    mpath = os.path.join(os.path.abspath(path), 'wscript')
    Context.wscript_vars['src'] = src
    #fcode = self.root.find_node(mpath).read('rU')
    #exec_dict = dict(Context.wscript_vars)
    #exec(compile(fcode, mpath, 'exec'), exec_dict)
    Context.load_module(mpath)

    respackages = Package.packages()
    Package.packdict[path] = respackages
    Package.initPackages(currpackages, currglobal)
    return respackages
Ejemplo n.º 7
0
def subdir(path) :
    currpackages = Package.packages()
    currglobal = Package.globalpackage
    Package.initPackages()

    def src(p) :
        return os.path.join(os.path.abspath(path), p)

    mpath = os.path.join(os.path.abspath(path), 'wscript')
    oldsrc = Context.wscript_vars.get('src', None)
    Context.wscript_vars['src'] = src
    #fcode = self.root.find_node(mpath).read('rU')
    #exec_dict = dict(Context.wscript_vars)
    #exec(compile(fcode, mpath, 'exec'), exec_dict)
    Context.load_module(mpath)

    respackages = Package.packages()
    Package.packdict[path] = respackages
    Package.initPackages(currpackages, currglobal)
    Context.wscript_vars['src'] = oldsrc
    return respackages
Ejemplo n.º 8
0
def set_main_module(file_path):
	Context.g_module=Context.load_module(file_path)
	Context.g_module.root_path=file_path
	def set_def(obj):
		name=obj.__name__
		if not name in Context.g_module.__dict__:
			setattr(Context.g_module,name,obj)
	for k in[update,dist,distclean,distcheck,update]:
		set_def(k)
	if not'init'in Context.g_module.__dict__:
		Context.g_module.init=Utils.nada
	if not'shutdown'in Context.g_module.__dict__:
		Context.g_module.shutdown=Utils.nada
	if not'options'in Context.g_module.__dict__:
		Context.g_module.options=Utils.nada
Ejemplo n.º 9
0
    def recurse(self, dirs, name=None, mandatory=True, once=True):
        try:
            cache = self.recurse_cache
        except:
            cache = self.recurse_cache = {}

        for d in Utils.to_list(dirs):

            if not os.path.isabs(d):
                # absolute paths only
                d = os.path.join(self.path.abspath(), d)

            WSCRIPT = os.path.join(d, 'wscript.py')
            WSCRIPT_FUN = 'wscript_' + (name or self.fun) + '.py'

            node = self.root.find_node(WSCRIPT_FUN)
            if node and (not once or node not in cache):
                cache[node] = True
                self.pre_recurse(node)
                try:
                    function_code = node.read('r')
                    exec(compile(function_code, node.abspath(), 'exec'),
                         self.exec_dict)
                finally:
                    self.post_recurse(node)
            elif not node:
                node = self.root.find_node(WSCRIPT)
                if node and (not once or node not in cache):
                    cache[node] = True
                    self.pre_recurse(node)
                    try:
                        wscript_module = mod.load_module(node.abspath())
                        user_function = getattr(wscript_module,
                                                (name or self.fun), None)
                        if not user_function:
                            if not mandatory:
                                continue
                            raise Errors.WafError(
                                'No function %s defined in %s' %
                                (name or self.fun, node.abspath()))
                        user_function(self)
                    finally:
                        self.post_recurse(node)
                elif not node:
                    if not mandatory:
                        continue
                    raise Errors.WafError('No wscript file in directory %s' %
                                          d)
Ejemplo n.º 10
0
def initialise_waf():
    if waf_initialised: return
    
    Logs.init_log()
    
    Context.waf_dir = wafdir
    Context.top_dir = Context.run_dir = xpdeintUserDataPath
    Context.out_dir = os.path.join(xpdeintUserDataPath, 'waf_configure')
    
    wscript_path = resource_filename(__name__, 'support/wscript')
    Context.g_module = Context.load_module(wscript_path)
    Context.g_module.root_path = wscript_path
    Context.g_module.out = Context.out_dir
    Context.g_module.configure = configure_wrapper(Context.g_module.configure)
    Context.Context.recurse = \
        lambda x, y: getattr(Context.g_module, x.cmd or x.fun, Utils.nada)(x)
    
    Options.OptionsContext().execute()
Ejemplo n.º 11
0
    def pre_recurse(self, node):
        wscript_module = Context.load_module(node.abspath())
        group_name = wscript_module.APPNAME
        self.stack.append(TestScope(self, group_name, self.defaults()))
        self.max_depth = max(self.max_depth, len(self.stack) - 1)

        bld_dir = node.get_bld().parent
        if bld_dir != self.path.get_bld():
            Logs.info('')

        self.original_dir = os.getcwd()
        Logs.info("Waf: Entering directory `%s'\n", bld_dir)
        os.chdir(str(bld_dir))

        if str(node.parent) == Context.top_dir:
            self.clear_coverage()

        self.log_good('=' * 10, 'Running %s tests', group_name)
        super(TestContext, self).pre_recurse(node)
Ejemplo n.º 12
0
	def recurse(self, dirs, name=None, mandatory=True, once=True):
		try:
			cache = self.recurse_cache
		except:
			cache = self.recurse_cache = {}

		for d in Utils.to_list(dirs):

			if not os.path.isabs(d):
				# absolute paths only
				d = os.path.join(self.path.abspath(), d)

			WSCRIPT     = os.path.join(d, 'wscript.py')
			WSCRIPT_FUN = 'wscript_' + (name or self.fun) + '.py'

			node = self.root.find_node(WSCRIPT_FUN)
			if node and (not once or node not in cache):
				cache[node] = True
				self.pre_recurse(node)
				try:
					function_code = node.read('rU')
					exec(compile(function_code, node.abspath(), 'exec'), self.exec_dict)
				finally:
					self.post_recurse(node)
			elif not node:
				node = self.root.find_node(WSCRIPT)
				if node and (not once or node not in cache):
					cache[node] = True
					self.pre_recurse(node)
					try:
						wscript_module = mod.load_module(node.abspath())
						user_function = getattr(wscript_module, (name or self.fun), None)
						if not user_function:
							if not mandatory:
								continue
							raise Errors.WafError('No function %s defined in %s' % (name or self.fun, node.abspath()))
						user_function(self)
					finally:
						self.post_recurse(node)
				elif not node:
					if not mandatory:
						continue
					raise Errors.WafError('No wscript file in directory %s' % d)
Ejemplo n.º 13
0
def set_main_module(file_path):
	"Read the main wscript file into a module and add missing functions if necessary"
	Context.g_module = Context.load_module(file_path)
	Context.g_module.root_path = file_path

	# note: to register the module globally, use the following:
	# sys.modules['wscript_main'] = g_module

	def set_def(obj):
		name = obj.__name__
		if not name in Context.g_module.__dict__:
			setattr(Context.g_module, name, obj)
	for k in [update, dist, distclean, distcheck]:
		set_def(k)
	# add dummy init and shutdown functions if they're not defined
	if not 'init' in Context.g_module.__dict__:
		Context.g_module.init = Utils.nada
	if not 'shutdown' in Context.g_module.__dict__:
		Context.g_module.shutdown = Utils.nada
	if not 'options' in Context.g_module.__dict__:
		Context.g_module.options = Utils.nada
Ejemplo n.º 14
0
    def recurse(self, folders, *args, **kwargs):
        if isinstance(folders, basestring):
            folders = [folders]
        for f in folders:
            self.pathstack.append(f)
            path = os.path.join(*self.pathstack)
            progress_report("Processing " + path)
            self.path = PathNode(path)
            if (os.path.isfile(path + '/wscript')):
                m = Context.load_module(path + '/wscript')

                def PathWrapper(p):
                    return p

                def SettingsWrapper(*k, **kw):
                    return (k, kw)

                m.Path = PathWrapper
                m.Settings = SettingsWrapper
                m.build(self)
            self.pathstack.pop()
Ejemplo n.º 15
0
    def pre_recurse(self, node):
        wscript_module = Context.load_module(node.abspath())
        group_name = wscript_module.APPNAME
        self.stack.append(TestScope(self, group_name, self.defaults()))
        self.max_depth = max(self.max_depth, len(self.stack) - 1)

        bld_dir = node.get_bld().parent

        if hasattr(wscript_module, 'test'):
            self.original_dir = os.getcwd()
            Logs.info("Waf: Entering directory `%s'", bld_dir)
            os.chdir(str(bld_dir))

            parent_is_top = str(node.parent) == Context.top_dir
            if not self.env.NO_COVERAGE and parent_is_top:
                self.clear_coverage()

            Logs.info('')
            self.log_good('=' * 10, 'Running %s tests\n', group_name)

        super(TestContext, self).pre_recurse(node)