def setenv(self, name, env=None): if name not in self.all_envs or env: if not env: env = ConfigSet.ConfigSet() self.prepare_env(env) else: env = env.derive() self.all_envs[name] = env self.variant = name
def __init__(self, *k, **kw): """ Task generator objects predefine various attributes (source, target) for possible processing by process_rule (make-like rules) or process_source (extensions, misc methods) Tasks are stored on the attribute 'tasks'. They are created by calling methods listed in ``self.meths`` or referenced in the attribute ``features`` A topological sort is performed to execute the methods in correct order. The extra key/value elements passed in ``kw`` are set as attributes """ self.source = [] self.target = "" self.meths = [] """ List of method names to execute (internal) """ self.features = [] """ List of feature names for bringing new methods in """ self.tasks = [] """ Tasks created are added to this list """ if not "bld" in kw: # task generators without a build context :-/ self.env = ConfigSet.ConfigSet() self.idx = 0 self.path = None else: self.bld = kw["bld"] self.env = self.bld.env.derive() self.path = self.bld.path # emulate chdir when reading scripts # Provide a unique index per folder # This is part of a measure to prevent output file name collisions path = self.path.abspath() try: self.idx = self.bld.idx[path] = self.bld.idx.get(path, 0) + 1 except AttributeError: self.bld.idx = {} self.idx = self.bld.idx[path] = 1 # Record the global task generator count try: self.tg_idx_count = self.bld.tg_idx_count = self.bld.tg_idx_count + 1 except AttributeError: self.tg_idx_count = self.bld.tg_idx_count = 1 for key, val in kw.items(): setattr(self, key, val)
def execute(self): if not Configure.autoconfig: return execute_method(self) env=ConfigSet.ConfigSet() do_config=False try: env.load(os.path.join(Context.top_dir,Options.lockfile)) except Exception ,e: Logs.warn('Configuring the project') do_config=True
def retrieve(self, name, fromenv=None): try: env = self.all_envs[name] except KeyError: env = ConfigSet.ConfigSet() self.prepare_env(env) self.all_envs[name] = env else: if fromenv: Logs.warn("The environment %s may have been configured already" % name) return env
def restore(self): self.top_dir = os.path.abspath(Context.g_module.top) self.srcnode = self.root.find_node(self.top_dir) self.path = self.srcnode self.out_dir = os.path.join(self.top_dir, Context.g_module.out) self.bldnode = self.root.make_node(self.out_dir) self.bldnode.mkdir() self.env = ConfigSet.ConfigSet()
def LOAD_ENVIRONMENT(): '''load the configuration environment, allowing access to env vars from new commands''' env = ConfigSet.ConfigSet() try: p = os.path.join(Context.g_module.out, 'c4che/default'+CACHE_SUFFIX) env.load(p) except (OSError, IOError): pass return env
def __init__(self, *k, **kw): """ The task generator objects predefine various attributes (source, target) for possible processing by process_rule (make-like rules) or process_source (extensions, misc methods) The tasks are stored on the attribute 'tasks'. They are created by calling methods listed in self.meths *or* referenced in the attribute features A topological sort is performed to ease the method re-use. The extra key/value elements passed in kw are set as attributes """ # so we will have to play with directed acyclic graphs # detect cycles, etc self.source = '' self.target = '' self.meths = [] """ List of method names to execute (it is usually a good idea to avoid touching this) """ self.prec = Utils.defaultdict(list) """ Precedence table for sorting the methods in self.meths """ self.mappings = {} """ List of mappings {extension -> function} for processing files by extension """ self.features = [] """ List of feature names for bringing new methods in """ self.tasks = [] """ List of tasks created. """ if not 'bld' in kw: # task generators without a build context :-/ self.env = ConfigSet.ConfigSet() self.idx = 0 self.path = None else: self.bld = kw['bld'] self.env = self.bld.env.derive() self.path = self.bld.path # emulate chdir when reading scripts for key, val in kw.items(): setattr(self, key, val)
def distclean(ctx): '''removes build folders and data''' def remove_and_log(k, fun): try: fun(k) except EnvironmentError as e: if e.errno != errno.ENOENT: Logs.warn('Could not remove %r', k) # remove waf cache folders on the top-level if not Options.commands: for k in os.listdir('.'): for x in '.waf-2 waf-2 .waf3-2 waf3-2'.split(): if k.startswith(x): remove_and_log(k, shutil.rmtree) # remove a build folder, if any cur = '.' if os.environ.get('NO_LOCK_IN_TOP') or ctx.options.no_lock_in_top: cur = ctx.options.out try: lst = os.listdir(cur) except OSError: Logs.warn('Could not read %r', cur) return if Options.lockfile in lst: f = os.path.join(cur, Options.lockfile) try: env = ConfigSet.ConfigSet(f) except EnvironmentError: Logs.warn('Could not read %r', f) return if not env.out_dir or not env.top_dir: Logs.warn('Invalid lock file %r', f) return if env.out_dir == env.top_dir: distclean_dir(env.out_dir) else: remove_and_log(env.out_dir, shutil.rmtree) env_dirs = [env.out_dir] if not (os.environ.get('NO_LOCK_IN_TOP') or ctx.options.no_lock_in_top): env_dirs.append(env.top_dir) if not (os.environ.get('NO_LOCK_IN_RUN') or ctx.options.no_lock_in_run): env_dirs.append(env.run_dir) for k in env_dirs: p = os.path.join(k, Options.lockfile) remove_and_log(p, os.remove)
def save_samba_deps(bld, tgt_list): '''save the dependency calculations between builds, to make further builds faster''' denv = ConfigSet.ConfigSet() denv.version = savedeps_version denv.savedeps_inputs = savedeps_inputs denv.savedeps_outputs = savedeps_outputs denv.input = {} denv.output = {} denv.outenv = {} denv.caches = {} denv.envvar = {} denv.files = {} for f in savedeps_files: denv.files[f] = os.stat(os.path.join(bld.srcnode.abspath(), f)).st_mtime for c in savedeps_caches: denv.caches[c] = LOCAL_CACHE(bld, c) for e in savedeps_envvars: denv.envvar[e] = bld.env[e] for t in tgt_list: # save all the input attributes for each target tdeps = {} for attr in savedeps_inputs: v = getattr(t, attr, None) if v is not None: tdeps[attr] = v if tdeps != {}: denv.input[t.sname] = tdeps # save all the output attributes for each target tdeps = {} for attr in savedeps_outputs: v = getattr(t, attr, None) if v is not None: tdeps[attr] = v if tdeps != {}: denv.output[t.sname] = tdeps tdeps = {} for attr in savedeps_outenv: if attr in t.env: tdeps[attr] = t.env[attr] if tdeps != {}: denv.outenv[t.sname] = tdeps depsfile = os.path.join(bld.cache_dir, "sambadeps") denv.store_fast(depsfile)
def execute(self): self.init_dirs() self.cachedir = self.bldnode.make_node(Build.CACHE_DIR) self.cachedir.mkdir() path = os.path.join(self.bldnode.abspath(), WAF_CONFIG_LOG) self.logger = Logs.make_logger(path, 'cfg') app = getattr(Context.g_module, 'APPNAME', '') if app: ver = getattr(Context.g_module, 'VERSION', '') if ver: app = "%s (%s)" % (app, ver) params = { 'now': time.ctime(), 'pyver': sys.hexversion, 'systype': sys.platform, 'args': " ".join(sys.argv), 'wafver': Context.WAFVERSION, 'abi': Context.ABI, 'app': app } self.to_log(conf_template % params) self.msg('Setting top to', self.srcnode.abspath()) self.msg('Setting out to', self.bldnode.abspath()) if id(self.srcnode) == id(self.bldnode): Logs.warn('Setting top == out') elif id(self.path) != id(self.srcnode): if self.srcnode.is_child_of(self.path): Logs.warn( 'Are you certain that you do not want to set top="." ?') super(ConfigurationContext, self).execute() self.store() Context.top_dir = self.srcnode.abspath() Context.out_dir = self.bldnode.abspath() env = ConfigSet.ConfigSet() env.argv = sys.argv env.options = Options.options.__dict__ env.config_cmd = self.cmd env.run_dir = Context.run_dir env.top_dir = Context.top_dir env.out_dir = Context.out_dir env.hash = self.hash env.files = self.files env.environ = dict(self.environ) env.launch_dir = Context.launch_dir if not (self.env.NO_LOCK_IN_RUN or env.environ.get('NO_LOCK_IN_RUN') or getattr(Options.options, 'no_lock_in_run')): env.store(os.path.join(Context.run_dir, Options.lockfile)) if not (self.env.NO_LOCK_IN_TOP or env.environ.get('NO_LOCK_IN_TOP') or getattr(Options.options, 'no_lock_in_top')): env.store(os.path.join(Context.top_dir, Options.lockfile)) if not (self.env.NO_LOCK_IN_OUT or env.environ.get('NO_LOCK_IN_OUT') or getattr(Options.options, 'no_lock_in_out')): env.store(os.path.join(Context.out_dir, Options.lockfile))
def load_envs(self): node=self.root.find_node(self.cache_dir) if not node: raise Errors.WafError('The project was not configured: run "waf configure" first!') lst=node.ant_glob('**/*%s'%CACHE_SUFFIX,quiet=True) if not lst: raise Errors.WafError('The cache directory is empty: reconfigure the project') for x in lst: name=x.path_from(node).replace(CACHE_SUFFIX,'').replace('\\','/') env=ConfigSet.ConfigSet(x.abspath()) self.all_envs[name]=env for f in env[CFG_FILES]: newnode=self.root.find_resource(f) if not newnode or not newnode.exists(): raise Errors.WafError('Missing configuration file %r, reconfigure the project!'%f)
def execute(self): self.init_dirs() self.cachedir = self.bldnode.make_node(Build.CACHE_DIR) self.cachedir.mkdir() path = os.path.join(self.bldnode.abspath(), WAF_CONFIG_LOG) self.logger = Logs.make_logger(path, 'cfg') app = getattr(Context.g_module, 'APPNAME', '') if app: ver = getattr(Context.g_module, 'VERSION', '') if ver: app = "%s (%s)" % (app, ver) now = time.ctime() pyver = sys.hexversion systype = sys.platform args = " ".join(sys.argv) wafver = Context.WAFVERSION abi = Context.ABI self.to_log(conf_template % vars()) self.msg('Setting top to', self.srcnode.abspath()) self.msg('Setting out to', self.bldnode.abspath()) if id(self.srcnode) == id(self.bldnode): Logs.warn('Setting top == out (remember to use "update_outputs")') elif id(self.path) != id(self.srcnode): if self.srcnode.is_child_of(self.path): Logs.warn( 'Are you certain that you do not want to set top="." ?') super(ConfigurationContext, self).execute() self.store() Context.top_dir = self.srcnode.abspath() Context.out_dir = self.bldnode.abspath() env = ConfigSet.ConfigSet() env['argv'] = sys.argv env['options'] = Options.options.__dict__ env.run_dir = Context.run_dir env.top_dir = Context.top_dir env.out_dir = Context.out_dir env['hash'] = self.hash env['files'] = self.files env['environ'] = dict(self.environ) if not self.env.NO_LOCK_IN_RUN and not getattr(Options.options, 'no_lock_in_run'): env.store(os.path.join(Context.run_dir, Options.lockfile)) if not self.env.NO_LOCK_IN_TOP and not getattr(Options.options, 'no_lock_in_top'): env.store(os.path.join(Context.top_dir, Options.lockfile)) if not self.env.NO_LOCK_IN_OUT and not getattr(Options.options, 'no_lock_in_out'): env.store(os.path.join(Context.out_dir, Options.lockfile))
def distclean(ctx): """removes build folders and data""" def remove_and_log(k, fun): try: fun(k) except OSError as e: if e.errno != errno.ENOENT: Logs.warn("Could not remove %r", k) # remove waf cache folders on the top-level if not Options.commands: for k in os.listdir("."): for x in ".waf-2 waf-2 .waf3-2 waf3-2".split(): if k.startswith(x): remove_and_log(k, shutil.rmtree) # remove a build folder, if any cur = "." if ctx.options.no_lock_in_top: cur = ctx.options.out try: lst = os.listdir(cur) except OSError: Logs.warn("Could not read %r", cur) return if Options.lockfile in lst: f = os.path.join(cur, Options.lockfile) try: env = ConfigSet.ConfigSet(f) except OSError: Logs.warn("Could not read %r", f) return if not env.out_dir or not env.top_dir: Logs.warn("Invalid lock file %r", f) return if env.out_dir == env.top_dir: distclean_dir(env.out_dir) else: remove_and_log(env.out_dir, shutil.rmtree) for k in (env.out_dir, env.top_dir, env.run_dir): p = os.path.join(k, Options.lockfile) remove_and_log(p, os.remove)
def distclean(ctx): '''removes the build directory''' def remove_and_log(k, fun): try: fun(k) except EnvironmentError as e: if e.errno != errno.ENOENT: Logs.warn('Could not remove %r', k) # remove waf cache folders on the top-level if not Options.commands: for k in os.listdir('.'): for x in '.waf-1. waf-1. .waf3-1. waf3-1.'.split(): if k.startswith(x): remove_and_log(k, shutil.rmtree) # remove a build folder, if any cur = '.' if ctx.options.no_lock_in_top: cur = ctx.options.out try: lst = os.listdir(cur) except OSError: Logs.warn('Could not read %r', cur) return if Options.lockfile in lst: f = os.path.join(cur, Options.lockfile) try: env = ConfigSet.ConfigSet(f) except EnvironmentError: Logs.warn('Could not read %r', f) return if not env.out_dir or not env.top_dir: Logs.warn('Invalid lock file %r', f) return if env.out_dir == env.top_dir: distclean_dir(env.out_dir) else: remove_and_log(env.out_dir, shutil.rmtree) for k in (env.out_dir, env.top_dir, env.run_dir): p = os.path.join(k, Options.lockfile) remove_and_log(p, os.remove)
def restore(self): """ Load the data from a previous run, sets the attributes listed in :py:const:`waflib.Build.SAVED_ATTRS` """ try: env = ConfigSet.ConfigSet( os.path.join(self.cache_dir, 'build.config.py')) except (IOError, OSError): pass else: if env['version'] < Context.HEXVERSION: raise Errors.WafError( 'Version mismatch! reconfigure the project') for t in env['tools']: self.setup(**t) f = None try: dbfn = os.path.join(self.variant_dir, Context.DBFILE) try: f = open(dbfn, 'rb') except (IOError, EOFError): # handle missing file/empty file Logs.debug( 'build: could not load the build cache %s (missing)' % dbfn) else: try: waflib.Node.pickle_lock.acquire() waflib.Node.Nod3 = self.node_class try: data = cPickle.load(f) except Exception as e: Logs.debug( 'build: could not pickle the build cache %s: %r' % (dbfn, e)) else: for x in SAVED_ATTRS: setattr(self, x, data[x]) finally: waflib.Node.pickle_lock.release() finally: if f: f.close() self.init_dirs()
def execute(self): """ Wraps :py:func:`waflib.Context.Context.execute` on the context class """ if not Configure.autoconfig: return execute_method(self) env = ConfigSet.ConfigSet() do_config = False try: env.load(os.path.join(Context.top_dir, Options.lockfile)) except EnvironmentError: Logs.warn('Configuring the project') do_config = True else: if env.run_dir != Context.run_dir: do_config = True else: h = 0 for f in env.files: try: h = Utils.h_list((h, Utils.readf(f, 'rb'))) except EnvironmentError: do_config = True break else: do_config = h != env.hash if do_config: cmd = env.config_cmd or 'configure' if Configure.autoconfig == 'clobber': tmp = Options.options.__dict__ launch_dir_tmp = Context.launch_dir if env.options: Options.options.__dict__ = env.options Context.launch_dir = env.launch_dir try: run_command(cmd) finally: Options.options.__dict__ = tmp Context.launch_dir = launch_dir_tmp else: run_command(cmd) run_command(self.cmd) else: return execute_method(self)
def configure(conf): store_data = ConfigSet.ConfigSet() options = vars(conf.options) environ = conf.environ if conf.options.reconfigure or conf.options.rebuild_cache: store_data.load(STORE_PATH) if conf.options.reconfigure: for o in options: if options[o]: store_data['OPTIONS'][o] = options[o] store_data['ENVIRON'].update(environ) store_data.store(STORE_PATH) conf.environ = store_data['ENVIRON'] conf.options = optparse.Values(store_data['OPTIONS']) else: store_data['OPTIONS'] = vars(conf.options) store_data['ENVIRON'] = conf.environ store_data.store(STORE_PATH)
def configure(conf): store_path = os.path.join(conf.bldnode.abspath(), 'configuration.py') store_data = ConfigSet.ConfigSet() options = vars(conf.options) environ = conf.environ if conf.options.reconfigure or conf.options.rebuild_cache: store_data.load(store_path) if conf.options.reconfigure: for o in options: if options[o]: store_data['OPTIONS'][o] = options[o] store_data['ENVIRON'].update(environ) store_data.store(store_path) conf.environ = store_data['ENVIRON'] conf.options = optparse.Values(store_data['OPTIONS']) else: store_data['OPTIONS'] = vars(conf.options) store_data['ENVIRON'] = conf.environ store_data.store(store_path)
def configure(ctx): has_git_repo = False has_ns3_tags = False if ctx.check_git_repo(): has_git_repo = True has_ns3_tags = ctx.check_git_repo_has_ns3_tags() ctx.env['HAVE_GIT_REPO'] = has_git_repo ctx.env['HAVE_NS3_REPO'] = has_ns3_tags if not has_ns3_tags: version_cache = ConfigSet.ConfigSet() #no ns-3 repository, look for a cache file containing the version info ctx.start_msg('Searching for file {}'.format(CACHE_FILE)) glob_pattern = '**/{}'.format(CACHE_FILE) cache_path = ctx.path.ant_glob(glob_pattern) if len(cache_path) > 0: #Found cache file #Load it and merge the information into the main context environment src_path = cache_path[0].srcpath() ctx.end_msg(src_path) version_cache.load(src_path) else: ctx.end_msg(False) #no version information, create dummy info version_cache['CLOSEST_TAG'] = '"ns-3.xx"' version_cache['VERSION_COMMIT_HASH'] = '"gxxxxxxx"' version_cache['VERSION_DIRTY_FLAG'] = '0' version_cache['VERSION_MAJOR'] = '3' version_cache['VERSION_MINOR'] = '0' version_cache['VERSION_PATCH'] = '0' version_cache['VERSION_RELEASE_CANDIDATE'] = '""' version_cache['VERSION_TAG'] = '"ns-3.xx"' version_cache['VERSION_TAG_DISTANCE'] = '0' ctx.env.update(version_cache)
def load_envs(self): node=self.root.find_node(self.cache_dir) if not node: raise Errors.WafError('The project was not configured: run "waf configure" first!') lst=node.ant_glob('**/*%s'%CACHE_SUFFIX,quiet=True) if not lst: raise Errors.WafError('The cache directory is empty: reconfigure the project') for x in lst: name=x.path_from(node).replace(CACHE_SUFFIX,'').replace('\\','/') env=ConfigSet.ConfigSet(x.abspath()) self.all_envs[name]=env for f in env[CFG_FILES]: newnode=self.root.find_resource(f) try: h=Utils.h_file(newnode.abspath()) except(IOError,AttributeError): Logs.error('cannot find %r'%f) h=Utils.SIG_NIL newnode.sig=h
def restore(self): """ Load data from a previous run, sets the attributes listed in :py:const:`waflib.Build.SAVED_ATTRS` """ try: env = ConfigSet.ConfigSet( os.path.join(self.cache_dir, 'build.config.py')) except EnvironmentError: pass else: if env.version < Context.HEXVERSION: raise Errors.WafError( 'Project was configured with a different version of Waf, please reconfigure it' ) for t in env.tools: self.setup(**t) dbfn = os.path.join(self.variant_dir, Context.DBFILE) try: data = Utils.readf(dbfn, 'rb') except (EnvironmentError, EOFError): # handle missing file/empty file Logs.debug('build: Could not load the build cache %s (missing)', dbfn) else: try: Node.pickle_lock.acquire() Node.Nod3 = self.node_class try: data = cPickle.loads(data) except Exception as e: Logs.debug( 'build: Could not pickle the build cache %s: %r', dbfn, e) else: for x in SAVED_ATTRS: setattr(self, x, data.get(x, {})) finally: Node.pickle_lock.release() self.init_dirs()
def execute(self): if Configure.autoconfig: env = ConfigSet.ConfigSet() do_config = False try: env.load( os.path.join(Context.lock_dir, Options.lockfile)) except Exception: Logs.warn('Configuring the project') do_config = True else: if env.run_dir != Context.run_dir: do_config = True else: h = 0 for f in env['files']: try: h = hash((h, Utils.readf(f, 'rb'))) except (IOError, EOFError): pass # ignore missing files (will cause a rerun cause of the changed hash) do_config = h != env.hash if do_config: Options.commands.insert(0, self.cmd) Options.commands.insert(0, 'configure') return # Execute custom clear command self.restore() if not self.all_envs: self.load_envs() self.recurse([self.run_dir]) if self.options.targets: self.target_clean() else: try: self.clean_output_targets() self.clean() finally: self.store()
def execute(self): self.init_dirs() self.cachedir = self.bldnode.make_node(Build.CACHE_DIR) self.cachedir.mkdir() path = os.path.join(self.bldnode.abspath(), WAF_CONFIG_LOG) self.logger = Logs.make_logger(path, 'cfg') app = getattr(Context.g_module, 'APPNAME', '') if app: ver = getattr(Context.g_module, 'VERSION', '') if ver: app = "%s (%s)" % (app, ver) now = time.ctime() pyver = sys.hexversion systype = sys.platform args = " ".join(sys.argv) wafver = Context.WAFVERSION abi = Context.ABI self.to_log(conf_template % vars()) self.msg('Setting top to', self.srcnode.abspath()) self.msg('Setting out to', self.bldnode.abspath()) if id(self.srcnode) == id(self.bldnode): Logs.warn('setting top == out') elif id(self.path) != id(self.srcnode): if self.srcnode.is_child_of(self.path): Logs.warn('Using an uncommon top directory') super(ConfigurationContext, self).execute() self.store() Context.top_dir = self.srcnode.abspath() Context.out_dir = self.bldnode.abspath() env = ConfigSet.ConfigSet() env['argv'] = sys.argv env['options'] = Options.options.__dict__ env.run_dir = Context.run_dir env.top_dir = Context.top_dir env.out_dir = Context.out_dir env['hash'] = self.hash env['files'] = self.files env['environ'] = dict(self.environ) env.store(Context.run_dir + os.sep + Options.lockfile) env.store(Context.top_dir + os.sep + Options.lockfile) env.store(Context.out_dir + os.sep + Options.lockfile)
def __init__(self,*k,**kw): self.source='' self.target='' self.meths=[] self.features=[] self.tasks=[] if not'bld'in kw: self.env=ConfigSet.ConfigSet() self.idx=0 self.path=None else: self.bld=kw['bld'] self.env=self.bld.env.derive() self.path=self.bld.path try: self.idx=self.bld.idx[self.path]=self.bld.idx.get(self.path,0)+1 except AttributeError: self.bld.idx={} self.idx=self.bld.idx[self.path]=1 for key,val in kw.items(): setattr(self,key,val)
def load_envs(self): """ The configuration command creates files of the form ``build/c4che/NAMEcache.py``. This method creates a :py:class:`waflib.ConfigSet.ConfigSet` instance for each ``NAME`` by reading those files and stores them in :py:attr:`waflib.Build.BuildContext.allenvs`. """ node = self.root.find_node(self.cache_dir) if not node: raise Errors.WafError('The project was not configured: run "waf configure" first!') lst = node.ant_glob('**/*%s' % CACHE_SUFFIX, quiet=True) if not lst: raise Errors.WafError('The cache directory is empty: reconfigure the project') for x in lst: name = x.path_from(node).replace(CACHE_SUFFIX, '').replace('\\', '/') env = ConfigSet.ConfigSet(x.abspath()) self.all_envs[name] = env for f in env[CFG_FILES]: newnode = self.root.find_resource(f) if not newnode or not newnode.exists(): raise Errors.WafError('Missing configuration file %r, reconfigure the project!' % f)
def configure(ctx): has_git_repo = False has_ns3_tags = False if not Options.options.enable_build_version: return if ctx.check_git_repo(): has_git_repo = True has_ns3_tags = ctx.check_git_repo_has_ns3_tags() ctx.env['HAVE_GIT_REPO'] = has_git_repo ctx.env['HAVE_NS3_REPO'] = has_ns3_tags if not has_ns3_tags: version_cache = ConfigSet.ConfigSet() #no ns-3 repository, look for a cache file containing the version info ctx.start_msg('Searching for file {}'.format(CACHE_FILE)) glob_pattern = '**/{}'.format(CACHE_FILE) cache_path = ctx.path.ant_glob(glob_pattern) if len(cache_path) > 0: #Found cache file #Load it and merge the information into the main context environment src_path = cache_path[0].srcpath() ctx.end_msg(src_path) version_cache.load(src_path) else: ctx.end_msg(False) ctx.fatal( 'Unable to find ns3 git repository or version.cache file ' 'containing version information') ctx.env.update(version_cache)
def execute(self): if not Configure.autoconfig: return execute_method(self) env = ConfigSet.ConfigSet() do_config = False try: env.load(os.path.join(Context.top_dir, Options.lockfile)) except Exception: Logs.warn('Configuring the project') do_config = True else: if env.run_dir != Context.run_dir: do_config = True else: h = 0 for f in env['files']: h = Utils.h_list((h, Utils.readf(f, 'rb'))) do_config = h != env.hash if do_config: Options.commands.insert(0, self.cmd) Options.commands.insert(0, 'configure') return return execute_method(self)
def __init__(self, *k, **kw): self.source = '' self.target = '' self.meths = [] self.prec = Utils.defaultdict(list) self.mappings = {} self.features = [] self.tasks = [] if not 'bld' in kw: self.env = ConfigSet.ConfigSet() self.idx = 0 self.path = None else: self.bld = kw['bld'] self.env = self.bld.env.derive() self.path = self.bld.path try: self.idx = self.bld.idx[id( self.path)] = self.bld.idx.get(id(self.path), 0) + 1 except AttributeError: self.bld.idx = {} self.idx = self.bld.idx[id(self.path)] = 0 for key, val in kw.items(): setattr(self, key, val)
def execute(self): """ See :py:func:`waflib.Context.Context.execute` """ self.init_dirs() self.cachedir = self.bldnode.make_node(Build.CACHE_DIR) self.cachedir.mkdir() path = os.path.join(self.bldnode.abspath(), WAF_CONFIG_LOG) self.logger = Logs.make_logger(path, 'cfg') app = getattr(Context.g_module, 'APPNAME', '') if app: ver = getattr(Context.g_module, 'VERSION', '') if ver: app = "%s (%s)" % (app, ver) now = time.ctime() pyver = sys.hexversion systype = sys.platform args = " ".join(sys.argv) wafver = Context.WAFVERSION abi = Context.ABI self.to_log(conf_template % vars()) self.msg('Setting top to', self.srcnode.abspath()) self.msg('Setting out to', self.bldnode.abspath()) if id(self.srcnode) == id(self.bldnode): Logs.warn('Setting top == out (remember to use "update_outputs")') elif id(self.path) != id(self.srcnode): if self.srcnode.is_child_of(self.path): Logs.warn( 'Are you certain that you do not want to set top="." ?') super(ConfigurationContext, self).execute() self.store() Context.top_dir = self.srcnode.abspath() Context.out_dir = self.bldnode.abspath() # this will write a configure lock so that subsequent builds will # consider the current path as the root directory (see prepare_impl). # to remove: use 'waf distclean' env = ConfigSet.ConfigSet() env['argv'] = sys.argv env['options'] = Options.options.__dict__ env.run_dir = Context.run_dir env.top_dir = Context.top_dir env.out_dir = Context.out_dir # conf.hash & conf.files hold wscript files paths and hash # (used only by Configure.autoconfig) env['hash'] = self.hash env['files'] = self.files env['environ'] = dict(self.environ) if not self.env.NO_LOCK_IN_RUN: env.store(Context.run_dir + os.sep + Options.lockfile) if not self.env.NO_LOCK_IN_TOP: env.store(Context.top_dir + os.sep + Options.lockfile) if not self.env.NO_LOCK_IN_OUT: env.store(Context.out_dir + os.sep + Options.lockfile)
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