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
def copyModuleIndex(srcRoot, dstRoot): """ Copies all <srcDIT>/Modules/Index/*.def and <srcDIT>/Modules/Index/*.py files to <dstSIT>/Modules/Index/ """ Any.requireIsDir(srcRoot) Any.requireIsDir(dstRoot) srcDir = os.path.join(srcRoot, 'Modules', 'Index') dstDir = os.path.join(dstRoot, 'Modules', 'Index') # For the case that srcRoot is an SIT proxy: Some people do not have # any files in their Index directory, furthermore the directory could # be entirely missing if never a BBCM had been installed into the # user's proxy # # Any.requireIsDirNonEmpty( srcDir ) FastScript.mkdir(dstDir) for srcFile in FastScript.getFilesInDir(srcDir): if srcFile.endswith(".def") or srcFile.endswith(".py"): fileName = os.path.basename(srcFile) srcPath = os.path.join(srcDir, fileName) dstPath = os.path.join(dstDir, fileName) FastScript.copy(srcPath, dstPath)
def createLocalProject(klocworkDir='klocwork', stdout=None, stderr=None): """ Creates a local .kwlp directory so that the analysis can be performed. @Retuns: nothing. Throws an RuntimeError in case of problems. """ Any.requireIsTextNonEmpty(klocworkDir) requireOutsideTmpDir() kwPackage = ToolBOSSettings.getConfigOption('package_klocwork') buildSpec = os.path.join(klocworkDir, 'kwinject.out') kwlpDir = os.path.join(klocworkDir, '.kwlp') # KW local project kwpsDir = os.path.join(klocworkDir, '.kwps') # KW project settings hostPlatform = Platforms.getHostPlatform() licenseServerHost = ToolBOSSettings.getConfigOption('kwLicenseServerHost') licenseServerPort = ToolBOSSettings.getConfigOption('kwLicenseServerPort') Any.requireIsTextNonEmpty(kwPackage) Any.requireIsTextNonEmpty(hostPlatform) ProcessEnv.source(kwPackage) FastScript.mkdir(klocworkDir) # ensure this exists FastScript.remove(kwlpDir) # but those should not exist FastScript.remove(kwpsDir) # but those should not exist if ProcessEnv.which('kwinject') is None: msg = '%s not installed for platform=%s' % (kwPackage, hostPlatform) raise EnvironmentError(msg) # inspect the build process to capture source files, defines, flags,... cmd = 'kwinject -o %s %s' % (buildSpec, 'BST.py -sb') FastScript.execProgram(cmd, stdout=stdout, stderr=stderr) Any.requireIsFileNonEmpty(buildSpec) # create Klocwork project directory cmd = 'kwcheck create --license-host %s --license-port %d -pd %s -sd %s %s' % \ ( licenseServerHost, licenseServerPort, kwlpDir, kwpsDir, buildSpec ) FastScript.execProgram(cmd, stdout=stdout, stderr=stderr) Any.requireIsDir(kwlpDir) Any.requireIsDir(kwpsDir) # import the build specification into project directory cmd = 'kwcheck import -pd %s %s' % (kwlpDir, buildSpec) FastScript.execProgram(cmd, stdout=stdout, stderr=stderr) # install the HIS-Subset taxonomy so that the user may select it tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT') fileName = 'HIS_Subset_MISRA_C_1.0.2.tconf' srcFile = os.path.join(tcRoot, 'external/emenda.com', fileName) dstDir = os.path.join(kwpsDir, 'servercache') dstFile = os.path.join(dstDir, fileName) Any.requireIsFileNonEmpty(srcFile) FastScript.mkdir(dstDir) FastScript.copy(srcFile, dstFile) # auto-detect source code directories (exclude some blacklisted ones) dirList = [] cwd = os.getcwd() for dirName in FastScript.getDirsInDir(): if dirName not in ('build', 'doc', 'external', 'lib'): dirList.append(os.path.join(cwd, dirName)) # create workingset values = {'dirList': dirList} creator = PackageCreator.PackageCreator('dummy', '1.0', values) srcDir = os.path.join(creator.templateDir, 'KlocworkProject') dstDir = kwlpDir creator.templatize(os.path.join(srcDir, 'workingsets.xml'), os.path.join(dstDir, 'workingsets.xml'))