def getVersionsAvailable(sitRootPath): """ Returns a list of strings with the RTMaps versions installed in the specified SIT, e.g. ['4.20', '4.21'] """ Any.requireIsDir(sitRootPath) installBaseDir = os.path.join(sitRootPath, 'External', 'RTMaps') Any.requireIsDirNonEmpty(installBaseDir) resultList = FastScript.getDirsInDir(installBaseDir) Any.requireIsListNonEmpty(resultList) return resultList
def copyBasePackages(srcRoot, dstRoot, packageList, verbose=True, ignore=None, resolveLTS=False, cacheDir=None): """ Copies all packages in the 'packageList' from the current srcRoot into dstRoot. Use the 'verbose' parameter to see/suppress a little progress information. 'ignore' might be a callable that will be given to shutil.copytree() for filtering-out undesired content. 'resolveLTS' indicates whether or not symlinks to LTS packages shall be resolved: True = copy content of LTS packages (resolve symlinks) False = keep LTS symlinks as they are If 'cacheDir' points to a SIT-like directory, packages aren't copied but instead linked there to speed-up, e.g. while debugging. """ Any.requireIsDir(srcRoot) Any.requireIsDir(dstRoot) Any.requireIsBool(verbose) Any.requireIsBool(resolveLTS) if ignore is not None: Any.requireIsCallable(ignore) if cacheDir is not None: Any.requireIsDirNonEmpty(cacheDir) for package in packageList: if cacheDir: symlink = os.path.join(dstRoot, package) target = os.path.join(cacheDir, package) FastScript.link(target, symlink) else: src = os.path.join(srcRoot, package) dst = os.path.join(dstRoot, package) _copyBasePackage(src, dst, verbose, ignore, resolveLTS)
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 codeCheck(klocworkDir='klocwork', stdout=None, stderr=None): """ Performs a CLI-analysis of the project. Note that the Klocwork-project must have been created before, e.g. using createLocalProject(). """ Any.requireIsDirNonEmpty(klocworkDir) requireOutsideTmpDir() ProcessEnv.source(ToolBOSSettings.getConfigOption('package_klocwork')) kwlpDir = os.path.join(klocworkDir, '.kwlp') Any.requireIsDirNonEmpty(kwlpDir) cmd = 'kwcheck run -pd %s' % kwlpDir FastScript.execProgram(cmd, stdout=stdout, stderr=stderr)
def test_makeDocumentation( self ): tmpDir = tempfile.mkdtemp( prefix='test-' ) packageName = 'HelloWorld' packageVersion = '42.0' projectRoot = os.path.join( tmpDir, packageName, packageVersion ) # create package on-the-fly PackageCreator_C_Library( packageName, packageVersion, outputDir=tmpDir ).run() Any.requireIsDirNonEmpty( tmpDir ) # create docu output = StringIO() if Any.getDebugLevel() <= 3 else None d = DocumentationCreator( projectRoot, stdout=output, stderr=output ) d.generate() # check result Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'doc' ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'doc/html' ) ) Any.requireIsFileNonEmpty( os.path.join( projectRoot, 'doc/html/index.html' ) ) Any.requireIsFileNonEmpty( os.path.join( projectRoot, 'doc/html/doxygen.css' ) ) Any.requireIsFileNonEmpty( os.path.join( projectRoot, 'doc/html/doxygen.png' ) ) FastScript.remove( tmpDir )
def __init__(self): appName = 'ToolBOS' tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT') defaultDir = os.path.join(tcRoot, 'etc') userDir = os.path.join(os.path.expanduser('~'), '.HRI', appName) addFiles = [] # integrate settings from other ToolBOS and user specified packages, if present mwRoot = FastScript.getEnv('TOOLBOSMIDDLEWARE_ROOT') toolBOSConfPaths = FastScript.getEnv('TOOLBOSCONF_PATH') if mwRoot: Any.requireIsDirNonEmpty(mwRoot) mwFile = os.path.join(mwRoot, 'etc', 'ToolBOS-Middleware.conf') if os.path.exists(mwFile): logging.debug('found ToolBOS Middleware in %s', mwRoot) addFiles.append(mwFile) if toolBOSConfPaths: Any.requireIsText(toolBOSConfPaths) toolBOSConfDirs = toolBOSConfPaths.split(':') for path in toolBOSConfDirs: filePath = os.path.join(path, 'ToolBOS.conf') if os.path.exists(filePath): logging.debug('found %s', filePath) addFiles.append(filePath) if not addFiles: addFiles = None super(ToolBOSConf, self).__init__(appName, defaultDir, userDir, addFiles=addFiles)
def _detectModulePath( self ): # in out-of-tree build situations add the source-directory's # ToolBOS.conf to the extra search path for "getConfigOption()" # (TBCORE-1052) tconfExtraDir = [ self._sourceTree ] if self._outOfTree else None if tconfExtraDir: logging.debug( 'registering extra ToolBOS.conf dir: %s', tconfExtraDir ) cmakeModPath = getConfigOption( 'BST_modulePath', tconfExtraDir ) cmakeModPath = FastScript.expandVars( cmakeModPath ) if self._outOfTree and not os.path.isabs( cmakeModPath ): cmakeModPath = os.path.abspath( os.path.join( self._sourceTree, cmakeModPath ) ) try: Any.requireIsDirNonEmpty( cmakeModPath ) except AssertionError as details: logging.error( 'invalid setting of BST_modulePath in ToolBOS.conf' ) logging.error( details ) raise self._cmakeModPath = cmakeModPath
def test_wineMSVC( self ): oldcwd = os.getcwd() tmpDir = tempfile.mkdtemp( prefix='test-' ) packageName = 'HelloWorld' packageVersion = '42.0' projectRoot = os.path.join( tmpDir, packageName, packageVersion ) output = StringIO() if Any.getDebugLevel() <= 3 else None hostPlatform = Platforms.getHostPlatform() targetPlatform = 'windows-amd64-vs2012' if targetPlatform not in CrossCompilation.getSwitchEnvironmentList( hostPlatform ): self.skipTest( '%s to %s cross-compilation not supported' % \ ( hostPlatform, targetPlatform ) ) # create package on-the-fly PackageCreator_C_Library( packageName, packageVersion, outputDir=tmpDir ).run() # build package FastScript.changeDirectory( projectRoot ) bst = BuildSystemTools() bst.setStdOut( output ) bst.setStdErr( output ) bst.setTargetPlatform( targetPlatform ) bst.compile() # check result Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'build' ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'build', targetPlatform ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'lib' ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'lib', targetPlatform ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'src' ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'test' ) ) Any.requireIsDirNonEmpty( os.path.join( projectRoot, 'test', targetPlatform ) ) # clean-up bst.distclean() self.assertFalse( os.path.exists( os.path.join( projectRoot, 'build' ) ) ) self.assertFalse( os.path.exists( os.path.join( projectRoot, 'lib' ) ) ) FastScript.remove( tmpDir ) FastScript.changeDirectory( oldcwd )
def test_nativeCompilation(self): oldcwd = os.getcwd() tmpDir = tempfile.mkdtemp(prefix='test-') packageName = 'HelloWorld' packageVersion = '42.0' projectRoot = os.path.join(tmpDir, packageName, packageVersion) output = StringIO() if Any.getDebugLevel() <= 3 else None platform = Platforms.getHostPlatform() # create package on-the-fly PackageCreator_C_Library(packageName, packageVersion, outputDir=tmpDir).run() # build package FastScript.changeDirectory(projectRoot) bst = BuildSystemTools() bst.setStdOut(output) bst.setStdErr(output) bst.compile() # check result Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'build')) Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'build', platform)) Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'lib')) Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'lib', platform)) Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'src')) Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'test')) Any.requireIsDirNonEmpty(os.path.join(projectRoot, 'test', platform)) # clean-up bst.distclean() self.assertFalse(os.path.exists(os.path.join(projectRoot, 'build'))) self.assertFalse(os.path.exists(os.path.join(projectRoot, 'lib'))) FastScript.remove(tmpDir) FastScript.changeDirectory(oldcwd)
for candidate in Platforms.getPlatformNames(): result = result.replace(candidate, '${MAKEFILE_PLATFORM}') return result #---------------------------------------------------------------------------- # Main program #---------------------------------------------------------------------------- tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT') hostPlatform = Platforms.getHostPlatform() binDirNoArch = os.path.join(tcRoot, 'bin') Any.requireIsDirNonEmpty(binDirNoArch) # unset VERBOSE and BST_BUILD_JOBS make output comparable origEnv = FastScript.getEnv() FastScript.unsetEnv('VERBOSE') FastScript.unsetEnv('BST_BUILD_JOBS') pyScripts = glob.glob(os.path.join(binDirNoArch, '*.py')) shScripts = glob.glob(os.path.join(binDirNoArch, '*.sh')) executables = glob.glob(os.path.join(binDirNoArch, hostPlatform, '*')) for program in pyScripts + shScripts + executables: basename = os.path.basename(program) Any.requireIsTextNonEmpty(basename)
def test_proxyInstallation(self): oldcwd = os.getcwd() packageName = 'ExamplePackage' packageVersion = '1.0' category = 'Applications' projectRoot = os.path.join('.', packageName, packageVersion) output = StringIO() if Any.getDebugLevel() <= 3 else None platform = Platforms.getHostPlatform() sitPath = SIT.getPath() # build + install package FastScript.changeDirectory(projectRoot) bst = BuildSystemTools() bst.setStdOut(output) bst.setStdErr(output) bst.compile() Any.requireIsDirNonEmpty('build') Any.requireIsDirNonEmpty(os.path.join('build', platform)) Any.requireIsDirNonEmpty('examples') Any.requireIsDirNonEmpty(os.path.join('examples', platform)) for fileName in ('ThreadingExampleAtomicOperation', 'ThreadingExampleJoin', 'ThreadingExampleTraps'): Any.requireIsFileNonEmpty(os.path.join('bin', platform, fileName)) if not ProxyDir.isProxyDir(sitPath): self.skip("%s: Is not a proxy directory" % sitPath) bst.makeDocumentation() bst.proxyInstall() installRoot = os.path.join(sitPath, category, packageName, packageVersion) # check result Any.requireIsDir(installRoot) Any.requireIsDirNonEmpty(os.path.join(installRoot, 'bin', platform)) Any.requireIsDirNonEmpty(os.path.join(installRoot, 'doc/html')) Any.requireIsFileNonEmpty( os.path.join(installRoot, 'doc/html/index.html')) Any.requireIsFileNonEmpty(os.path.join(installRoot, 'pkgInfo.py')) Any.requireIsFileNonEmpty(os.path.join(installRoot, 'packageVar.cmake')) for fileName in ('ThreadingExampleAtomicOperation', 'ThreadingExampleJoin', 'ThreadingExampleTraps'): Any.requireIsFileNonEmpty( os.path.join(installRoot, 'bin', platform, fileName)) # clean-up bst.uninstall(cleanGlobalInstallation=False) bst.distclean() self.assertFalse(os.path.exists(installRoot)) FastScript.changeDirectory(oldcwd)
def getCDefinesAsString(targetPlatform, targetName): """ Returns a long string with all compiler definitions set for the package using the addDefinitions() directive. This means all definitions passed to the compiler in the given path (beside system defaults), in the form "-DDEFINE1 -DFOO=BAR...". If no additional definitions are set, an empty string will be returned. NOTE: CMake supports that compiler definitions may be different for various target platforms, and even per executable and/or library. Therefore you need to specify both of them. A rule of thumb is targetName='<PROJECTNAME>-global'. """ Any.requireIsTextNonEmpty(targetPlatform) Any.requireIsTextNonEmpty(targetName) fileName = os.path.join('build/%s/CMakeFiles/%s.dir/flags.make' % (targetPlatform, targetName)) Any.requireIsDirNonEmpty('build/%s' % targetPlatform) Any.requireIsFileNonEmpty(fileName) # read-in ground truth information logging.debug('parsing %s' % fileName) content = FastScript.getFileContent(fileName, splitLines=True) raw_C = '' raw_CPP = '' raw_C_CFLAGS = '' raw_CPP_CFLAGS = '' regexp_C = re.compile('^C_DEFINES\s=\s+(.*)$') regexp_CPP = re.compile('^CXX_DEFINES\s=\s+(.*)$') regexp_C_CFLAGS = re.compile('^C_FLAGS\s=\s+(.*)$') regexp_CPP_CFLAGS = re.compile('^CXX_FLAGS\s=\s+(.*)$') result = '' for line in content: tmp = regexp_C.search(line) if tmp: raw_C = tmp.group(1) # logging.debug( 'raw C defines: %s' % raw_C ) tmp = regexp_CPP.search(line) if tmp: raw_CPP = tmp.group(1) # logging.debug( 'raw CPP defines: %s' % raw_CPP ) tmp = regexp_C_CFLAGS.search(line) if tmp: raw_C_CFLAGS = tmp.group(1) tmp = regexp_CPP_CFLAGS.search(line) if tmp: raw_CPP_CFLAGS = tmp.group(1) candidates = (shlex.split(raw_C) + shlex.split(raw_CPP) + shlex.split(raw_C_CFLAGS) + shlex.split(raw_CPP_CFLAGS)) for candidate in candidates: if candidate.startswith('-D'): result += candidate + ' ' return result