def display(self): col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL master = self.generator.bld.producer def cur(): return master.processed - master.ready.qsize() if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line(cur(), master.total, col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % ( master.total, cur(), ins, outs, ela) s = str(self) if not s: return None total = master.total n = len(str(total)) fs = '[%%%dd/%%%dd] %%s%%s%%s%%s\n' % (n, n) kw = self.keyword() if kw: kw += ' ' return fs % (cur(), total, kw, col1, s, col2)
def display(self): col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line( self.generator.bld.producer.processed - 1, self.position[1], col1, col2 ) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ",".join([n.name for n in self.inputs]) except AttributeError: ins = "" try: outs = ",".join([n.name for n in self.outputs]) except AttributeError: outs = "" return "|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n" % ( self.position[1], self.generator.bld.producer.processed - 1, ins, outs, ela, ) s = str(self) if not s: return None total = self.position[1] n = len(str(total)) fs = "[%%%dd/%%%dd] %%s%%s%%s" % (n, n) return fs % (self.generator.bld.producer.processed - 1, self.position[1], col1, s, col2)
def display(self): col1=Logs.colors(self.color) col2=Logs.colors.NORMAL master=self.master def cur(): tmp=-1 if hasattr(master,'ready'): tmp-=master.ready.qsize() return master.processed+tmp if self.generator.bld.progress_bar==1: return self.generator.bld.progress_line(cur(),master.total,col1,col2) if self.generator.bld.progress_bar==2: ela=str(self.generator.bld.timer) try: ins=','.join([n.name for n in self.inputs]) except AttributeError: ins='' try: outs=','.join([n.name for n in self.outputs]) except AttributeError: outs='' return'|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n'%(master.total,cur(),ins,outs,ela) s=str(self) if not s: return None total=master.total n=len(str(total)) fs='[%%%dd/%%%dd] %%s%%s%%s%%s\n'%(n,n) kw=self.keyword() if kw: kw+=' ' return fs%(cur(),total,kw,col1,s,col2)
def display(self): col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line( self.generator.bld.producer.processed - 1, self.position[1], col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % ( self.position[1], self.generator.bld.producer.processed - 1, ins, outs, ela) s = str(self) if not s: return None total = self.position[1] n = len(str(total)) fs = '[%%%dd/%%%dd] %%s%%s%%s' % (n, n) return fs % (self.generator.bld.producer.processed - 1, self.position[1], col1, s, col2)
def display(self): "print either the description (using __str__) or the progress bar or the ide output" col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line(self.position[0], self.position[1], col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % (self.position[1], self.position[0], ins, outs, ela) s = str(self) if not s: return None total = self.position[1] n = len(str(total)) fs = '[%%%dd/%%%dd] %%s%%s%%s' % (n, n) return fs % (self.position[0], self.position[1], col1, s, col2)
def display(self): """ Return an execution status for the console, the progress bar, or the IDE output. :rtype: string """ col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line(len(self.generator.bld.returned_tasks), self.position[1], col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % (self.position[1], len(self.generator.bld.returned_tasks), ins, outs, ela) s = str(self) if not s: return None total = self.position[1] n = len(str(total)) fs = '[%%%dd/%%%dd] %%s%%s%%s' % (n, n) return fs % (len(self.generator.bld.returned_tasks), self.position[1], col1, s, col2)
def display(self): """ Return an execution status for the console, the progress bar, or the IDE output. :rtype: string """ col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL master = self.master def cur(): # the current task position, computed as late as possible tmp = -1 if hasattr(master, 'ready'): tmp -= master.ready.qsize() return master.processed + tmp if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line(cur(), master.total, col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % ( master.total, cur(), ins, outs, ela) s = str(self) if not s: return None total = master.total n = len(str(total)) fs = '[%%%dd/%%%dd] %%s%%s%%s%%s\n' % (n, n) kw = self.keyword() if kw: kw += ' ' return fs % (cur(), total, kw, col1, s, col2)
def display(self): """ Returns an execution status for the console, the progress bar, or the IDE output. :rtype: string """ col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL master = self.generator.bld.producer def cur(): # the current task position, computed as late as possible tmp = -1 if hasattr(master, 'ready'): tmp -= master.ready.qsize() return master.processed + tmp if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line(cur(), master.total, col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % (master.total, cur(), ins, outs, ela) s = str(self) if not s: return None total = master.total n = len(str(total)) fs = '[%%%dd/%%%dd] %%s%%s%%s%%s\n' % (n, n) kw = self.keyword() if kw: kw += ' ' return fs % (cur(), total, kw, col1, s, col2)
def display(self): """ Returns an execution status for the console, the progress bar, or the IDE output. :rtype: string """ col1 = Logs.colors(self.color) col2 = Logs.colors.NORMAL master = self.generator.bld.producer def cur(): # the current task position, computed as late as possible return master.processed - master.ready.qsize() if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line(cur(), master.total, col1, col2) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ",".join([n.name for n in self.inputs]) except AttributeError: ins = "" try: outs = ",".join([n.name for n in self.outputs]) except AttributeError: outs = "" return ( f"|Total {master.total}|Current {cur()}|Inputs {ins}|Outputs {outs}|Time {ela}|\n" ) s = str(self) if not s: return None total = master.total n = len(str(total)) fs = "[%%%dd/%%%dd] %%s%%s%%s%%s\n" % (n, n) kw = self.keyword() if kw: kw += " " return fs % (cur(), total, kw, col1, s, col2)
def run(self): """Run the task.""" for source_node, target_node in zip(self.inputs, self.outputs): source = source_node.abspath() target = target_node.abspath() # Following is for shared libs and stale inodes (-_-) try: os.remove(target) except OSError: pass # Make sure the output directories are available try: os.makedirs(os.path.dirname(target)) except OSError: pass # Copy the file try: shutil.copy2(source, target) os.chmod(target, self.chmod) except IOError as e: Logs.error("The copy file step failed: {0}".format(e)) try: os.stat(source) except (OSError, IOError): Logs.error("File %r does not exist" % source) raise Errors.WafError("Could not copy the file %r" % target) Logs.info("{n}{s}Copying {c}{source}{n} -> {c}{target}{n}".format( c=Logs.colors(CopyFileTask.color), s=" " * 10, source=source_node.name, target=target_node.relpath(), n=Logs.colors.NORMAL, ))
def run(self): """Run the task.""" for source_node, target_node in zip(self.inputs, self.outputs): source = source_node.abspath() target = target_node.abspath() # Following is for shared libs and stale inodes (-_-) try: os.remove(target) except OSError: pass # Make sure the output directories are available try: os.makedirs(os.path.dirname(target)) except OSError: pass # Copy the file try: shutil.copy2(source, target) os.chmod(target, self.chmod) except IOError as e: Logs.error("The copy file step failed: {0}".format(e)) try: os.stat(source) except (OSError, IOError): Logs.error('File %r does not exist' % source) raise Errors.WafError('Could not copy the file %r' % target) Logs.info("{n}{s}Copying {c}{source}{n} -> {c}{target}{n}".format( c=Logs.colors(CopyFileTask.color), s=' ' * 10, source=source_node.name, target=target_node.relpath(), n=Logs.colors.NORMAL))
def display(self): """log to term... mostly copied from waflib.Task.Task """ norm = Logs.colors.NORMAL bold = Logs.colors.BOLD dark = Logs.colors.BLACK col1 = Logs.colors(self.color) col2 = bold + col1 master = self.master def cur(): # the current task position, computed as late as possible tmp = -1 if hasattr(master, 'ready'): tmp -= master.ready.qsize() return master.processed + tmp if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line( cur(), master.total, col1, col2, ) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % ( master.total, cur(), ins, outs, ela, ) total = master.total n = len(str(total)) n_min = (n * 2) + 2 n_mod = n_min % 4 n_buf = n_min + n_mod pfx = ' ' * n_buf sp = ' ' * 2 env = self.env src_str = ('\n' + pfx).join([a.nice_path() for a in self.inputs]) tgt_str = ('\n' + pfx + sp).join([a.nice_path() for a in self.outputs]) sep0 = sep1 = '' if self.inputs: sep0 = '\n' + norm + col1 + pfx if self.outputs: sep1 = '\n' + norm + col1 + pfx + sp name = str(self) dist = getattr(self, 'dist', None) if dist: name = '%s%s %s%s' % (name, dark, norm, dist.name_and_version) s = '%s%s%s%s%s\n' % (name, sep0, src_str, sep1, tgt_str) fs = '%s%%%dd/%%%dd%s%s %%s%%s%%s' % (' ' * n_mod, n, n, bold, dark) out = fs % (cur(), total, col2, s, norm) sys.stderr.write(out) return ''
def configure(conf): conf.load('relocation', tooldir=['waf-tools']) # attach some extra methods conf.check_nonfatal = types.MethodType(_check_nonfatal, conf) conf.check_compilation_flag = types.MethodType(_check_compilation_flag, conf) conf.report_optional_feature = types.MethodType(report_optional_feature, conf) conf.check_optional_feature = types.MethodType(check_optional_feature, conf) conf.env['NS3_OPTIONAL_FEATURES'] = [] conf.load('compiler_c') cc_string='.'.join(conf.env['CC_VERSION']) conf.msg('Checking for cc version',cc_string,'GREEN') conf.load('compiler_cxx') conf.load('cflags', tooldir=['waf-tools']) conf.load('command', tooldir=['waf-tools']) conf.load('gnu_dirs') env = conf.env if Options.options.enable_gcov: env['GCOV_ENABLED'] = True env.append_value('CCFLAGS', '-fprofile-arcs') env.append_value('CCFLAGS', '-ftest-coverage') env.append_value('CXXFLAGS', '-fprofile-arcs') env.append_value('CXXFLAGS', '-ftest-coverage') env.append_value('LINKFLAGS', '-lgcov') env.append_value('LINKFLAGS', '-coverage') if Options.options.build_profile == 'debug': env.append_value('DEFINES', 'NS3_ASSERT_ENABLE') env.append_value('DEFINES', 'NS3_LOG_ENABLE') env['PLATFORM'] = sys.platform env['BUILD_PROFILE'] = Options.options.build_profile if Options.options.build_profile == "release": env['BUILD_SUFFIX'] = '' else: env['BUILD_SUFFIX'] = '-'+Options.options.build_profile env['APPNAME'] = wutils.APPNAME env['VERSION'] = wutils.VERSION if conf.env['CXX_NAME'] in ['gcc', 'icc']: if Options.options.build_profile == 'release': env.append_value('CXXFLAGS', '-fomit-frame-pointer') if Options.options.build_profile == 'optimized': if conf.check_compilation_flag('-march=native'): env.append_value('CXXFLAGS', '-march=native') env.append_value('CXXFLAGS', '-fstrict-overflow') if conf.env['CC_VERSION'] == cc_version_warn_strict_overflow: env.append_value('CXXFLAGS', '-Wstrict-overflow=5') if sys.platform == 'win32': env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc") elif sys.platform == 'cygwin': env.append_value("LINKFLAGS", "-Wl,--enable-auto-import") cxx = env['CXX'] cxx_check_libstdcxx = cxx + ['-print-file-name=libstdc++.so'] p = subprocess.Popen(cxx_check_libstdcxx, stdout=subprocess.PIPE) libstdcxx_location = os.path.dirname(p.stdout.read().strip()) p.wait() if libstdcxx_location: conf.env.append_value('NS3_MODULE_PATH', libstdcxx_location) if Options.platform in ['linux']: if conf.check_compilation_flag('-Wl,--soname=foo'): env['WL_SONAME_SUPPORTED'] = True env['ENABLE_STATIC_NS3'] = False if Options.options.enable_static: if Options.platform == 'darwin': if conf.check_compilation_flag(flag=[], linkflags=['-Wl,-all_load']): conf.report_optional_feature("static", "Static build", True, '') env['ENABLE_STATIC_NS3'] = True else: conf.report_optional_feature("static", "Static build", False, "Link flag -Wl,-all_load does not work") else: if conf.check_compilation_flag(flag=[], linkflags=['-Wl,--whole-archive,-Bstatic', '-Wl,-Bdynamic,--no-whole-archive']): conf.report_optional_feature("static", "Static build", True, '') env['ENABLE_STATIC_NS3'] = True else: conf.report_optional_feature("static", "Static build", False, "Link flag -Wl,--whole-archive,-Bstatic does not work") # Set this so that the lists won't be printed at the end of this # configure command. conf.env['PRINT_BUILT_MODULES_AT_END'] = False conf.env['MODULES_NOT_BUILT'] = [] conf.recurse('bindings/python') conf.recurse('src') # Set the list of enabled modules. if Options.options.enable_modules: # Use the modules explicitly enabled. conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in Options.options.enable_modules.split(',')] else: # Use the enabled modules list from the ns3 configuration file. if modules_enabled[0] == 'all_modules': # Enable all modules if requested. conf.env['NS3_ENABLED_MODULES'] = conf.env['NS3_MODULES'] else: # Enable the modules from the list. conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in modules_enabled] # Add the template module to the list of enabled modules that # should not be built if this is a static build on Darwin. They # don't work there for the template module, and this is probably # because the template module has no source files. if conf.env['ENABLE_STATIC_NS3'] and sys.platform == 'darwin': conf.env['MODULES_NOT_BUILT'].append('template') # Remove these modules from the list of enabled modules. for not_built in conf.env['MODULES_NOT_BUILT']: not_built_name = 'ns3-' + not_built if not_built_name in conf.env['NS3_ENABLED_MODULES']: conf.env['NS3_ENABLED_MODULES'].remove(not_built_name) if not conf.env['NS3_ENABLED_MODULES']: raise WafError('Exiting because the ' + not_built + ' module can not be built and it was the only one enabled.') conf.recurse('src/mpi') # for suid bits try: conf.find_program('sudo', var='SUDO') except WafError: pass why_not_sudo = "because we like it" if Options.options.enable_sudo and conf.env['SUDO']: env['ENABLE_SUDO'] = True else: env['ENABLE_SUDO'] = False if Options.options.enable_sudo: why_not_sudo = "program sudo not found" else: why_not_sudo = "option --enable-sudo not selected" conf.report_optional_feature("ENABLE_SUDO", "Use sudo to set suid bit", env['ENABLE_SUDO'], why_not_sudo) # Decide if tests will be built or not. if Options.options.enable_tests: # Tests were explicitly enabled. env['ENABLE_TESTS'] = True why_not_tests = "option --enable-tests selected" elif Options.options.disable_tests: # Tests were explicitly disabled. env['ENABLE_TESTS'] = False why_not_tests = "option --disable-tests selected" else: # Enable tests based on the ns3 configuration file. env['ENABLE_TESTS'] = tests_enabled if config_file_exists: why_not_tests = "based on configuration file" elif tests_enabled: why_not_tests = "defaults to enabled" else: why_not_tests = "defaults to disabled" conf.report_optional_feature("ENABLE_TESTS", "Build tests", env['ENABLE_TESTS'], why_not_tests) # Decide if examples will be built or not. if Options.options.enable_examples: # Examples were explicitly enabled. env['ENABLE_EXAMPLES'] = True why_not_examples = "option --enable-examples selected" elif Options.options.disable_examples: # Examples were explicitly disabled. env['ENABLE_EXAMPLES'] = False why_not_examples = "option --disable-examples selected" else: # Enable examples based on the ns3 configuration file. env['ENABLE_EXAMPLES'] = examples_enabled if config_file_exists: why_not_examples = "based on configuration file" elif examples_enabled: why_not_examples = "defaults to enabled" else: why_not_examples = "defaults to disabled" env['EXAMPLE_DIRECTORIES'] = [] for dir in os.listdir('examples'): if dir.startswith('.') or dir == 'CVS': continue if os.path.isdir(os.path.join('examples', dir)): env['EXAMPLE_DIRECTORIES'].append(dir) conf.report_optional_feature("ENABLE_EXAMPLES", "Build examples", env['ENABLE_EXAMPLES'], why_not_examples) env['VALGRIND_FOUND'] = False try: conf.find_program('valgrind', var='VALGRIND') env['VALGRIND_FOUND'] = True except WafError: pass # These flags are used for the implicitly dependent modules. if env['ENABLE_STATIC_NS3']: if sys.platform == 'darwin': env.STLIB_MARKER = '-Wl,-all_load' else: env.STLIB_MARKER = '-Wl,--whole-archive,-Bstatic' env.SHLIB_MARKER = '-Wl,-Bdynamic,--no-whole-archive' have_gsl = conf.check_cfg(package='gsl', args=['--cflags', '--libs'], uselib_store='GSL', mandatory=False) conf.env['ENABLE_GSL'] = have_gsl conf.report_optional_feature("GSL", "GNU Scientific Library (GSL)", conf.env['ENABLE_GSL'], "GSL not found") # for compiling C code, copy over the CXX* flags conf.env.append_value('CCFLAGS', conf.env['CXXFLAGS']) def add_gcc_flag(flag): if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ: if conf.check_compilation_flag(flag, mode='cxx'): env.append_value('CXXFLAGS', flag) if env['COMPILER_CC'] == 'gcc' and 'CCFLAGS' not in os.environ: if conf.check_compilation_flag(flag, mode='cc'): env.append_value('CCFLAGS', flag) add_gcc_flag('-Wno-error=deprecated-declarations') add_gcc_flag('-fstrict-aliasing') add_gcc_flag('-Wstrict-aliasing') try: conf.find_program('doxygen', var='DOXYGEN') except WafError: pass # append user defined flags after all our ones for (confvar, envvar) in [['CCFLAGS', 'CCFLAGS_EXTRA'], ['CXXFLAGS', 'CXXFLAGS_EXTRA'], ['LINKFLAGS', 'LINKFLAGS_EXTRA'], ['LINKFLAGS', 'LDFLAGS_EXTRA']]: if envvar in os.environ: value = shlex.split(os.environ[envvar]) conf.env.append_value(confvar, value) # Write a summary of optional features status print "---- Summary of optional NS-3 features:" print "%-30s: %s%s%s" % ("Build profile", Logs.colors('GREEN'), Options.options.build_profile, Logs.colors('NORMAL')) bld = wutils.bld print "%-30s: %s%s%s" % ("Build directory", Logs.colors('GREEN'), Options.options.out, Logs.colors('NORMAL')) for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']: if was_enabled: status = 'enabled' color = 'GREEN' else: status = 'not enabled (%s)' % reason_not_enabled color = 'RED' print "%-30s: %s%s%s" % (caption, Logs.colors(color), status, Logs.colors('NORMAL'))
def fake_pprint(col, str, label='', sep='\n'): fake_output.write("%s%s%s %s%s" % (Logs.colors(col), str, Logs.colors.NORMAL, label, sep))
def display(self): """log to term... mostly copied from waflib.Task.Task """ norm = Logs.colors.NORMAL bold = Logs.colors.BOLD dark = Logs.colors.BLACK col1 = Logs.colors(self.color) col2 = bold + col1 master = self.master def cur(): # the current task position, computed as late as possible tmp = -1 if hasattr(master, 'ready'): tmp -= master.ready.qsize() return master.processed + tmp if self.generator.bld.progress_bar == 1: return self.generator.bld.progress_line( cur(), master.total, col1, col2, ) if self.generator.bld.progress_bar == 2: ela = str(self.generator.bld.timer) try: ins = ','.join([n.name for n in self.inputs]) except AttributeError: ins = '' try: outs = ','.join([n.name for n in self.outputs]) except AttributeError: outs = '' return '|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n' % ( master.total, cur(), ins, outs, ela, ) total = master.total n = len(str(total)) n_min = (n * 2) + 2 n_mod = n_min % 4 n_buf = n_min + n_mod pfx = ' '*n_buf sp = ' '*2 env = self.env src_str = ('\n'+pfx).join([a.nice_path() for a in self.inputs]) tgt_str = ('\n'+pfx+sp).join([a.nice_path() for a in self.outputs]) sep0 = sep1 = '' if self.inputs: sep0 = '\n'+norm+col1+pfx if self.outputs: sep1 = '\n'+norm+col1+pfx+sp name = str(self) dist = getattr(self, 'dist', None) if dist: name = '%s%s %s%s' % ( name, dark, norm, dist.name_and_version ) s = '%s%s%s%s%s\n' % (name, sep0, src_str, sep1, tgt_str) fs = '%s%%%dd/%%%dd%s%s %%s%%s%%s' % (' '*n_mod, n, n, bold, dark) out = fs % (cur(), total, col2, s, norm) sys.stderr.write(out) return ''