Skip to content
Snippets Groups Projects
Commit 38c4e883 authored by al.schwinn's avatar al.schwinn
Browse files

Bug 1445 - move generated code for fesa-class into "generated" folder

Bug 1180 - migration: automatically replace silecs-version-string in
FESA Makefile.specific
parent 2feba81c
No related branches found
No related tags found
No related merge requests found
...@@ -662,6 +662,7 @@ override WARNFLAGS += ...@@ -662,6 +662,7 @@ override WARNFLAGS +=
# Additional compiler flags # Additional compiler flags
COMPILER_FLAGS += -I$(SILECS_PATH)/include -I$(SILECS_PATH)/include/silecs-communication/interface/core COMPILER_FLAGS += -I$(SILECS_PATH)/include -I$(SILECS_PATH)/include/silecs-communication/interface/core
COMPILER_FLAGS += -I./generated-silecs/cpp
COMPILER_FLAGS += COMPILER_FLAGS +=
LINKER_FLAGS += LINKER_FLAGS +=
......
...@@ -186,17 +186,20 @@ def genCppSource(className, silecsRoot, fesaRoot, sourcePath,logTopics): ...@@ -186,17 +186,20 @@ def genCppSource(className, silecsRoot, fesaRoot, sourcePath,logTopics):
iecommon.logInfo('Source file for '+className+' generated successfully', logTopics) iecommon.logInfo('Source file for '+className+' generated successfully', logTopics)
def genCppFiles(className, workspacePath, silecsDesignFilePath,logTopics={'errorlog': True}): def genCppFiles(className, workspacePath, silecsDesignFilePath,logTopics={'errorlog': True}):
fesaCommonDirectory = iefiles.getFesa3CommonDirectory(workspacePath,className)
iecommon.logInfo("fesaCommonDirectory:" + fesaCommonDirectory,logTopics)
if not os.path.exists(fesaCommonDirectory ): generatedCodeFolder = workspacePath + '/' + className + '/generated-silecs/cpp/' + className + '/GeneratedCode'
os.makedirs(fesaCommonDirectory) generatedCodeFolderNorm = os.path.normpath(generatedCodeFolder)
iecommon.logInfo("generated code folder:" + generatedCodeFolderNorm,logTopics)
if not os.path.exists(generatedCodeFolderNorm ):
os.makedirs(generatedCodeFolderNorm)
silecsDesignFilePath = iefiles.getSilecsDesignFilePath(workspacePath,className) silecsDesignFilePath = iefiles.getSilecsDesignFilePath(workspacePath,className)
fesaDesignFilePath = workspacePath + "/" + className + "/src/" + className + ".design" fesaDesignFilePath = workspacePath + "/" + className + "/src/" + className + ".design"
silecsRoot = libxml2.parseFile(silecsDesignFilePath) silecsRoot = libxml2.parseFile(silecsDesignFilePath)
fesaRoot = libxml2.parseFile(fesaDesignFilePath) fesaRoot = libxml2.parseFile(fesaDesignFilePath)
genHSource(className, silecsRoot, fesaRoot, fesaCommonDirectory,logTopics) genHSource(className, silecsRoot, fesaRoot, generatedCodeFolderNorm,logTopics)
genCppSource(className, silecsRoot, fesaRoot, fesaCommonDirectory,logTopics) genCppSource(className, silecsRoot, fesaRoot, generatedCodeFolderNorm,logTopics)
...@@ -123,11 +123,6 @@ def getDuWrapperFile(workspacePath, deployName, controllerName ): ...@@ -123,11 +123,6 @@ def getDuWrapperFile(workspacePath, deployName, controllerName ):
def getDuDesignWrapperFile(workspacePath, deployName, designName): def getDuDesignWrapperFile(workspacePath, deployName, designName):
return getDuWrapperSourceDirectory(workspacePath, deployName) + "/" + getDuWrapperFileName(designName) return getDuWrapperSourceDirectory(workspacePath, deployName) + "/" + getDuWrapperFileName(designName)
#--- FESA ---
def getFesa3CommonDirectory(workspacePath, designName):
fesa3ClassPath = workspacePath + '/' + designName + '/src/' + designName + '/Common'
fesa3ClassPathNorm = os.path.normpath(fesa3ClassPath)
return fesa3ClassPathNorm
def getProjectDirectory(workspacePath, designName): def getProjectDirectory(workspacePath, designName):
path = workspacePath + '/' + designName path = workspacePath + '/' + designName
......
#!/usr/bin/python
# Copyright 2016 CERN and GSI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
from migrationBase import MigrationBase
from migration2_0_Xto2_1_X.migrators import *
import libxml2
import sys
import FileUtils
import shutil
class Migration(MigrationBase):
def __init__(self, arguments):
super(Migration, self).__init__()
def migrateClass(self, context, projectDir ):
modified = fesaClassIncludeHeaderMigrator(context,self.silecsDocument)
removeSilecsGenCode(context, self.silecsDocument)
# modified |= designBlockRegisterMigrator(context)
return modified
if __name__ == "__main__":
migration = Migration(sys.argv)
migration.migrate()
migration.updateFESAMakeSpecific()
...@@ -25,15 +25,38 @@ def write(string, filePath): ...@@ -25,15 +25,38 @@ def write(string, filePath):
f.write(string) f.write(string)
def backupFile(fileName): def backupFile(fileName):
if not os.path.isfile(fileName):
return
src = fileName src = fileName
dst = fileName + ".backup" dst = fileName + ".backup"
print("Original file backed up by adding '.backup'") os.rename(src, dst)
shutil.copyfile(src, dst) print("Backed up old file: " + dst)
def getExtension(fileName): def getExtension(fileName):
'''Returns the file extension, dot included''' '''Returns the file extension, dot included'''
return fileName[fileName.rfind('.'):] return fileName[fileName.rfind('.'):]
def getProjectDir(fesaDocument): def getProjectDir(file_in_project):
absPath = os.path.abspath(fesaDocument) absPath = os.path.abspath(file_in_project)
return os.path.dirname(os.path.dirname(absPath)) return os.path.dirname(os.path.dirname(absPath))
def getFesaSourceFiles(fesaClassName, projectDir):
fesaCodeFolder = os.path.join(projectDir,"src",fesaClassName)
if not os.path.exists(fesaCodeFolder):
return []
if not os.path.isdir(fesaCodeFolder):
return []
sourceFiles = []
for root, subdirs, files in os.walk(fesaCodeFolder):
for file in files:
if file.endswith(".cpp") or file.endswith(".h"):
print os.path.join(root,file)
sourceFiles.append(os.path.join(root,file))
return sourceFiles
def replaceInFile(filePath,searchString,replaceWithString):
with open(filePath, 'r') as file :
filedata = file.read()
filedata = filedata.replace(searchString, replaceWithString)
with open(filePath, 'w') as file:
file.write(filedata)
\ No newline at end of file
#!/usr/bin/python
# Copyright 2016 CERN and GSI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import libxml2
import FileUtils
import os
def fesaClassIncludeHeaderMigrator(context,silecsDocument):
modified = False
silecsClassNodes = context.xpathEval("//SILECS-Class")
if not silecsClassNodes:
raise Exception('Node "SILECS-Class" not found')
silecsClassNodes = silecsClassNodes[0]
silecsClassName = silecsClassNodes.prop("name")
projectDir = FileUtils.getProjectDir(silecsDocument)
sourceFiles = FileUtils.getFesaSourceFiles(silecsClassName, projectDir)
searchString = "<" + os.path.join(silecsClassName,"Common",silecsClassName) + ".h>"
replaceString = "<" + os.path.join(silecsClassName,"GeneratedCode",silecsClassName) + ".h>"
for sourceFile in sourceFiles:
FileUtils.replaceInFile(sourceFile,searchString,replaceString)
modified = True
return modified
def removeSilecsGenCode(context, silecsDocument):
silecsClassNodes = context.xpathEval("//SILECS-Class")
if not silecsClassNodes:
raise Exception('Node "SILECS-Class" not found')
silecsClassNodes = silecsClassNodes[0]
silecsClassName = silecsClassNodes.prop("name")
projectDir = FileUtils.getProjectDir(silecsDocument)
commonFolder = os.path.join(projectDir,"src",silecsClassName,"Common")
cppFile = os.path.join(commonFolder,silecsClassName + ".cpp")
hppFile = os.path.join(commonFolder,silecsClassName + ".h")
if os.path.isfile(cppFile):
os.remove(cppFile)
if os.path.isfile(hppFile):
os.remove(hppFile)
#!/usr/bin/python
# Copyright 2016 CERN and GSI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from test.testBase import *
import libxml2
from migration.migration2_0_Xto2_1_X.migrators import *
import inspect #get caller name
def runTests():
print("nothing so far")
#testdesignValueTypeMigrator()
#testdesignBlockRegisterMigrator()
# print deployDoc # for debugging
...@@ -31,6 +31,8 @@ class MigrationBase(object): ...@@ -31,6 +31,8 @@ class MigrationBase(object):
results = self.parser.parse_args() results = self.parser.parse_args()
self.versionOld = results.versionOld self.versionOld = results.versionOld
self.versionNew = results.versionNew self.versionNew = results.versionNew
self.silecsDocument = results.silecsDocument
self.xmlSchema = results.xmlSchema
def fixSilecsVersion(self, context): def fixSilecsVersion(self, context):
root = context.xpathEval("/*")[0] root = context.xpathEval("/*")[0]
...@@ -45,18 +47,23 @@ class MigrationBase(object): ...@@ -45,18 +47,23 @@ class MigrationBase(object):
print("Info: Replaced old silecs-xmlSchema") print("Info: Replaced old silecs-xmlSchema")
def backupOldFESAMakeSpecific(self): def backupOldFESAMakeSpecific(self):
results = self.parser.parse_args() projectDir = FileUtils.getProjectDir(self.silecsDocument)
silecsDocument = results.silecsDocument makeSpecific = os.path.join(projectDir,"Makefile.specific")
projectDir = FileUtils.getProjectDir(silecsDocument) FileUtils.backupFile(makeSpecific)
makeSpecific = projectDir + "/Makefile.specific"
def updateFESAMakeSpecific(self):
projectDir = FileUtils.getProjectDir(self.silecsDocument)
makeSpecific = os.path.join(projectDir,"Makefile.specific")
if os.path.isfile(makeSpecific): if os.path.isfile(makeSpecific):
os.rename(makeSpecific, makeSpecific + ".backup") oldComm = "silecs-communication-cpp/" + self.versionOld
print("Backed up old FESA Make.specific file: " + makeSpecific) newComm = "silecs-communication-cpp/" + self.versionNew
FileUtils.replaceInFile(makeSpecific,oldComm,newComm)
oldSnap7 = "snap7/" + self.versionOld
newSnap7 = "snap7/" + self.versionNew
FileUtils.replaceInFile(makeSpecific,oldSnap7,newSnap7)
def removeGenCode(self): def removeGenCode(self):
results = self.parser.parse_args() projectDir = FileUtils.getProjectDir(self.silecsDocument)
silecsDocument = results.silecsDocument
projectDir = FileUtils.getProjectDir(silecsDocument)
clientFolder = projectDir + "/generated/client" clientFolder = projectDir + "/generated/client"
controllerFolder = projectDir + "/generated/controller" controllerFolder = projectDir + "/generated/controller"
wrapperFolder = projectDir + "/generated/wrapper" wrapperFolder = projectDir + "/generated/wrapper"
...@@ -71,24 +78,21 @@ class MigrationBase(object): ...@@ -71,24 +78,21 @@ class MigrationBase(object):
print("removed generation folder: " + wrapperFolder) print("removed generation folder: " + wrapperFolder)
def migrate(self): def migrate(self):
results = self.parser.parse_args()
silecsDocument = results.silecsDocument
xmlSchema = results.xmlSchema
print("INFO: Migration %s --> %s " % (self.versionOld, self.versionNew)) print("INFO: Migration %s --> %s " % (self.versionOld, self.versionNew))
#project directory path #project directory path
projectDir = FileUtils.getProjectDir(silecsDocument) projectDir = FileUtils.getProjectDir(self.silecsDocument)
# Design # Design
extension = FileUtils.getExtension(silecsDocument) extension = FileUtils.getExtension(self.silecsDocument)
modified = False modified = False
if extension == '.silecsdesign': if extension == '.silecsdesign':
context = self._parse(silecsDocument) context = self._parse(self.silecsDocument)
modified = self.migrateClass(context, projectDir) modified = self.migrateClass(context, projectDir)
# Deploy # Deploy
elif extension == '.silecsdeploy': elif extension == '.silecsdeploy':
context = self._parse(silecsDocument) context = self._parse(self.silecsDocument)
modified = self.migrateDeployUnit(context, projectDir) modified = self.migrateDeployUnit(context, projectDir)
# Unknown # Unknown
...@@ -97,13 +101,13 @@ class MigrationBase(object): ...@@ -97,13 +101,13 @@ class MigrationBase(object):
# only chaning the version or the schema does not count as modification --> no backup needed # only chaning the version or the schema does not count as modification --> no backup needed
self.fixSilecsVersion(context) self.fixSilecsVersion(context)
self.fixXMLScheman(context,xmlSchema) self.fixXMLScheman(context,self.xmlSchema)
if modified: if modified:
self._saveAndBackupFile(context, silecsDocument) self._saveAndBackupFile(context, self.silecsDocument)
else: else:
self._saveFile(context, silecsDocument) self._saveFile(context, self.silecsDocument)
print('File %r successfully migrated' % silecsDocument) print('File %r successfully migrated' % self.silecsDocument)
def migrateClass(self, context, projectDir): def migrateClass(self, context, projectDir):
return False return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment