def _patchCIA1143( self, dryRun=False ): """ Replace legacy C macro ANY_TNALLOC by ANY_NTALLOC for consistency reasons with the order of the parameters. """ old = 'ANY_TNALLOC' new = 'ANY_NTALLOC' result = [] ticket = 'CIA-1143' whitelist = [ '.c', '.h', '.cpp', '.hpp', '.inc' ] # do not patch the ToolBOS package itself, otherwise this function # would patch the deprecated ANY_TNALLOC macro itself, which is # kept for compatibility reasons. # # We generally assume that the ToolBOS packages themselves are # clean from legacy occurrences. if self.details.canonicalPath.find( 'DevelopmentTools/ToolBOS' ) == -1 and \ self.details.canonicalPath.find( 'Libraries/ToolBOSLib' ) == -1: for fileName in FastScript.findFiles( '.', ext=whitelist ): modified = self._replace( fileName, old, old, new, ticket, dryRun ) if modified: result.append( fileName ) return result else: logging.info( 'skipping ToolBOS packages to not patch backward-compatibility layers' ) return []
def isRTMapsPackage(self): """ Returns True if the package is intended for usage within the RTMaps framework of Intempora, f.i. if the following file exists: * src/maps_*.cpp """ expr = re.compile('^maps_.*\.cpp') found = FastScript.findFiles('src', regexp=expr) return bool(found) # True if at least one file found
def registerNormalPackages(sitPath, dryRun=False): """ Searches the SIT for RTMaps packages and invokes registerHondaPackage() for each of them. """ Any.requireIsDir(sitPath) Any.requireIsBool(dryRun) sitProxyPath = SIT.getPath() ProxyDir.requireIsProxyDir(sitProxyPath) searchBaseDir = os.path.join(sitPath, 'Modules', 'RTMaps') # Any.requireIsTextNonEmpty( searchBaseDir ) # dir. might not exist Any.requireIsTextNonEmpty(searchBaseDir) indexBaseDir = getIndexBaseDir(sitProxyPath) # Any.requireIsDir( indexBaseDir ) # dir. might not exist Any.requireIsTextNonEmpty(indexBaseDir) logging.debug('SIT path: %s', sitPath) logging.debug('search basedir: %s', searchBaseDir) logging.debug('index basedir: %s', indexBaseDir) # find *.pck files logging.debug('scanning %s...', searchBaseDir) pckPaths = FastScript.findFiles(searchBaseDir, ext='.pck') Any.requireIsList(pckPaths) logging.debug('found HORP files:') logging.debug(pckPaths) # process each *.pck file (tokenize path and create symlink) for pckPath in pckPaths: # the *.pck file is located on the 3rd subdirectory level relative # to the installRoot, so compute the installRoot based on this tokens = pckPath.split(os.path.sep) installRoot = os.path.sep.join(tokens[:-3]) package = SIT.strip(installRoot) Any.requireIsDir(installRoot) Any.requireIsTextNonEmpty(package) try: registerNormalPackage(package, sitProxyPath, indexBaseDir, dryRun) except ValueError as e: logging.error(e)
def _patchCIA1094( self, dryRun=False ): """ Replace fixed values of valid-flags by randomized value to discover memory problems. """ old1 = '0x900db00f' old2 = '0xdeadb00f' result = [] ticket = 'CIA-1094' whitelist = [ '.c', '.h', '.cpp', '.hpp', '.inc' ] def check( fileName ): Any.requireIsFile( fileName ) content = FastScript.getFileContent( fileName ) return content.find( old1 ) != -1 or \ content.find( old2 ) != -1 for fileName in FastScript.findFiles( 'src', ext=whitelist ): modified = False while check( fileName ): new1, new2 = PackageCreator.randomizeValidityFlags() # search for boilerplate valid-flag if self._replace( fileName, old1, old1, new1, ticket, dryRun, 1 ): modified |= True # search for boilerplate invalid-flag if self._replace( fileName, old2, old2, new2, ticket, dryRun, 1 ): modified |= True if modified: result.append( fileName ) return result
def registerDistributionPackages(sitRootPath, sitProxyPath, dryRun=False): """ Searches the SIT for packages shipped with RTMaps itself (by Intempora). """ Any.requireIsDir(sitRootPath) ProxyDir.requireIsProxyDir(sitProxyPath) Any.requireIsBool(dryRun) platformList = getPlatformNames() rtmapsVersions = getVersionsAvailable(sitRootPath) Any.requireIsListNonEmpty(platformList) Any.requireIsListNonEmpty(rtmapsVersions) installBaseDir = os.path.join(sitRootPath, 'External', 'RTMaps') indexBaseDir = getIndexBaseDir(sitProxyPath) # Any.requireIsDir( indexBaseDir ) # dir. might not exist Any.requireIsTextNonEmpty(indexBaseDir) # find *.pck files shipped with RTMaps for rtmapsVersion in rtmapsVersions: logging.debug('searching for packages shipped with RTMaps %s', rtmapsVersion) for platform in platformList: searchPath = os.path.join(installBaseDir, rtmapsVersion, platform, 'packages') pckPaths = FastScript.findFiles(searchPath, ext='.pck') Any.requireIsList(pckPaths) for pckPath in pckPaths: pckFile = os.path.basename(pckPath) Any.requireIsTextNonEmpty(pckFile) symlink = os.path.join(indexBaseDir, rtmapsVersion, platform, pckFile) target = pckPath FastScript.link(target, symlink, dryRun)
def _patchCIA1112( self, dryRun=False ): """ Replace legacy HRI_GLOBAL_ROOT variable by SIT, except for BBML graph files where this is part of the specification. """ old = 'HRI_GLOBAL_ROOT' new = 'SIT' result = [] ticket = 'CIA-1112' whitelist = [ '.bat', '.c', '.h', '.cpp', '.hpp', '.inc', '.py', '.sh', '.cmake', # e.g. packageVar.cmake '' # e.g. BashSrc (no extension) ] # do not patch the ToolBOS package itself, otherwise this function # would be patched to replace "SIT" by "SIT" ;-) # # We generally assume that the ToolBOS packages themselves are # clean from legacy occurrences. if self.details.canonicalPath.find( 'DevelopmentTools/ToolBOS' ) == -1 and \ self.details.canonicalPath.find( 'Applications/ToolBOS' ) == -1: for fileName in FastScript.findFiles( '.', ext=whitelist ): modified = self._replace( fileName, old, old, new, ticket, dryRun ) if modified: result.append( fileName ) return result else: logging.info( 'skipping ToolBOS packages to not patch backward-compatibility layers' ) return []
def registerNormalPackage(package, sitProxyPath=None, indexBaseDir=None, dryRun=False): """ Creates a symlink to the *.pck file of 'package' within the RTMaps index. RTMAPS_VERSION is taken from the dependency list of the package. """ if sitProxyPath is None: sitProxyPath = SIT.getPath() if indexBaseDir is None: indexBaseDir = getIndexBaseDir(sitProxyPath) ProjectProperties.requireIsCanonicalPath(package) Any.requireIsDir(sitProxyPath) Any.requireIsDir(indexBaseDir) Any.requireIsBool(dryRun) platformList = getPlatformNames() packageName = ProjectProperties.getPackageName(package) packageVersion = ProjectProperties.getPackageVersion(package) versionTokens = ProjectProperties.splitVersion(packageVersion) majorVersion = int(versionTokens[0]) minorVersion = int(versionTokens[1]) installRoot = os.path.join(sitProxyPath, package) Any.requireIsListNonEmpty(platformList) Any.requireIsTextNonEmpty(packageName) Any.requireIsTextNonEmpty(packageVersion) Any.requireIsDir(installRoot) deps = ProjectProperties.getDependencies(package) try: Any.requireIsListNonEmpty(deps) except AssertionError: logging.debug( 'empty list of dependencies in RTMaps package is unplausible') msg = "%s: unable to retrieve dependencies, please check SIT installation" % package raise ValueError(msg) expr = re.compile('^sit://External/RTMaps/(\d+\.\d+)') # detect RTMaps version used by package rtmapsVersion = '' for dep in deps: tmp = expr.match(dep) if tmp: rtmapsVersion = tmp.group(1) break Any.requireIsTextNonEmpty(rtmapsVersion) logging.debug('%s depends on RTMaps %s', package, rtmapsVersion) libDir = os.path.join(installRoot, 'lib') pckFiles = FastScript.findFiles(libDir, ext='.pck') Any.requireMsg( len(pckFiles) > 0, package + ": No *.pck file found, forgot to compile?") for relPath in pckFiles: pckFileName = os.path.basename(relPath) pckPackage = os.path.splitext(pckFileName)[0] pckFileExt = os.path.splitext(pckFileName)[1] logging.debug('registering %s', pckPackage) for platform in platformList: pckPath = os.path.join(libDir, platform, pckFileName) dstDir = os.path.join(indexBaseDir, rtmapsVersion, platform) if os.path.exists(pckPath): symlinkFile = '%s_%d.%d%s' % (pckPackage, majorVersion, minorVersion, pckFileExt) symlinkPath = os.path.join(dstDir, symlinkFile) target = pckPath FastScript.link(target, symlinkPath, dryRun)