From: caremoli Date: Mon, 26 Jan 2009 10:33:54 +0000 (+0000) Subject: CCAR: add definition parameter "sources" to C++, F77, Python components. X-Git-Tag: V5_1_1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b93ea75718e6fa07ae5959de568cbea1f715788f;p=tools%2Fyacsgen.git CCAR: add definition parameter "sources" to C++, F77, Python components. It's now possible to add some files that will be copied to module source tree and compiled (not needed for Python) and linked into component lib (see Examples for more) --- diff --git a/Examples/fort1/bidul.f b/Examples/fort1/bidul.f new file mode 100644 index 0000000..64011d9 --- /dev/null +++ b/Examples/fort1/bidul.f @@ -0,0 +1,4 @@ + subroutine bidul() + write(6,*)"coucou" + return + end diff --git a/Examples/fort1/code2.f b/Examples/fort1/code2.f index b6e58d6..d5ab3b1 100644 --- a/Examples/fort1/code2.f +++ b/Examples/fort1/code2.f @@ -6,6 +6,7 @@ CALL cplDB(compo,CP_ITERATION,t0,t1,1,'PARAM',1,nval,tt,info) write(6,*)'info=',info write(6,*)'tt=',tt + call bidul() c=a+b return end diff --git a/Examples/fort1/components.py b/Examples/fort1/components.py index a09cfa7..3c44fda 100644 --- a/Examples/fort1/components.py +++ b/Examples/fort1/components.py @@ -15,7 +15,7 @@ c1=F77Component("fcode1", services=[Service("serv1",inport=[("a","double"),("b", c2=F77Component("fcode2", services=[Service("serv1",inport=[("a","double"),("b","double")], outport=[("c","double")], instream=[("PARAM","CALCIUM_double","I")],), ], - libs="-L%s -lcode2" % cwd) + sources=["code2.f","bidul.f"]) g=Generator(Module("fcompos",components=[c1,c2],prefix="./install"),context) g.generate() diff --git a/Examples/pyth1/bidul.py b/Examples/pyth1/bidul.py new file mode 100644 index 0000000..f622882 --- /dev/null +++ b/Examples/pyth1/bidul.py @@ -0,0 +1,2 @@ +def f(): + print "coucou" diff --git a/Examples/pyth1/components.py b/Examples/pyth1/components.py index 831bdf6..ae8608f 100644 --- a/Examples/pyth1/components.py +++ b/Examples/pyth1/components.py @@ -8,6 +8,9 @@ context={'update':1, cwd=os.getcwd() +defs=""" +import bidul +""" body=""" #b1 @@ -20,6 +23,7 @@ body=""" val=numpy.zeros(10,'d') info,tt,ii,mval=calcium.cp_ldb(component, dep, 0.,1., 1, "aa", nval,val) print mval,val + bidul.f() c=a+b d=a-b err=calcium.cp_fin(component,calcium.CP_ARRET) @@ -29,9 +33,10 @@ c1=PYComponent("compo2",services=[ outport=[("c","double"),("d","double")], instream=[("aa","CALCIUM_double","I"),], outstream=[("ba","CALCIUM_double","I"),], - defs="#def1",body=body, + defs=defs,body=body, ), ], + sources=["bidul.py"], ) diff --git a/MANIFEST.in b/MANIFEST.in index 3483581..4611729 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,7 @@ -include README.txt -recursive-include Examples/fort1 code1.f code2.f components.py coupling.xml Makefile README.txt -recursive-include Examples/cpp1 components.py coupling.xml README.txt -recursive-include Examples/pyth1 components.py coupling.xml README.txt +include Examples/fort1/code1.f Examples/fort1/code2.f Examples/fort1/components.py Examples/fort1/coupling.xml Examples/fort1/Makefile Examples/fort1/README.txt +include Examples/cpp1/components.py Examples/cpp1/coupling.xml Examples/cpp1/README.txt +include Examples/pyth1/components.py Examples/pyth1/coupling.xml Examples/pyth1/README.txt +include Examples/fort2/code1.f Examples/fort2/code2.f Examples/fort2/components.py Examples/fort2/coupling.xml Examples/fort2/Makefile Examples/fort2/README.txt +include Examples/cpp2/components.py Examples/cpp2/coupling.xml Examples/cpp2/README.txt Examples/cpp2/Makefile Examples/cpp2/prog.cxx +include Examples/pyth2/components.py Examples/pyth2/coupling.xml Examples/pyth2/README.txt diff --git a/module_generator/cpp_tmpl.py b/module_generator/cpp_tmpl.py index 38fdaf1..bc842fa 100644 --- a/module_generator/cpp_tmpl.py +++ b/module_generator/cpp_tmpl.py @@ -364,7 +364,7 @@ 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 +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} diff --git a/module_generator/cppcompo.py b/module_generator/cppcompo.py index a912e17..e2d9508 100644 --- a/module_generator/cppcompo.py +++ b/module_generator/cppcompo.py @@ -8,10 +8,11 @@ from cpp_tmpl import compoEXEMakefile, compoMakefile, exeCPP class CPPComponent(Component): def __init__(self, name, services=None, libs="", rlibs="", includes="", - kind="lib", exe_path=None): + kind="lib", exe_path=None, sources=None): self.exe_path = exe_path Component.__init__(self, name, services, impl="CPP", libs=libs, - rlibs=rlibs, includes=includes, kind=kind) + rlibs=rlibs, includes=includes, kind=kind, + sources=sources) def validate(self): """ validate component definition parameters""" @@ -32,10 +33,12 @@ class CPPComponent(Component): cxxfile = "%s.cxx" % self.name hxxfile = "%s.hxx" % self.name if self.kind == "lib": + sources = " ".join(self.sources) return {"Makefile.am":compoMakefile.substitute(module=gen.module.name, component=self.name, libs=self.libs, rlibs=self.rlibs, + sources=sources, includes=self.includes), cxxfile:self.makecxx(gen), hxxfile:self.makehxx(gen)} if self.kind == "exe": diff --git a/module_generator/fcompo.py b/module_generator/fcompo.py index 5c32b92..02b8d11 100644 --- a/module_generator/fcompo.py +++ b/module_generator/fcompo.py @@ -12,10 +12,10 @@ else: class F77Component(CPPComponent): def __init__(self, name, services=None, libs="", rlibs="", - kind="lib", exe_path=None): - self.exe_path = exe_path - Component.__init__(self, name, services, impl="F77", - libs=libs, rlibs=rlibs, kind=kind) + kind="lib", exe_path=None, sources=None): + CPPComponent.__init__(self, name, services, libs=libs, rlibs=rlibs, + kind=kind, exe_path=exe_path, sources=sources) + self.impl = "F77" def makebody(self): for serv in self.services: diff --git a/module_generator/gener.py b/module_generator/gener.py index 22d0c3e..18fc93b 100644 --- a/module_generator/gener.py +++ b/module_generator/gener.py @@ -70,10 +70,11 @@ class Module(object): if compo.name in lcompo: raise Invalid("%s is already defined as a component of the module" % compo.name) lcompo.add(compo.name) + compo.validate() class Component(object): def __init__(self, name, services=None, impl="PY", libs="", rlibs="", - includes="", kind="lib"): + includes="", kind="lib", sources=None): self.name = name self.impl = impl self.kind = kind @@ -81,7 +82,7 @@ class Component(object): self.libs = libs self.rlibs = rlibs self.includes = includes - self.validate() + self.sources = sources or [] def validate(self): if self.impl not in ValidImpl: @@ -95,6 +96,10 @@ class Component(object): lnames.add(serv.name) serv.validate() + for src in self.sources: + if not os.path.exists(src): + raise Invalid("Source file %s does not exist" % src) + def getImpl(self): return "SO", "" @@ -207,6 +212,10 @@ class Generator(object): "adm_local":{"make_common_starter.am":makecommon, "check_aster.m4":check_aster}, }, namedir) os.chmod(os.path.join(namedir, "autogen.sh"), 0777) + #copy source files if any in creates tree + for compo in module.components: + for src in compo.sources: + shutil.copyfile(src, os.path.join(namedir, "src", compo.name, src)) for m4file in ("check_Kernel.m4", "check_omniorb.m4", "ac_linker_options.m4", "ac_cxx_option.m4", diff --git a/module_generator/pycompo.py b/module_generator/pycompo.py index 375297b..69ac03f 100644 --- a/module_generator/pycompo.py +++ b/module_generator/pycompo.py @@ -6,9 +6,11 @@ from pyth_tmpl import pyinitService, pyService, pyCompoEXE, pyCompo from pyth_tmpl import pycompoEXEMakefile, pycompoMakefile class PYComponent(Component): - def __init__(self, name, services=None, python_path=None, kind="lib"): + def __init__(self, name, services=None, python_path=None, kind="lib", + sources=None): self.python_path = python_path or [] - Component.__init__(self, name, services, impl="PY", kind=kind) + Component.__init__(self, name, services, impl="PY", kind=kind, + sources=sources) def validate(self): Component.validate(self) @@ -18,13 +20,19 @@ class PYComponent(Component): def makeCompo(self, gen): pyfile = "%s.py" % self.name + sources = " ".join(self.sources) if self.kind == "lib": return {"Makefile.am":pycompoMakefile.substitute(module=gen.module.name, - component=self.name), pyfile:self.makepy(gen)} + component=self.name, + sources=sources), + pyfile:self.makepy(gen) + } if self.kind == "exe": return {"Makefile.am":pycompoEXEMakefile.substitute(module=gen.module.name, - component=self.name), self.name+".exe":self.makepyexe(gen), - } + component=self.name, + sources=sources), + self.name+".exe":self.makepyexe(gen), + } def makepy(self, gen): services = [] diff --git a/module_generator/pyth_tmpl.py b/module_generator/pyth_tmpl.py index e863c41..dd74576 100644 --- a/module_generator/pyth_tmpl.py +++ b/module_generator/pyth_tmpl.py @@ -114,11 +114,12 @@ pyinitEXEService=pyinitService #Makefile pycompoMakefile="""include $$(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON = ${component}.py +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)