]> SALOME platform Git repositories - tools/yacsgen.git/commitdiff
Salome HOME
CCAR: add definition parameter "sources" to C++, F77, Python components.
authorcaremoli <caremoli>
Mon, 26 Jan 2009 10:33:54 +0000 (10:33 +0000)
committercaremoli <caremoli>
Mon, 26 Jan 2009 10:33:54 +0000 (10:33 +0000)
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)

12 files changed:
Examples/fort1/bidul.f [new file with mode: 0644]
Examples/fort1/code2.f
Examples/fort1/components.py
Examples/pyth1/bidul.py [new file with mode: 0644]
Examples/pyth1/components.py
MANIFEST.in
module_generator/cpp_tmpl.py
module_generator/cppcompo.py
module_generator/fcompo.py
module_generator/gener.py
module_generator/pycompo.py
module_generator/pyth_tmpl.py

diff --git a/Examples/fort1/bidul.f b/Examples/fort1/bidul.f
new file mode 100644 (file)
index 0000000..64011d9
--- /dev/null
@@ -0,0 +1,4 @@
+      subroutine bidul()
+      write(6,*)"coucou"
+      return
+      end
index b6e58d6fce1b4b943fe26ad35fe7bebf59e3c2e1..d5ab3b1bc9a0fa90d00d68d1272a7332070cecc8 100644 (file)
@@ -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
index a09cfa7560dc296f3896f31fbb2ac3592b40ab91..3c44fda040313a25d579741679897287f6aaddf3 100644 (file)
@@ -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 (file)
index 0000000..f622882
--- /dev/null
@@ -0,0 +1,2 @@
+def f():
+  print "coucou"
index 831bdf6587ec4c9d0da50d95abecf6edefd5f21d..ae8608f539647c3b9eb220c86a7c43a3c7387a57 100644 (file)
@@ -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"],
          )
 
 
index 3483581967baa6a72a3930cb93c25afca0431cc9..46117299f2d35a35c6c4e296c98c0fb44acfec69 100644 (file)
@@ -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
 
index 38fdaf10d6e4efda0740bb8e333e8d815a3b6b17..bc842fa29029f6b4cedf3c21cfd854f9be938323 100644 (file)
@@ -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}
index a912e17f93d4c9ae981c0b88d98280c7645dae5a..e2d950801bdad4f5d542dff195c27ea1d5d7cd1a 100644 (file)
@@ -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":
index 5c32b92a09f8b041b8c3c4f1a22b9c8f565b44bf..02b8d1153f28268691d4a835c4fc36745322eb1d 100644 (file)
@@ -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:
index 22d0c3e58aea4f13f4a3a0f896e4cab76160140f..18fc93be4a79bb79b9320e982abee80609150d12 100644 (file)
@@ -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",
index 375297be4446a4e6d29faa2954bb3e0c3e6a2f05..69ac03f5e49f49d2e74607fa5a04523212ad8016 100644 (file)
@@ -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 = []
index e863c41b8b7235154ebbdd69a7fea6563fe42c73..dd745760965150477d76715e2d6d3b90c25dff75 100644 (file)
@@ -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)