def test_helpText(self): tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT') hostPlatform = Platforms.getHostPlatform() binDirNoArch = os.path.join(tcRoot, 'bin') Any.requireIsDirNonEmpty(binDirNoArch) pyScripts = glob.glob(os.path.join(binDirNoArch, '*.py')) shScripts = glob.glob(os.path.join(binDirNoArch, '*.sh')) executables = glob.glob(os.path.join(binDirNoArch, hostPlatform, '*')) # unset VERBOSE and BST_BUILD_JOBS to make output comparable origEnv = FastScript.getEnv() FastScript.unsetEnv('VERBOSE') FastScript.unsetEnv('BST_BUILD_JOBS') for program in pyScripts + shScripts + executables: basename = os.path.basename(program) Any.requireIsTextNonEmpty(basename) logging.info('processing %s', basename) output = StringIO() cmd = '%s --help' % program fileName = os.path.join('ReferenceData', '%s.txt' % basename) Any.requireIsTextNonEmpty(cmd) Any.requireIsTextNonEmpty(fileName) FastScript.execProgram(cmd, stdout=output, stderr=output) expected = FastScript.getFileContent(fileName) result = normalizeOutput(output.getvalue()) Any.isTextNonEmpty(expected) Any.isTextNonEmpty(result) if result != expected: logging.info('differences in output of %s:', basename) logging.info('<result>\n%s', result) logging.info('</result>') logging.info('<expected>\n%s', expected) logging.info('</expected>') self.fail('help text of %s differs' % basename) FastScript.setEnv(origEnv)
def _readFile(self, filePath): if os.path.exists(filePath): if os.path.isfile(filePath): try: logging.debug('evaluating %s', filePath) result = {} allSymbols = FastScript.execFile(filePath) # remove Python modules, callables etc. from dict for key, value in allSymbols.items(): if Any.isTextNonEmpty(key): result[key] = value except (AssertionError, IOError, OSError) as e: logging.error(e) result = {} else: logging.error('%s: Not a regular file', filePath) result = {} else: # logging.debug( '%s: No such file', filePath ) result = {} return result
def getConfigOptions(addPaths=None): """ Returns a dict with all config options and their values. The master-list of available config options is defined in etc/ToolBOS.conf (the fallback list shipped with ToolBOS SDK). To search in non-standard locations provide a list 'addPaths'. Its path entries will be searched right after ./ToolBOS.conf. """ allSymbols = {} # do in reverse order (starting from default), and update step-by-step # with the higher-priority settings order = _getEvalOrder(addPaths) order.reverse() for fileName in order: try: fileSymbols = FastScript.execFile(fileName) logging.debug('evaluating %s', fileName) except (AssertionError, IOError, OSError): fileSymbols = {} allSymbols.update(fileSymbols) # remove Python modules, callables etc. from dict result = {} for key, value in allSymbols.items(): if Any.isTextNonEmpty(key) and not Any.isCallable(value): result[key] = value return result
def collapseHGR(string): """ Returns all computable values of HRI_GLOBAL_ROOT with an ${HRI_GLOBAL_ROOT} placeholder. Deprecated: $HRI_GLOBAL_ROOT is not supposed to be used anymore. If not defined this function uses the value of $SIT instead. """ envValue = FastScript.getEnv('HRI_GLOBAL_ROOT') # may no longer be defined, if so we use $SIT if not envValue: envValue = FastScript.getEnv('SIT') if not Any.isTextNonEmpty(envValue): raise EnvironmentError("Environment variable $SIT not defined") # replace all occurrences of ${HRI_GLOBAL_ROOT} or its value tmp = FastScript.collapseVar(string, 'HRI_GLOBAL_ROOT') # if existing, replace the path where ${HRI_GLOBAL_ROOT}/parentTree points to linkName = os.path.join(envValue, parentLink) try: linkTarget = os.readlink(linkName) tmp = tmp.replace(linkTarget + '/', '') except ( OSError, # probably has no such link AttributeError): # os.readlink n/a on Windows pass return tmp
def _parseDependDotMake(targetBuildDir, platformBuildDir): """ Returns a dictionary mapping header files to the set of language files that use it. The dictionary is obtained parsing the file build/<targetPlatform>/CMakeFiles/<targetName>.dir/depend.make """ Any.requireIsTextNonEmpty(targetBuildDir) Any.requireIsTextNonEmpty(platformBuildDir) dependDotMakePath = os.path.join(targetBuildDir, 'depend.make') lines = FastScript.getFileContent(dependDotMakePath, splitLines=True) result = collections.defaultdict(set) languageNormalizationMap = { '.c': 'c', '.C': 'c++', '.CC': 'c++', '.CPP': 'c++', '.CXX': 'c++', '.cc': 'c++', '.cpp': 'c++', '.cxx': 'c++', } for l in lines: # skip comments and empty lines if Any.isTextNonEmpty(l) and not l.startswith('#'): # lines are in the format # /path/to/obj/file.{c,cpp,cc,cxx}.o: /path/to/dependencyfile.{c,cpp,cc,cxx,h,hpp,hxx,hh} objFile, depFile = l.split(':') srcFile, objExt = os.path.splitext(objFile.strip()) srcName, srcExt = os.path.splitext(srcFile) depFile = depFile.strip() _, depFileExt = os.path.splitext(depFile) language = languageNormalizationMap[srcExt] if depFileExt.lower() in ('.h', '.hxx', '.hpp', '.hh'): if not os.path.isabs(depFile): relPath = os.path.join(platformBuildDir, depFile) absPath = os.path.abspath(relPath) else: absPath = depFile result[absPath].add(language) return result
def getEnvChk(varName, default=None): """ Like FastScript.getEnv, with additional support for a default parameter. If the requested 'varName' is not found in the environment and no default parameter is specified, an EnvironmentError is raised. """ Any.requireIsTextNonEmpty(varName) value = getEnv(varName) if value is None: if default is None: if not Any.isTextNonEmpty(value): raise EnvironmentError('%s: empty environment variable' % varName) else: return default else: return value