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 )
Esempio n. 2
0
    def makeDocumentation( self ):
        from ToolBOSCore.BuildSystem.DocumentationCreator import DocumentationCreator

        if self._outOfTree:
            logging.warning( 'documentation creation in out-of-tree build not implemented' )
            return False


        if Any.getDebugLevel() <= 3:
            from six import StringIO

            # capture output so that it's not printed
            output = StringIO()
        else:
            output = None


        try:
            dstSIT = SIT.getPath()

            dc = DocumentationCreator( self._sourceTree, dstSIT, output, output )
            dc.generate()

        except AssertionError as e:

            logging.error( 'failed to create documentation: %s', e )
            return False

        except subprocess.CalledProcessError:

            if output:
                print( output.getvalue() )

            logging.error( 'failed to create documentation' )
            return False
Esempio n. 3
0
def _checkForUpdates():
    """
        Check if there are any updates for this package.
    """
    from ToolBOSCore.CIA.PatchSystem import PatchSystem

    logging.debug('checking for updates')

    oldDebugLevel = Any.getDebugLevel()
    Any.setDebugLevel(1)

    patcher = PatchSystem()
    result = patcher.run(dryRun=True)

    Any.setDebugLevel(oldDebugLevel)

    if len(result) > 0:
        logging.info('')
        logging.info('\033[7;37m\033[1;31m' + ' ' * 60 + '\033[0m')
        logging.info(
            '\033[1;31mupdates are available for this package:\033[0m')

        for patch in result:
            logging.info('  - %s', patch[0])

        logging.info('')
        logging.info('')
        logging.info(
            '\033[0;31mYou may apply them using "BST.py --upgrade".\033[0m')
        logging.info('\033[7;37m\033[1;31m' + ' ' * 60 + '\033[0m')
        logging.info('')
    else:
        logging.debug('no need to patch')
Esempio n. 4
0
    def _assembleScriptCmd( self, name ):
        Any.requireIsTextNonEmpty( name )

        # When compiling natively, under Linux the *.sh and on Windows the
        # *.bat needs to be executed.
        #
        # But also when cross-compiling we need to execute the script for
        # the host platform, f.i. a Windows *.bat script won't work on
        # Linux.
        #
        # Hence there is no need to check for the targetPlatform at all,
        # see TBCORE-1217.

        if self._hostPlatform.startswith( 'windows' ):
            filename = '%s.bat' % name
            cmd      = filename
        else:
            filename = '%s.sh' % name

            if Any.getDebugLevel() > 3:
                cmd = 'bash -x ./%s' % filename
            else:
                cmd = './' + filename

        return filename, cmd
Esempio n. 5
0
def isExcludedFromCIA(package):
    """
        Checks from the filesystem if the specified package (canonical path)
        is flagged as being opted-out from the Continuous Integration
        system.

        The function checks if "excludeFromCIA = True" is specified in
        the pkgInfo.py of the installed package.
    """
    from ToolBOSCore.Storage.PkgInfo import getPkgInfoContent

    status = False

    # temporarily disable verbosity, to prevent flooding CIA log
    oldLevel = Any.getDebugLevel()
    Any.setDebugLevel(3)

    try:
        pkgInfo = getPkgInfoContent(package)

        if pkgInfo['excludeFromCIA']:
            status = True

    except (AssertionError, IOError, KeyError):
        # if pkgInfo.py not present, the package surely was not opted-out
        pass

    Any.setDebugLevel(oldLevel)

    return status
    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)
Esempio n. 7
0
    def run(self):
        progressLog = StringIO()
        debugLevel = logging.DEBUG if Any.getDebugLevel() > 3 else logging.INFO

        Any.addStreamLogger(progressLog, debugLevel, False)

        PackageCreator.runTemplate(self.templateName, self.packageName,
                                   self.packageVersion)

        self.newOutput.emit(progressLog.getvalue())
def _setDebugLevel(libHandle):
    """
        If the library makes use of ToolBOS's ANY_LOG framework, set the
        debug level appropriately according to the debugLevel used in Python.
    """
    Any.requireIsInstance(libHandle, ctypes.CDLL)

    try:
        debugLevel = Any.getDebugLevel()

        # Any.py logs at maximum level 5 while the Any.c logs up to infinity.
        # therefore we generally suppress setting the loglevel if above 5.

        if debugLevel < 5:
            libHandle.Any_setDebugLevel(Any.getDebugLevel())

        libHandle.Any_setShortLogFormat()

    except AttributeError:
        # likely does not link against ToolBOSCore library
        pass
    def __init__( self, parent=None ):
        super( QGroupBox, self ).__init__( 'options', parent )

        self._verboseOption   = QCheckBox( '&verbose' )
        self._verboseOption.setChecked( Any.getDebugLevel() > 3 )
        self._verboseOption.setToolTip( 'show debug messages?' )

        self._parallelOption  = QCheckBox( 'parallel jobs:' )
        self._parallelValue   = QLineEdit()
        self._parallelWidget  = QWidget()
        self._parallelLayout  = QHBoxLayout()

        jobs = FastScript.getEnv( 'BST_BUILD_JOBS' )

        if jobs:
            if jobs == '1':
                self._parallelOption.setChecked( False )
                self._parallelValue.setEnabled( False )
                self._parallelValue.setText( '32' ) # 1 would be a bad default
            else:
                self._parallelOption.setChecked( True )
                self._parallelValue.setEnabled( True )
                self._parallelValue.setText( jobs )
        else:
            self._parallelOption.setChecked( False )
            self._parallelValue.setEnabled( False )
            self._parallelValue.setText( '32' )     # default parallelization

        self._parallelOption.setToolTip( 'parallel build ("-j" option)' )
        # noinspection PyUnresolvedReferences
        self._parallelOption.stateChanged.connect( self._onParallelOption )
        self._parallelValue.setValidator( QIntValidator( 1, 99, self._parallelWidget ) )
        self._parallelValue.setMaxLength( 2 )
        self._parallelValue.setMaximumWidth( 30 )
        self._parallelValue.setToolTip( 'number of parallel build jobs' )
        self._parallelValue.resize( 0, 0 )

        self._parallelLayout.setAlignment( Qt.AlignLeft )
        self._parallelLayout.addWidget( self._parallelOption )
        self._parallelLayout.addWidget( self._parallelValue )
        self._parallelLayout.addStretch( 1 )
        self._parallelLayout.setContentsMargins( 0, 0, 0, 0 )   # no add. margin
        self._parallelWidget.setLayout( self._parallelLayout )

        layout = QVBoxLayout()
        layout.addWidget( self._verboseOption )
        layout.addWidget( self._parallelWidget )

        self.setLayout( layout )
Esempio n. 10
0
def ErrorDialog(title, msg, printException=False):
    msg = str(msg)  # also accept exception types

    Any.requireIsTextNonEmpty(title)
    Any.requireIsTextNonEmpty(msg)

    if printException or Any.getDebugLevel() >= 5:
        excType, _excValue, excTraceback = sys.exc_info()
        tbs = traceback.format_tb(excTraceback)

        logging.error('%s, %s', excType, msg)
        logging.error(''.join(tbs))
    else:
        logging.error(msg)

    QMessageBox.critical(None, title, msg, QMessageBox.Ok)
    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 )
Esempio n. 12
0
        def run(self):

            # suppress dry-run patching output
            oldDebugLevel = Any.getDebugLevel()
            Any.setDebugLevel(1)

            try:
                patchesAvailable = PatchSystem().run(dryRun=True)
            except AssertionError as e:
                # e.g. templates not installed, let's gnore this case
                logging.debug(e)
                patchesAvailable = False

            Any.setDebugLevel(oldDebugLevel)

            if patchesAvailable:
                logging.debug('patches available')
                self.updatesAvailable.emit()
Esempio n. 13
0
    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)
Esempio n. 14
0
    def test_jsonSerialization(self):
        bbmlFile = 'TestSerializeToJSON.bbml'
        cmlFile = 'TestSerializeToJSON.cml'
        outputFile = 'serialized.json'

        # run RTBOS to create JSON-serialized output file
        Any.requireIsFileNonEmpty(bbmlFile)
        cmd = 'RTBOS.sh %s' % bbmlFile
        output = StringIO() if Any.getDebugLevel() <= 3 else None
        FastScript.remove(outputFile)  # ensure it's not there
        FastScript.execProgram(cmd, stdout=output, stderr=output)

        # verify output file has been created
        Any.requireIsFileNonEmpty(outputFile)

        # check result
        data = json.load(open(outputFile))
        arrayBlock = data['bBDMArrayBlockF32']

        self.assertEqual(arrayBlock['m_dims'], 1)
        self.assertEqual(arrayBlock['m_totalSize'], 2)
        self.assertEqual(len(arrayBlock['m_data']), arrayBlock['m_totalSize'])
        self.assertEqual(
            arrayBlock['elementsPerDimension']['elementsPerDimension'],
            [2, 0, 0, 0])

        for block in arrayBlock['m_data']:
            self.assertEqual(block['owner'], 1)
            self.assertEqual(len(block['data']['data']), 16)
            self.assertEqual(block['size']['width'], 4)
            self.assertEqual(block['size']['height'], 4)

        # clean-up
        FastScript.remove('LibIndex')
        FastScript.remove(outputFile)
        FastScript.remove(cmlFile)
#----------------------------------------------------------------------------
# Main program
#----------------------------------------------------------------------------


BuildSystemTools.requireTopLevelDir()


ProcessEnv.source( ToolBOSSettings.getConfigOption( 'package_pycharm' ) )


try:
    #PyCharm.createUserConfig()

    logging.info( 'creating config in ./.idea' )
    PyCharm.createProject()
    FastScript.prettyPrintError( 'Now please execute: runPyCharm.sh' )

except ( AssertionError, RuntimeError ) as details:
    logging.error( details )

    # show stacktrace in verbose mode
    if Any.getDebugLevel() >= 5:
        raise

    sys.exit( -1 )


# EOF
Esempio n. 16
0
def codeCheck():
    """
        Performs a static source code analysis using PyCharm's built-in
        code inspector.

        The default inspection profile of the project is used, which unless
        modified by the developer will be the common HRI-EU profile coming
        from CreatePyCharmProject.py

        If there is no ".idea" directory in the current directory, it will
        be temporarily created and deleted when finished.

        @returns: defects as list of XML strings

        @see: parseCodeCheckResult()

    """
    ProcessEnv.source(ToolBOSSettings.getConfigOption('package_pycharm'))

    output = StringIO()
    FastScript.execProgram('ps aux', stdout=output, stderr=output)

    if output.getvalue().find('pycharm') > 0:
        raise RuntimeError(
            'PyCharm already running, unable to invoke code checker')

    # create project files if not existing
    if os.path.exists('.idea'):
        created = False
    else:
        created = True
        #createUserConfig()
        createProject()

    resultsDir = 'build/PY05'
    FastScript.remove(resultsDir)
    FastScript.mkdir(resultsDir)

    output.truncate(0)

    cmd = 'inspect.sh . HRI-EU %s' % resultsDir

    try:
        logging.info('running analysis...')
        FastScript.execProgram(cmd, stdout=output, stderr=output)

        if Any.getDebugLevel() > 3:
            logging.info('\n' + output.getvalue())

    except subprocess.CalledProcessError:
        if output.getvalue().find('No valid license found') > 0:
            raise RuntimeError('PyCharm: No valid license found')
        else:
            raise RuntimeError(output.getvalue())

    # delete project files if we have created them
    if created:
        FastScript.remove('.idea')

    resultList = []

    for filePath in glob.glob('build/PY05/*.xml'):
        Any.requireIsFile(filePath)
        content = FastScript.getFileContent(filePath)

        resultList.append(content)

    return resultList