From ee3551b59bba3f1b072286e7826b2528fcf8e32f Mon Sep 17 00:00:00 2001 From: caremoli Date: Fri, 27 Nov 2009 08:52:06 +0000 Subject: [PATCH] CCAR: add an option to put all components in a single directory It is an option of the module and is named layout (default="multidir", other value "monodir") --- MANIFEST.in | 30 +++++++----- module_generator/astcompo.py | 29 ++++++++---- module_generator/aster_tmpl.py | 22 --------- module_generator/cpp_tmpl.py | 17 ------- module_generator/cppcompo.py | 67 +++++++++++++++++---------- module_generator/gener.py | 83 +++++++++++++++++++++++++++++----- module_generator/pycompo.py | 20 ++++---- module_generator/pyth_tmpl.py | 13 ------ 8 files changed, 165 insertions(+), 116 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 91bab87..3f6bec4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,12 +1,18 @@ -recursive-include Examples/fort1 *.f components.py coupling.xml Makefile README.txt -recursive-include Examples/cpp1 components.py coupling.xml README.txt -recursive-include Examples/pyth1 *.py coupling.xml README.txt -recursive-include Examples/fort2 *.f components.py coupling.xml Makefile README.txt -recursive-include Examples/cpp2 components.py coupling.xml README.txt Makefile prog.cxx -recursive-include Examples/pyth2 components.py coupling.xml README.txt -recursive-include Examples/ast1 components.py coupling.xml f.comm README.txt -recursive-include Examples/ast1/fcompo compo.f Makefile -recursive-include Examples/ast1/myaster Makefile make_cata src/*.f catalo/*.capy -recursive-include Examples/ast2 components.py coupling.xml f.comm README.txt -recursive-include Examples/ast2/fcompo compo.f Makefile -recursive-include Examples/ast2/myaster Makefile make_exec config.txt src/*.f catalo/*.capy +include Examples/context.py +include Examples/makefile.inc +include Examples/*/*.f +include Examples/*/*.py +include Examples/*/*.cxx +include Examples/*/coupling.xml +include Examples/*/Makefile +include Examples/*/README.txt +include Examples/*/f.comm +include Examples/ast*/fcompo/compo.f +include Examples/ast*/fcompo/Makefile +include Examples/ast*/myaster/src/*.f +include Examples/ast*/myaster/catalo/*.capy +include Examples/ast*/myaster/Makefile +include Examples/ast1/myaster/make_cata +include Examples/ast2/myaster/make_exec +include Examples/ast2/myaster/config.txt +include Examples/ast2/exeaster diff --git a/module_generator/astcompo.py b/module_generator/astcompo.py index d1781cb..f4f1efb 100644 --- a/module_generator/astcompo.py +++ b/module_generator/astcompo.py @@ -12,7 +12,6 @@ from gener import Component, Invalid, makedirs from pyth_tmpl import pyinitEXEService, pyinitCEXEService, pyinitService from aster_tmpl import asterCEXEService, asterEXEService from aster_tmpl import asterService, asterEXECompo, asterCEXECompo, asterCompo -from aster_tmpl import asterexeMakefile, astercexeMakefile, astercompoMakefile from aster_tmpl import comm, make_etude, cexe, exeaster from aster_tmpl import container, component @@ -64,30 +63,40 @@ class ASTERComponent(Component): #on suppose que les composants ASTER sont homogenes (utilisent meme install) gen.aster = self.aster_dir if self.kind == "lib": - return {"Makefile.am":astercompoMakefile.substitute(module=gen.module.name, - component=self.name), - filename:self.makeaster(gen)} + return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), + filename:self.makeaster(gen)} elif self.kind == "cexe": - #creation de l'installation aster dans exe_path fdict=self.makecexepath(gen) - d= {"Makefile.am":astercexeMakefile.substitute(module=gen.module.name, - component=self.name), + d= {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), self.name+".exe":cexe.substitute(compoexe=self.exe_path), filename:self.makecexeaster(gen) } d.update(fdict) return d elif self.kind == "exe": - #creation de l'installation aster dans exe_path fdict=self.makeexepath(gen) - d= {"Makefile.am":asterexeMakefile.substitute(module=gen.module.name, - component=self.name), + d= {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), self.name+".exe":exeaster.substitute(compoexe=self.exe_path), self.name+"_module.py":self.makeexeaster(gen) } d.update(fdict) return d + def getMakefileItems(self,gen): + makefileItems={"header":"include $(top_srcdir)/adm_local/make_common_starter.am"} + if self.kind == "lib": + makefileItems["salomepython_PYTHON"]=[self.name+".py"] + elif self.kind == "exe": + makefileItems["salomepython_PYTHON"]=[self.name+"_module.py",self.name+"_component.py","E_SUPERV.py"] + makefileItems["dist_salomescript_SCRIPTS"]=[self.name+".exe"] + makefileItems["salomeres_DATA"]=[self.name+"_config.txt"] + elif self.kind == "cexe": + makefileItems["salomepython_PYTHON"]=[self.name+".py",self.name+"_container.py","E_SUPERV.py"] + makefileItems["dist_salomescript_SCRIPTS"]=[self.name+".exe"] + makefileItems["salomeres_DATA"]=[self.name+"_config.txt"] + return makefileItems + + def makeexepath(self, gen): """standalone component: generate files for calculation code""" #patch to E_SUPERV.py diff --git a/module_generator/aster_tmpl.py b/module_generator/aster_tmpl.py index c427a60..57458fd 100644 --- a/module_generator/aster_tmpl.py +++ b/module_generator/aster_tmpl.py @@ -4,28 +4,6 @@ try: except: from compat import Template,set -astercompoMakefile="""include $$(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON = ${component}.py - -""" -astercompoMakefile=Template(astercompoMakefile) - -astercexeMakefile="""include $$(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON = ${component}.py ${component}_container.py E_SUPERV.py -# These files are executable scripts -dist_salomescript_SCRIPTS= ${component}.exe -salomeres_DATA = ${component}_config.txt -""" -astercexeMakefile=Template(astercexeMakefile) - -asterexeMakefile="""include $$(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON = ${component}_module.py ${component}_component.py E_SUPERV.py -# These files are executable scripts -dist_salomescript_SCRIPTS= ${component}.exe -salomeres_DATA = ${component}_config.txt -""" -asterexeMakefile=Template(asterexeMakefile) - asterCompo=""" import sys,traceback,os import ${module}__POA diff --git a/module_generator/cpp_tmpl.py b/module_generator/cpp_tmpl.py index 055e67c..df5b591 100644 --- a/module_generator/cpp_tmpl.py +++ b/module_generator/cpp_tmpl.py @@ -113,7 +113,6 @@ ${component}_i::${component}_i(CORBA::ORB_ptr orb, const char *interfaceName) : Superv_Component_i(orb, poa, contId, instanceName, interfaceName) { - std::cerr << "create component" << std::endl; #if ${exe} setsig(SIGSEGV,&THandler); set_terminate(&terminateHandler); @@ -270,7 +269,6 @@ hxxCompo=Template(hxxCompo) cxxService=""" void ${component}_i::${service}(${parameters}) { - std::cerr << "${component}_i::${service}" << std::endl; beginService("${component}_i::${service}"); Superv_Component_i * component = dynamic_cast(this); char nom_instance[INSTANCE_LEN]; @@ -317,7 +315,6 @@ ${body} throw SALOME::SALOME_Exception(es); } endService("${component}_i::${service}"); - std::cerr << "end of ${component}_i::${service}" << std::endl; } """ @@ -360,36 +357,22 @@ exeCPP=Template(exeCPP) # Makefile compoMakefile=""" -include $$(top_srcdir)/adm_local/make_common_starter.am - -AM_CFLAGS=$$(KERNEL_INCLUDES) -fexceptions - -lib_LTLIBRARIES = lib${component}Engine.la lib${component}Engine_la_SOURCES = ${component}.cxx ${sources} nodist_lib${component}Engine_la_SOURCES = lib${component}Engine_la_CXXFLAGS = -I$$(top_builddir)/idl $$(KERNEL_INCLUDES) ${includes} lib${component}Engine_la_FFLAGS = $$(KERNEL_INCLUDES) -fexceptions ${includes} lib${component}Engine_la_LIBADD = -L$$(top_builddir)/idl -l${module} $$(FLIBS) ${libs} lib${component}Engine_la_LDFLAGS = ${rlibs} -salomeinclude_HEADERS = ${component}.hxx """ compoMakefile=Template(compoMakefile) compoEXEMakefile=""" -include $$(top_srcdir)/adm_local/make_common_starter.am - -AM_CFLAGS=$$(KERNEL_INCLUDES) -fexceptions - -lib_LTLIBRARIES = lib${component}Exelib.la lib${component}Exelib_la_SOURCES = ${component}.cxx nodist_lib${component}Exelib_la_SOURCES = lib${component}Exelib_la_CXXFLAGS = -I$$(top_builddir)/idl $$(KERNEL_INCLUDES) ${includes} lib${component}Exelib_la_FFLAGS = $$(KERNEL_INCLUDES) -fexceptions ${includes} lib${component}Exelib_la_LIBADD = -L$$(top_builddir)/idl -l${module} $$(FLIBS) ${libs} lib${component}Exelib_la_LDFLAGS = ${rlibs} -salomeinclude_HEADERS = ${component}.hxx -# These files are executable scripts -dist_salomescript_SCRIPTS= ${component}.exe """ compoEXEMakefile=Template(compoEXEMakefile) diff --git a/module_generator/cppcompo.py b/module_generator/cppcompo.py index 195e2b4..adc8977 100644 --- a/module_generator/cppcompo.py +++ b/module_generator/cppcompo.py @@ -5,13 +5,13 @@ import os from gener import Component, Invalid from cpp_tmpl import initService, cxxService, hxxCompo, cxxCompo -from cpp_tmpl import compoEXEMakefile, compoMakefile, exeCPP +from cpp_tmpl import exeCPP, compoEXEMakefile, compoMakefile class CPPComponent(Component): - def __init__(self, name, services=None, libs="", rlibs="", includes="", + def __init__(self, name, services=None, libs="", rlibs="", includes="", kind="lib", exe_path=None, sources=None): self.exe_path = exe_path - Component.__init__(self, name, services, impl="CPP", libs=libs, + Component.__init__(self, name, services, impl="CPP", libs=libs, rlibs=rlibs, includes=includes, kind=kind, sources=sources) @@ -28,28 +28,49 @@ class CPPComponent(Component): def makeCompo(self, gen): """generate files for C++ component - + return a dict where key is the file name and value is the content of the file """ cxxfile = "%s.cxx" % self.name hxxfile = "%s.hxx" % self.name if self.kind == "lib": sources = " ".join(map(os.path.basename,self.sources)) - return {"Makefile.am":compoMakefile.substitute(module=gen.module.name, + return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), + cxxfile:self.makecxx(gen), + hxxfile:self.makehxx(gen) + } + if self.kind == "exe": + return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), + self.name+".exe":exeCPP.substitute(compoexe=self.exe_path), + cxxfile:self.makecxx(gen, 1), + hxxfile:self.makehxx(gen) + } + + def getMakefileItems(self,gen): + makefileItems={"header":""" +include $(top_srcdir)/adm_local/make_common_starter.am + +AM_CFLAGS=$(KERNEL_INCLUDES) -fexceptions +"""} + if self.kind == "lib": + makefileItems["lib_LTLIBRARIES"]=["lib"+self.name+"Engine.la"] + makefileItems["salomeinclude_HEADERS"]=[self.name+".hxx"] + makefileItems["body"]=compoMakefile.substitute(module=gen.module.name, component=self.name, - libs=self.libs, + libs=self.libs, rlibs=self.rlibs, - sources=sources, - includes=self.includes), - cxxfile:self.makecxx(gen), hxxfile:self.makehxx(gen)} - if self.kind == "exe": - return {"Makefile.am":compoEXEMakefile.substitute(module=gen.module.name, + sources= " ".join(map(os.path.basename,self.sources)), + includes=self.includes) + elif self.kind == "exe": + makefileItems["lib_LTLIBRARIES"]=["lib"+self.name+"Exelib.la"] + makefileItems["salomeinclude_HEADERS"]=[self.name+".hxx"] + makefileItems["dist_salomescript_SCRIPTS"]=[self.name+".exe"] + makefileItems["body"]=compoEXEMakefile.substitute(module=gen.module.name, component=self.name, - libs=self.libs, + libs=self.libs, rlibs=self.rlibs, - includes=self.includes), - self.name+".exe":exeCPP.substitute(compoexe=self.exe_path), - cxxfile:self.makecxx(gen, 1), hxxfile:self.makehxx(gen)} + includes=self.includes) + return makefileItems def makehxx(self, gen): """return a string that is the content of .hxx file @@ -60,7 +81,7 @@ class CPPComponent(Component): service = service+gen.makeArgs(serv)+");" services.append(service) servicesdef = "\n".join(services) - return hxxCompo.substitute(component=self.name, module=gen.module.name, + return hxxCompo.substitute(component=self.name, module=gen.module.name, servicesdef=servicesdef) def makecxx(self, gen, exe=0): @@ -71,25 +92,25 @@ class CPPComponent(Component): defs = [] for serv in self.services: defs.append(serv.defs) - service = cxxService.substitute(component=self.name, service=serv.name, + service = cxxService.substitute(component=self.name, service=serv.name, parameters=gen.makeArgs(serv), body=serv.body, exe=exe) streams = [] for name, typ, dep in serv.instream: - streams.append(' create_calcium_port(this,"%s","%s","IN","%s");'% (name, typ, dep)) + streams.append(' create_calcium_port(this,(char *)"%s",(char *)"%s",(char *)"IN",(char *)"%s");'% (name, typ, dep)) instream = "\n".join(streams) streams = [] for name, typ, dep in serv.outstream: - streams.append(' create_calcium_port(this,"%s","%s","OUT","%s");'% (name, typ, dep)) + streams.append(' create_calcium_port(this,(char *)"%s",(char *)"%s",(char *)"OUT",(char *)"%s");'% (name, typ, dep)) outstream = "\n".join(streams) init = initService.substitute(component=self.name, service=serv.name, instream=instream, outstream=outstream) services.append(service) inits.append(init) - return cxxCompo.substitute(component=self.name, module=gen.module.name, - exe=exe, exe_path=self.exe_path, - servicesdef="\n".join(defs), - servicesimpl="\n".join(services), + return cxxCompo.substitute(component=self.name, module=gen.module.name, + exe=exe, exe_path=self.exe_path, + servicesdef="\n".join(defs), + servicesimpl="\n".join(services), initservice='\n'.join(inits)) diff --git a/module_generator/gener.py b/module_generator/gener.py index 59640f4..80efd13 100644 --- a/module_generator/gener.py +++ b/module_generator/gener.py @@ -75,10 +75,11 @@ def makedirs(namedir): os.makedirs(namedir) class Module(object): - def __init__(self, name, components=None, prefix=""): + def __init__(self, name, components=None, prefix="",layout="multidir"): self.name = name self.components = components or [] self.prefix = prefix or "%s_INSTALL" % name + self.layout=layout try: self.validate() except Invalid,e: @@ -126,6 +127,9 @@ class Component(object): def getImpl(self): return "SO", "" + def getMakefileItems(self,gen): + return {} + class Service(object): def __init__(self, name, inport=None, outport=None, instream=None, outstream=None, parallel_instream=None, parallel_outstream=None, body="", defs="", impl_type="sequential"): @@ -248,14 +252,42 @@ class Generator(object): srcs = {} makefile = "SUBDIRS=" - makefiles = [] + makefileItems={"header":""" +include $(top_srcdir)/adm_local/make_common_starter.am +AM_CFLAGS=$$(KERNEL_INCLUDES) -fexceptions +""", + "salomepython_PYTHON":[], + "dist_salomescript_SCRIPTS":[], + "salomeres_DATA":[], + "lib_LTLIBRARIES":[], + "salomeinclude_HEADERS":[], + "body":"", + } + for compo in module.components: - makefile = makefile+" "+compo.name - srcs[compo.name] = compo.makeCompo(self) - makefiles.append(" src/"+compo.name+"/Makefile") + #for components files + fdict=compo.makeCompo(self) + if self.module.layout=="multidir": + srcs[compo.name] = fdict + #for src/Makefile.am + makefile = makefile+" "+compo.name + else: + srcs.update(fdict) + #for src/Makefile.am + mdict=compo.getMakefileItems(self) + makefileItems["salomepython_PYTHON"]=makefileItems["salomepython_PYTHON"]+mdict.get("salomepython_PYTHON",[]) + makefileItems["dist_salomescript_SCRIPTS"]=makefileItems["dist_salomescript_SCRIPTS"]+mdict.get("dist_salomescript_SCRIPTS",[]) + makefileItems["salomeres_DATA"]=makefileItems["salomeres_DATA"]+mdict.get("salomeres_DATA",[]) + makefileItems["lib_LTLIBRARIES"]=makefileItems["lib_LTLIBRARIES"]+mdict.get("lib_LTLIBRARIES",[]) + makefileItems["salomeinclude_HEADERS"]=makefileItems["salomeinclude_HEADERS"]+mdict.get("salomeinclude_HEADERS",[]) + makefileItems["body"]=makefileItems["body"]+mdict.get("body","")+'\n' + + if self.module.layout=="multidir": + srcs["Makefile.am"] = makefile+'\n' + else: + srcs["Makefile.am"] = self.makeMakefile(makefileItems) - srcs["Makefile.am"] = makefile+'\n' - idlfile = "%s.idl" % module.name + #for catalog files catalogfile = "%sCatalog.xml" % module.name self.makeFiles({"autogen.sh":autogen, @@ -266,6 +298,14 @@ class Generator(object): "adm_local":{"make_common_starter.am":makecommon, "check_aster.m4":check_aster}, }, namedir) + #for configure.ac + configure_makefiles = [] + if self.module.layout=="multidir": + for compo in module.components: + configure_makefiles.append(" src/"+compo.name+"/Makefile") + #for idl files + idlfile = "%s.idl" % module.name + if paco: xmlfile = "%s.xml" % module.name PACO_BUILT_SOURCES = idlMakefilePaCO_BUILT_SOURCES.substitute(module=module.name) @@ -275,7 +315,7 @@ class Generator(object): PACO_INCLUDES = idlMakefilePACO_INCLUDES self.makeFiles({"configure.ac":configure.substitute(module=module.name.lower(), - makefiles='\n'.join(makefiles), + makefiles='\n'.join(configure_makefiles), paco_configure=paco_configure), "idl":{"Makefile.am":idlMakefile.substitute(module=module.name, PACO_BUILT_SOURCES=PACO_BUILT_SOURCES, @@ -288,7 +328,7 @@ class Generator(object): }, namedir) else : self.makeFiles({"configure.ac":configure.substitute(module=module.name.lower(), - makefiles='\n'.join(makefiles), + makefiles='\n'.join(configure_makefiles), paco_configure=""), "idl":{"Makefile.am":idlMakefile.substitute(module=module.name, PACO_BUILT_SOURCES="", @@ -300,10 +340,13 @@ class Generator(object): }, namedir) os.chmod(os.path.join(namedir, "autogen.sh"), 0777) - #copy source files if any in creates tree + #copy source files if any in created tree for compo in module.components: for src in compo.sources: - shutil.copyfile(src, os.path.join(namedir, "src", compo.name, os.path.basename(src))) + if self.module.layout=="multidir": + shutil.copyfile(src, os.path.join(namedir, "src", compo.name, os.path.basename(src))) + else: + shutil.copyfile(src, os.path.join(namedir, "src", os.path.basename(src))) for m4file in ("check_Kernel.m4", "check_omniorb.m4", "ac_linker_options.m4", "ac_cxx_option.m4", @@ -315,6 +358,24 @@ class Generator(object): return + def makeMakefile(self,makefileItems): + makefile="" + if makefileItems.has_key("header"): + makefile=makefile + makefileItems["header"]+'\n' + if makefileItems.has_key("lib_LTLIBRARIES"): + makefile=makefile+"lib_LTLIBRARIES= "+" ".join(makefileItems["lib_LTLIBRARIES"])+'\n' + if makefileItems.has_key("salomepython_PYTHON"): + makefile=makefile+"salomepython_PYTHON= "+" ".join(makefileItems["salomepython_PYTHON"])+'\n' + if makefileItems.has_key("dist_salomescript_SCRIPTS"): + makefile=makefile+"dist_salomescript_SCRIPTS= "+" ".join(makefileItems["dist_salomescript_SCRIPTS"])+'\n' + if makefileItems.has_key("salomeres_DATA"): + makefile=makefile+"salomeres_DATA= "+" ".join(makefileItems["salomeres_DATA"])+'\n' + if makefileItems.has_key("salomeinclude_HEADERS"): + makefile=makefile+"salomeinclude_HEADERS= "+" ".join(makefileItems["salomeinclude_HEADERS"])+'\n' + if makefileItems.has_key("body"): + makefile=makefile+makefileItems["body"]+'\n' + return makefile + def makeArgs(self, service): """generate source service for arguments""" params = [] diff --git a/module_generator/pycompo.py b/module_generator/pycompo.py index 0abf5d4..2b71161 100644 --- a/module_generator/pycompo.py +++ b/module_generator/pycompo.py @@ -4,7 +4,6 @@ import os from gener import Component, Invalid from pyth_tmpl import pyinitService, pyService, pyCompoEXE, pyCompo -from pyth_tmpl import pycompoEXEMakefile, pycompoMakefile import textwrap from string import split,rstrip,join @@ -32,24 +31,29 @@ class PYComponent(Component): raise Invalid("kind must be one of %s for component %s" % (kinds,self.name)) def makeCompo(self, gen): - """generate component sources as a dictionary containing + """generate component sources as a dictionary containing file names (key) and file content (values) """ pyfile = "%s.py" % self.name sources = " ".join(map(os.path.basename,self.sources)) if self.kind == "lib": - return {"Makefile.am":pycompoMakefile.substitute(module=gen.module.name, - component=self.name, - sources=sources), + return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), pyfile:self.makepy(gen) } if self.kind == "exe": - return {"Makefile.am":pycompoEXEMakefile.substitute(module=gen.module.name, - component=self.name, - sources=sources), + return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)), self.name+".exe":self.makepyexe(gen), } + def getMakefileItems(self,gen): + makefileItems={"header":"include $(top_srcdir)/adm_local/make_common_starter.am"} + if self.kind == "lib": + makefileItems["salomepython_PYTHON"]=[self.name+".py"]+self.sources + if self.kind == "exe": + makefileItems["salomepython_PYTHON"]=self.sources + makefileItems["dist_salomescript_SCRIPTS"]=[self.name+".exe"] + return makefileItems + def makepy(self, gen): """generate standard SALOME component source (python module)""" services = [] diff --git a/module_generator/pyth_tmpl.py b/module_generator/pyth_tmpl.py index 3974e1c..d43c804 100644 --- a/module_generator/pyth_tmpl.py +++ b/module_generator/pyth_tmpl.py @@ -109,16 +109,3 @@ pyinitService=Template(pyinitService) pyinitCEXEService=pyinitService pyinitEXEService=pyinitService -#Makefile - -pycompoMakefile="""include $$(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON = ${component}.py ${sources} -""" -pycompoMakefile=Template(pycompoMakefile) - -pycompoEXEMakefile="""include $$(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON = ${sources} -dist_salomescript_SCRIPTS= ${component}.exe -""" -pycompoEXEMakefile=Template(pycompoEXEMakefile) - -- 2.39.2