Example #1
0
    def test_makeShellfiles(self):
        projectRoot = FastScript.getEnv('TOOLBOSCORE_ROOT')
        installDir = os.path.join(projectRoot, 'install')
        fileNamePrefix = ToolBOSSettings.packageName + '-'

        # create shellfiles
        makeShellfiles(projectRoot)

        # check result
        for fileName in ('pkgInfo.py', 'BashSrc', 'CmdSrc.bat'):
            expectedFile = fileNamePrefix + fileName
            resultFile = os.path.join(installDir, fileName)

            logging.info('expecting content as in: %s' % expectedFile)
            logging.info('comparing with:          %s' % resultFile)

            expectedContent = FastScript.getFileContent(expectedFile)
            resultContent = FastScript.getFileContent(resultFile)

            # check if each line occurs in 'resultContent', except the line
            # of the SVN revision as this frequently changes
            for line in expectedContent.splitlines():
                if not line.startswith('revision'):
                    try:
                        self.assertTrue(resultContent.find(line) != -1)
                    except AssertionError:
                        logging.error('line not found: %s' % line)
                        raise
    def _patchCIA977( self, dryRun=False ):
        """
            Updates the Makefile of a BBCM component to call "MakeBBCM.py"
            instead of "RunTemplate.php".
        """
        if not self.details.isBBCM():
            logging.debug( 'package is not a BBCM' )
            return False

        srcFile    = os.path.join( PackageCreator.templateDir, 'C_BBCM', 'Makefile' )
        dstFile    = 'Makefile'

        if not os.path.exists( dstFile ):
            logging.debug( 'package has no Makefile, patch does not apply' )
            return False

        srcContent = FastScript.getFileContent( srcFile )
        dstContent = FastScript.getFileContent( dstFile )

        if srcContent != dstContent:
            if not dryRun:
                FastScript.copy( srcFile, dstFile )
            else:
                logging.debug( '[DRY-RUN] cp %s %s', srcFile, dstFile )

            return [ dstFile ]
        else:
            return False
Example #3
0
    def _parseCMakeLists(self):
        if self.hasCMakeLists:
            filename = os.path.join(self.topLevelDir, 'CMakeLists.txt')
            logging.debug('reading %s', filename)

            content = FastScript.getFileContent(filename)
            self.dependencies = CMakeLists.getDependencies(content)
    def __init__(self, details=None):
        """
            Allows modifying an existing pkgInfo.py file, f.i. add/remove
            entries.

            Multiple changes can be applied in a row. The actual re-writing
            of the file is done using write().

            We attempt to modify the package in the current working directory
            unless another PackageDetector class is provided.
        """
        if details is not None:
            Any.requireIsInstance(details, PackageDetector)
            self._details = details
        else:
            self._details = PackageDetector()

        self._filePath = os.path.join(self._details.topLevelDir, 'pkgInfo.py')
        self._worker = PkgInfoWriter(self._details, sourceTree=True)

        try:
            self._content = FastScript.getFileContent(self._filePath)
            self.checkSyntax()
            self._data = getPkgInfoContent(dirName=self._details.topLevelDir)

        except IOError:
            self._content = self._worker.addLeadIn()

        except SyntaxError:
            raise
Example #5
0
    def _createMainDoxyfile(self):

        if self.details.isPythonPackage() and \
           getConfigOption( 'BST_useDoxypy' ) == True:
            fileName = 'Doxyfile-Python'
        else:
            fileName = 'Doxyfile'

        content = ''
        template = os.path.join(FastScript.getEnv('TOOLBOSCORE_ROOT'), 'etc',
                                fileName)
        Any.requireIsFileNonEmpty(template)

        if os.path.isdir(os.path.join(self.details.topLevelDir, 'examples')):
            logging.debug('doxygen: indexing examples')
            content += 'EXAMPLE_PATH           = ../examples\n' + \
                       'EXAMPLE_PATTERNS       =\n' + \
                       'EXAMPLE_RECURSIVE      = YES\n'

        if self.details.isComponent():
            logging.debug('doxygen: indexing src/*.{c,cpp}')
            content += 'FILE_PATTERNS          = *.c *.cpp *.h\n'

        content = FastScript.getFileContent(template) + content
        FastScript.setFileContent(self.mainDoxyfile, content)
 def setContent(self, filePath):
     """
         Allows setting content from original file, in order to evolve an
         existing pkgInfo.py over time.
     """
     Any.requireIsFileNonEmpty(filePath)
     self.content = FastScript.getFileContent(filePath)
        def check( fileName ):
            Any.requireIsFile( fileName )

            content = FastScript.getFileContent( fileName )

            return content.find( old1 ) != -1 or \
                   content.find( old2 ) != -1
    def test_addGlobalInstallLog( self ):
        msgType  = 'NEW'
        message  = 'Test message (unittest)'


        # create log entry
        logEntry = GlobalInstallLog( ToolBOSSettings.canonicalPath,
                                     isFirstInstall=False,
                                     msgType=msgType,
                                     message=message )
        fileName = tempfile.mkstemp( prefix='test-' )[1]
        logEntry.setFileName( fileName )
        logEntry.writeFile()

        Any.requireIsFileNonEmpty( fileName )
        content  = FastScript.getFileContent( fileName )


        # check result
        self.assertTrue( content.find( msgType ) > 0, "log file incorrect" )
        self.assertTrue( content.find( message ) > 0, "log file incorrect" )


        # clean-up
        FastScript.remove( fileName )
    def _patchCIA1147( self, dryRun=False ):
        """
            Remove obsolete BBCM_INFO_CATEGORY.
        """
        if not self.details.isBBCM():
            logging.debug( 'package is not a BBCM' )
            return False

        fileName = 'src/%s_info.c' % self.details.packageName

        if not os.path.exists( fileName ):
            return False


        lines      = FastScript.getFileContent( fileName, splitLines=True )
        modified   = []
        newContent = ''

        for line in lines:
            if line.startswith( 'BBCM_INFO_CATEGORY' ):
                modified.append( fileName )
            else:
                newContent += line

        if modified and dryRun is False:
            FastScript.setFileContent( fileName, newContent )


        return modified
    def _patchCIA955( self, dryRun=False ):
        """
            BST.py requires CMake 2.8.8 for building library packages.

            However the CMakeLists.txt template stated a minimum required
            version of "2.6" which should be replaced by "2.8.8" accordingly.

            Otherwise the user will receive strange error messages when trying
            to compile with an older version than 2.8.8.
        """
        fileName = 'CMakeLists.txt'
        old      = 'cmake_minimum_required(VERSION 2.6)'
        new      = 'cmake_minimum_required(VERSION 2.8.8)'
        status   = False

        # This patch is only necessary if the package is about building
        # libraries

        try:
            content = FastScript.getFileContent( fileName )
        except IOError:
            logging.debug( '%s: No such file' % fileName )
            return False


        if 'bst_build_libraries' in content or 'add_library' in content:
            status = self._replace( fileName, old, old, new, 'CIA-955', dryRun )
        else:
            logging.debug( 'neither bst_build_libraries() nor add_library() found' )

        if status:
            return [ fileName ]
Example #11
0
def getStdSwitches(targetPlatform, targetName):
    """
        Returns a string with the compiler std switch.

        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)

    # We need defaults because the macro parser needs the switch to
    # correctly parse c++ code.

    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_CFLAGS = ''
    raw_CPP_CFLAGS = ''
    regexp_C_CFLAGS = re.compile(r'^C_FLAGS\s=\s+(.*)$')
    regexp_CPP_CFLAGS = re.compile(r'^CXX_FLAGS\s=\s+(.*)$')

    for line in content:
        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)

    # get the default language standards
    standards = Compilers.getDefaultLanguageStandard(targetPlatform)
    cStdSwitch = '-std={}'.format(standards['c'])
    cppStdSwitch = '-std={}'.format(standards['c++'])

    # look if the user specified different standards in the C_FLAGS/CPP_FLAGS
    # CMake variables
    candidates = shlex.split(raw_C_CFLAGS)
    for candidate in candidates:
        if candidate.startswith('-std='):
            cStdSwitch = candidate

    candidates = shlex.split(raw_CPP_CFLAGS)
    for candidate in candidates:
        if candidate.startswith('-std='):
            cppStdSwitch = candidate

    return Switches(c=cStdSwitch, cpp=cppStdSwitch)
Example #12
0
def getConfigContent():
    """
        Returns the content of dtbos.cfg as list of strings.

        Returns empty list if dtbos.cfg does not exist.
    """
    try:
        return FastScript.getFileContent(getConfigFilePath(), splitLines=True)
    except AssertionError:
        return []
    def test_getDependenciesFromCMakeLists(self):
        testFile = 'TestCMakeLists.txt'
        expected = [
            'sit://DevelopmentTools/ToolBOSCore/2.0',
            'sit://Libraries/BPLBase/7.0', 'sit://Libraries/MasterClock/1.7'
        ]

        content = FastScript.getFileContent(testFile)
        returned = CMakeLists.getDependencies(content)

        self.assertEqual(expected, returned)
Example #14
0
def getIncludePathsAsString(targetPlatform, targetName):
    """
        Returns a long string with all include paths set for the package
        using include_directories() in CMakeLists.txt (in this package or
        included ones).

        This means all paths where the compiler would search for header
        files (beside system defaults), in the form "-I/path1 -I/path2...".

        If no additional paths are set, an empty string will be returned.

        NOTE: CMake supports that include directories 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 = ''
    regexp_C = re.compile('^(?:C_FLAGS|C_INCLUDES)\s=\s+(.*)$')
    regexp_CPP = re.compile('^(?:CXX_FLAGS|CXX_INCLUDES)\s=\s+(.*)$')
    result = ''

    for line in content:
        tmp = regexp_C.search(line)

        if tmp:
            raw_C = tmp.group(1)
            # logging.debug( 'raw C flags: %s' % raw_C )

        tmp = regexp_CPP.search(line)

        if tmp:
            raw_CPP = tmp.group(1)
            # logging.debug( 'raw CPP flags: %s' % raw_CPP )

    for candidate in (shlex.split(raw_C) + shlex.split(raw_CPP)):
        if candidate.startswith('-I'):
            result += candidate + ' '

    return result
Example #15
0
    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)
Example #16
0
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 _patchCIA1267( self, dryRun=False ):
        """
            Check files for outdated CSV keywords and remove
            these keywords and expanded information from the source code
        """
        files    = FastScript.getFilesInDirRecursive( 'bin' ) | \
                   FastScript.getFilesInDirRecursive( 'examples' ) | \
                   FastScript.getFilesInDirRecursive( 'src' ) | \
                   FastScript.getFilesInDirRecursive( 'test' )

        modified = []

        # CSV keywords
        keywords = frozenset( [ '$Author', '$Date', '$Header', '$Id', '$Log',
                                '$Locker', '$Name', '$RCSfile', '$Revision',
                                '$Source', '$State' ] )

        for filePath in files:
            rewrite     = False

            try:
                fileContent = FastScript.getFileContent( filename=filePath,
                                                         splitLines=True )
            except UnicodeDecodeError:
                # most probably we attempt to read a binary file,
                # e.g. a compiled executable under bin/ or the like
                continue

            # check each line for CSV keyword and remove line if found
            for line in fileContent:
                if any( key in line for key in keywords):
                    rewrite = True
                    fileContent.remove( line )

            if rewrite:
                if dryRun:
                    logging.info( '[DRY-RUN] patching %s', filePath )
                else:
                    logging.info( 'patching %s', filePath )
                    newContent = ''.join( fileContent )
                    FastScript.setFileContent( filePath, newContent )

                modified.append( filePath )

        return modified
Example #18
0
    def _msvc2012SpecificChecks():
        if not os.path.exists(os.path.join(configDir, 'user.reg')):
            setupWineDotNet(configDir, postfix)

        linkPath = os.path.join(configDir, 'drive_c', 'msvc-sdk')

        if not os.path.exists(linkPath):  # considers broken links
            logging.debug('%s not found', linkPath)
            setupMSVC(configDir, sdk)

        # sometimes it happens that the registry gets screwed up
        userReg = os.path.join(configDir, 'user.reg')
        Any.requireIsFileNonEmpty(userReg)
        content = FastScript.getFileContent(userReg)

        if content.find('1413877490') == -1:
            logging.debug('found broken registry: rebuilding %s', configDir)
            setupMSVC(configDir, sdk)
Example #19
0
    def test_serializeUtility_convert(self):
        tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT')
        platform = Platforms.getHostPlatform()
        exe = os.path.join(tcRoot, 'bin', platform, 'ConvertSerializedData')
        inFile = 'BBDMArrayBlockF32-binary.ser'
        outFile = tempfile.mkstemp(prefix='test-')[1]
        cmd = '%s -i %s -f Ascii -o %s' % (exe, inFile, outFile)
        tmp = StringIO()

        try:
            FastScript.execProgram(cmd, stdout=tmp, stderr=tmp)
        except OSError:
            raise RuntimeError("Please compile this package first!")

        output = tmp.getvalue()

        # typical error could be:
        #
        # [... SerializeUtility.c:809 Error] Could not load data library
        # 'BBDMArrayBlockF32' (libBBDMArrayBlockF32.so): Reason
        # 'libBBDMArrayBlockF32.so: cannot open shared object file:
        # No such file or directory'
        #
        # [... SerializeUtility.c:653 Error] The input file
        # 'test/miscInputFiles/BBDMArrayBlockF32-binary.ser'
        # does not contain valid data

        # check result
        self.assertTrue(output.find('libBBDMArrayBlockF32.so') == -1)
        self.assertTrue(output.find('Could not load data library') == -1)
        self.assertTrue(output.find('No such file or directory') == -1)
        self.assertTrue(
            output.find('Aborting serialization function') > 0)  # at EOF
        self.assertTrue(output.find('does not contain valid data') == -1)

        Any.requireIsFileNonEmpty(outFile)
        content = FastScript.getFileContent(outFile)

        # there must be 3x "HRIS" in the ASCII representation of this file
        matches = re.findall('HRIS', content)
        self.assertTrue(len(matches) == 3)

        # clean-up
        FastScript.remove(outFile)
Example #20
0
    def test_serializeUtility_createSerializedData(self):
        random.seed(self)

        tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT')
        platform = Platforms.getHostPlatform()
        exe = os.path.join(tcRoot, 'bin', platform, 'CreateSerializedData')
        count = random.randint(3, 20)
        outFile = tempfile.mkstemp(prefix='test-')[1]
        cmd = '%s -t BBDMArrayBlockF32 -c %d -r -f Ascii -o %s' % (exe, count,
                                                                   outFile)
        tmp = StringIO()

        try:
            FastScript.execProgram(cmd, stdout=tmp, stderr=tmp)
        except OSError:
            raise RuntimeError("Please compile this package first!")

        output = tmp.getvalue()

        # typical error could be:
        #
        # [... SerializeUtility.c:809 Error] Could not load data library
        # 'BBDMBaseF32' (libBBDMBaseF32.so): Reason 'libBBDMBaseF32.so:
        # cannot open shared object file: No such file or directory'
        #
        # SerializeUtility.c:1083 BBDMBaseF32: unsupported datatype
        # (BBDMBaseF32_new() not found)

        # check result
        self.assertTrue(output.find('libBBDMArrayBlockF32.so') == -1)
        self.assertTrue(output.find('cannot open shared object file') == -1)
        self.assertTrue(output.find('No such file or directory') == -1)
        self.assertTrue(output.find('unsupported datatype') == -1)

        Any.requireIsFileNonEmpty(outFile)
        content = FastScript.getFileContent(outFile)

        # we must find "count"-times the keyword "HRIS" inside the file
        matches = re.findall('HRIS', content)
        self.assertTrue(len(matches) == count)

        # clean-up
        FastScript.remove(outFile)
    def _patchCIA982( self, dryRun=False ):
        """
            Check (and evtl. set) a build-dependency if ToolBOSPluginMatlab
            is included within a separate CMakeLists.txt.
        """
        cmakeFile = 'wrapper/CMakeLists.txt'

        if not os.path.exists( cmakeFile ):
            logging.debug( '%s: No such file', cmakeFile )
            return False

        cmakeContent = FastScript.getFileContent( cmakeFile )
        Any.requireIsTextNonEmpty( cmakeContent )

        # check if dependencies included in the wrapper/CMakeLists.txt
        # appear in the normally detected depends/buildDepends sections
        #
        # if not, then add it at least as a build-dependency

        newBuildDeps = copy.copy( self.details.buildDependencies )

        for package in CMakeLists.getDependencies( cmakeContent ):
            Any.requireIsTextNonEmpty( package )

            if package not in self.details.dependencies and \
               package not in self.details.buildDependencies:
                logging.info( 'adding build-dependency: %s', package )

                newBuildDeps.append( package )


        # if some additional build-dependencies have been found then store
        # them into pkgInfo.py
        if self.details.buildDependencies != newBuildDeps:
            p = PkgInfoInterface( self.details )
            p.set( 'buildDepends', newBuildDeps )

            if not dryRun:
                p.write()

            return [ 'pkgInfo.py' ]
        else:
            return False
Example #22
0
def setupLegacyMSVC(configDir):
    from ToolBOSCore.Storage.SIT import getPath

    sitRootPath = getPath()
    packageName = 'Data/wine.net/0.1'
    handmadeDir = os.path.join(sitRootPath, packageName, 'config')
    userName = FastScript.getCurrentUserName()

    if not os.path.exists(handmadeDir):
        raise AssertionError('%s: No such package in SIT' % packageName)

    if not userName:
        raise AssertionError('Unable to query username :-(')

    # replace 'Program Files' and 'windows' directories in configDir by
    # symlinks to handmade directories in SIT

    for item in ('Program Files', 'windows'):
        path = os.path.join(configDir, 'drive_c', item)
        Any.requireIsDir(path)
        FastScript.remove(path)

        target = os.path.join(handmadeDir, 'drive_c', item)
        FastScript.link(target, path)

    # copy all the handmade *.reg files
    regFiles = glob.glob("%s/*.reg" % handmadeDir)
    Any.requireIsListNonEmpty(regFiles)

    for srcFilePath in regFiles:
        fileName = os.path.basename(srcFilePath)
        dstFilePath = os.path.join(configDir, fileName)

        logging.debug('cp %s %s', srcFilePath, dstFilePath)
        shutil.copyfile(srcFilePath, dstFilePath)
        Any.requireIsFileNonEmpty(dstFilePath)

        # replace occurrences of 'roberto' by username
        oldContent = FastScript.getFileContent(dstFilePath)
        newContent = oldContent.replace('roberto', userName)
        FastScript.setFileContent(dstFilePath, newContent)
Example #23
0
    def test_serializeUtility_printSerializedData(self):
        tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT')
        platform = Platforms.getHostPlatform()
        exe = os.path.join(tcRoot, 'bin', platform, 'PrintSerializedData')
        inFile = os.path.join('BBDMArrayBlockF32-binary.ser')
        outFile = os.path.join('BBDMArrayBlockF32-ascii.ser')
        cmd = '%s -f %s' % (exe, inFile)
        tmp = StringIO()

        Any.requireIsFileNonEmpty(inFile)
        Any.requireIsFileNonEmpty(outFile)

        try:
            # do not redirect stderr to file, otherwise we can't compare with
            # the expected output (ANY_LOG timestamps would differ), there is
            # at least stderr-message "Aborting serialization function" at EOF
            FastScript.execProgram(cmd, stdout=tmp)
        except OSError:
            raise RuntimeError("Please compile this package first!")

        expected = FastScript.getFileContent(outFile)
        output = tmp.getvalue()

        # typical error could be:
        #
        # [... SerializeUtility.c:809 Error] Could not load data library
        # 'BBDMArrayBlockF32' (libBBDMArrayBlockF32.so): Reason
        # 'libBBDMArrayBlockF32.so: cannot open shared object file:
        # No such file or directory'
        #
        # [... SerializeUtility.c:591 Error] The input file
        # 'test/miscInputFiles/BBDMArrayBlockF32-binary.ser' does not
        # contain valid data

        # check result
        self.assertTrue(output.find('libBBDMArrayBlockF32.so') == -1)
        self.assertTrue(output.find('cannot open shared object file') == -1)
        self.assertTrue(output.find('No such file or directory') == -1)
        self.assertTrue(output.find('does not contain valid data') == -1)

        self.assertEqual(expected, output)
    def _replace( self, fileName, check, old, new, ticketID, dryRun, count=None ):
        """
            Checks if <fileName> contains <check>, and if so it replaces
            the string <old> by <new>.

            If dryRun=True the check for patch necessity will be executed
            normally, but then no files will be altered.

            Returns a boolean if the file was affected or not.
            Returns 'None' if the specified file was not found thus the
            patch might not be applicable.

            If the argument 'count' is given, only the first n occurrences
            will be replaced.
        """
        try:
            content = FastScript.getFileContent( fileName )

        except ( IOError, UnicodeDecodeError ):
            # UnicodeDecodeError may happen when attempting to read a binary
            # file (e.g. executable), skip those as they shall not be patched

            return False

        logging.debug( '%s: searching for "%s"', fileName, check.strip() )
        needed = content.find( check ) > 0
        logging.debug( 'patch "%s" --> "%s" needed: %s' % \
                       ( old.strip(), new.strip(), str(needed) ) )

        if needed and not dryRun:

            if count is None:
                content = content.replace( old, new )
            else:
                content = content.replace( old, new, count )


            FastScript.setFileContent( fileName, content )

        return needed
def execInAllProjects(command):
    Any.requireIsTextNonEmpty(command)

    # determine list of packages (and versions) to visit

    dirList = []
    oldcwd = os.getcwd()

    if listfile:
        Any.requireIsFileNonEmpty(listfile)

        # read subdirectories from file, and remove trailing newlines
        dirList = FastScript.getFileContent(listfile, splitLines=True)
        dirList = map(str.strip, dirList)
    else:
        noSVN = re.compile("^.svn$")
        for path in FastScript.getDirsInDirRecursive(excludePattern=noSVN):
            if os.path.isfile(os.path.join(path, 'CMakeLists.txt')):
                dirList.append(path)

    # execute the task

    for entry in dirList:
        workingDir = os.path.realpath(os.path.join(oldcwd, entry))

        logging.debug('cd %s' % workingDir)
        logging.info('workingDir=%s', workingDir)

        FastScript.changeDirectory(workingDir)

        try:
            FastScript.execProgram(command)
        except subprocess.CalledProcessError as e:

            if ignoreErrors:
                logging.warning(e)
            else:
                raise

        FastScript.changeDirectory(oldcwd)
Example #26
0
def getDependenciesFromCurrentPackage(recursive=False, systemPackages=False):
    """
        Assuming the current working directory to be a source package,
        it queries the dependencies and optionally all the recursive
        dependencies, too.
    """
    from ToolBOSCore.Storage import CMakeLists
    from ToolBOSCore.Storage.PkgInfo import getPkgInfoContent

    Any.requireIsBool(recursive)
    Any.requireIsBool(systemPackages)

    fileName = 'CMakeLists.txt'
    Any.requireIsFileNonEmpty(fileName)

    fileContent = FastScript.getFileContent(fileName)
    Any.requireIsTextNonEmpty(fileContent)

    try:
        depList = getPkgInfoContent(dirName='.')['depends']
    except (AssertionError, IOError, KeyError):
        depList = CMakeLists.getDependencies(fileContent)

    Any.requireIsList(depList)

    if recursive:
        result = []
        cache = {}

        for dep in depList:
            result.append(dep)

            tmp = getDependencies(dep, recursive, cache, systemPackages)

            if tmp:  # do not add empty lists
                result.append(tmp)
    else:
        result = depList

    return result
Example #27
0
def isDeprecated(canonicalPath):
    """
        Checks from the filesystem if the specified package (canonical path)
        is flagged as deprecated.

        Returns True if either of these files exists:
               <sitRoot>/Libraries/Spam/42.0/deprecated.txt
               <sitRoot>/Libraries/Spam/deprecated.txt

               or if the canonicalPath is listed in the file
               <sitPath>/Temporary/CIA/1.0/deprecatedOverride.txt.
    """
    requireIsCanonicalPath(canonicalPath)

    filename = 'deprecated.txt'
    sitRoot = SIT.getRootPath()
    pkgPath = os.path.join(sitRoot, canonicalPath)
    check1 = os.path.join(sitRoot, os.path.dirname(canonicalPath), filename)
    check2 = os.path.join(sitRoot, canonicalPath, filename)

    # if package is not present in SIT we can't give reliable information
    # if it is deprecated or not

    if not os.path.exists(pkgPath):
        raise ValueError("%s: Package not installed in SIT" % canonicalPath)

    if os.path.exists(check1) or os.path.exists(check2):
        return True

    # check CIA operator "sudo override"
    overrideFile = os.path.join(SIT.getPath(),
                                'Temporary/CIA/1.0/deprecatedOverride.txt')

    if os.path.exists(overrideFile):
        for line in FastScript.getFileContent(overrideFile, splitLines=True):
            if line.strip() == canonicalPath:
                return True

    return False
Example #28
0
def setupMSVC2012(configDir):
    """
        Configures the Microsoft Visual Compiler to be used with Wine
        from the ToolBOS build system.

        You may provide a path to the directory where your Wine
        configuration is. If omitted, the path returned from getWineConfigDir()
        will be used.
    """
    from ToolBOSCore.Storage.SIT import getPath

    if not os.path.exists(os.path.join(configDir, 'user.reg')):
        setupWineDotNet(configDir)

    Any.requireIsDir(configDir)

    if not os.path.exists(os.path.join(configDir, 'dosdevices')):
        setupWineDotNet(configDir)

    logging.info('setting up Visual Studio...')

    linkPath = os.path.join(configDir, 'dosdevices', 'c:')
    linkTarget = '../drive_c'
    FastScript.remove(linkPath)
    FastScript.link(linkTarget, linkPath)

    linkPath = os.path.join(configDir, 'dosdevices', 'z:')
    linkTarget = '/'
    FastScript.remove(linkPath)
    FastScript.link(linkTarget, linkPath)

    # create temp. directories
    driveC = os.path.join(configDir, 'drive_c')
    userName = FastScript.getCurrentUserName()
    userTempDir = os.path.join(driveC, 'users', userName, 'Temp')
    sysTempDir = os.path.join(driveC, 'temp')
    logging.debug('userTempDir=%s', userTempDir)
    FastScript.mkdir(userTempDir)
    FastScript.mkdir(sysTempDir)

    # ensure to NOT have the "h:" link, else wine would not find some links
    FastScript.remove(os.path.join(configDir, 'dosdevices', 'h:'))

    # replace "C:\Program Files" by symlink into SIT
    FastScript.remove(os.path.join(configDir, 'drive_c', 'Program Files'))

    sitPath = getPath()

    linkPath = os.path.join(configDir, 'drive_c', 'msvc-sdk')
    linkTarget = os.path.join(sitPath, 'External/MSVC/10.0/msvc-sdk')
    FastScript.remove(linkPath)
    FastScript.link(linkTarget, linkPath)

    linkPath = os.path.join(configDir, 'drive_c', 'Program Files')
    linkTarget = os.path.join(sitPath, 'External/MSVC/10.0/Program Files')
    FastScript.remove(linkPath)
    FastScript.link(linkTarget, linkPath)

    # copy a hancrafted system.reg
    srcFile = os.path.join(
        sitPath, 'External/MSVC/10.0/otherstuff/winevs2012/system.reg')
    dstFile = os.path.join(configDir, 'system.reg')
    shutil.copyfile(srcFile, dstFile)

    # force wine to use the MSVC native library
    userReg = os.path.join(configDir, 'user.reg')

    Any.requireIsFileNonEmpty(userReg)
    content = FastScript.getFileContent(userReg)

    if content.find('1413877490') == -1:
        content += \
'''

[Software\\\\Wine\\\\DllOverrides] 1413877490
"mscoree"="native"
"msvcr110"="native"

'''
        logging.debug('updating %s', userReg)
        FastScript.setFileContent(userReg, content)
    def _patchCIA1265( self, dryRun=False ):
        """
            Checks BBCM package for included outdated headerfiles and
            replaces them with the nowadays version.
            Duplicates will be deleted.
        """
        if not self.details.isBBCM():
            return False

        # Get a list of all files to check
        files    = FastScript.getFilesInDirRecursive( 'src' )
        modified = []

        # Check every file
        for filePath in files:
            logging.debug( 'processing %s', filePath )

            # Only rewrite line if changed
            rewrite = False
            # Get file content
            fileContent = FastScript.getFileContent( filename=filePath,
                                                     splitLines=True )
            # Check every line
            for line in fileContent:
                item = line.split()

                # Check for include statement
                if line.find( '#include <BBDM' ) != -1:
                    # Replace old package names with the nowadays form
                    match = re.search( r"-A|-CID|-S", item[ 1 ] )
                    if match:
                        fileContent[ fileContent.index( line ) ] = re.sub(
                            r"-A|-CID|-S", "", line )
                        rewrite = True

            includes = []

            # Check file backwards
            for line in reversed( fileContent ):
                item = line.split()

                if line.find( '#include <BBDM' ) != -1:
                    # Check for duplicates and remove existing ones
                    if line in includes:
                        rewrite = True
                        fileContent.remove( line )

                    # add to list of known includes
                    else:
                        includes.append( line )

            # Overwrite file with new content
            try:
                if rewrite:
                    if dryRun:
                        logging.info( '[DRY-RUN] patching %s', filePath )
                    else:
                        logging.info( 'patching %s', filePath )
                        newContent = ''.join( fileContent )
                        FastScript.setFileContent( filePath, newContent )

                    modified.append( filePath )

            except IOError as e:
                logging.error( e )

        return modified
    def _patchCIA989( self, dryRun=False ):
        """
            Removes legacy ANY_DEF_*_TAG macros.
        """
        if self.details.canonicalPath.find( 'DevelopmentTools/ToolBOS' ) == -1 and \
           self.details.canonicalPath.find( 'Libraries/ToolBOSLib'     ) == -1 and \
           self.details.canonicalPath.find( 'Applications/ToolBOS'     ) == -1:

            result = []
            ticket = 'CIA-989'

            pkgNameUpper  = self.details.packageName.upper()
            srcTagPattern = re.compile( '(ANY_DEF_SRCTAG\s?\(.*?\);)', re.DOTALL )

            for fileName in FastScript.getFilesInDir( 'src' ):
                fileName = os.path.join( 'src', fileName )
                modified = False
                new      = ''

                old = 'ANY_DEF_BINTAG;\n'
                if self._replace( fileName, old, old, new, ticket, dryRun ):
                    modified |= True


                old = '/* File tag */\n'
                if self._replace( fileName, old, old, new, ticket, dryRun ):
                    modified |= True


                old = '/*---------------------------------------------*/\n' + \
                      '/* File tag                                    */\n' + \
                      '/*---------------------------------------------*/\n'
                if self._replace( fileName, old, old, new, ticket, dryRun ):
                    modified |= True


                old = '#define %s_C_SRCTAG\n' % pkgNameUpper
                if self._replace( fileName, old, old, new, ticket, dryRun ):
                    modified |= True


                old = '#undef %s_C_SRCTAG\n' % pkgNameUpper
                if self._replace( fileName, old, old, new, ticket, dryRun ):
                    modified |= True


                content = FastScript.getFileContent( fileName )

                tmp = srcTagPattern.search( content )

                if tmp:
                    old = tmp.group(1)
                    if self._replace( fileName, old, old, new, ticket, dryRun ):
                        modified |= True


                # use the occasion and replace some more clutter
                old = '/* Temporary solution for a local debug level */\n'
                if self._replace( fileName, old, old, new, ticket, dryRun ):
                    modified |= True


                # remove too many empty lines left-over from previous replacements
                if modified:
                    old = '\n\n\n\n\n'
                    new = '\n\n'
                    self._replace( fileName, old, old, new, ticket, dryRun )

                    result.append( fileName )

        else:

            logging.info( 'skipping ToolBOS packages to not patch backward-compatibility layers' )

            return []