Salome HOME
in logs, collapse by default the logs
[tools/sat.git] / src / environment.py
index 721fbeeabfeda1f49e937a42ff4f2f86f4a2aac6..d295a5abfacc839cd5c0c7fbe77545c27e854189 100644 (file)
@@ -167,7 +167,7 @@ class SalomeEnviron:
     """Class to manage the environment of SALOME.
     """
 
-    def __init__(self, cfg, environ, forBuild=False):
+    def __init__(self, cfg, environ, forBuild=False, for_package=None):
         '''Initialization.
 
         :param cfg Config: the global config
@@ -175,10 +175,13 @@ class SalomeEnviron:
                                 to store the environment variables
         :param forBuild bool: If true, it is a launch environment, 
                               else a build one
+        :param for_package str: If not None, produce a relative environment 
+                                designed for a package. 
         '''
         self.environ = environ
         self.cfg = cfg
         self.forBuild = forBuild
+        self.for_package = for_package
         self.silent = False
 
     def __repr__(self):
@@ -299,13 +302,16 @@ class SalomeEnviron:
         """Get the products name to add in SALOME_MODULES environment variable
            It is the name of the product, except in the case where the is a 
            component name. And it has to be in SALOME_MODULES variable only 
-           if has_gui = "yes"
+           if the product has the property has_salome_hui = "yes"
         
         :param lProducts list: List of products to potentially add
         """
-        lProdHasGui = [p for p in lProducts if 'type ' in 
-                    src.product.get_product_config(self.cfg, p) and 
-                    src.product.get_product_config(self.cfg, p).type=='salome']
+        lProdHasGui = [p for p in lProducts if 'properties' in 
+            src.product.get_product_config(self.cfg, p) and
+            'has_salome_gui' in 
+            src.product.get_product_config(self.cfg, p).properties and
+            src.product.get_product_config(self.cfg,
+                                           p).properties.has_salome_gui=='yes']
         lProdName = []
         for ProdName in lProdHasGui:
             pi = src.product.get_product_config(self.cfg, ProdName)
@@ -325,7 +331,22 @@ class SalomeEnviron:
         if 'environ' in self.cfg.APPLICATION:
             self.add_comment("APPLICATION environment")
             for p in self.cfg.APPLICATION.environ:
-                self.set(p, self.cfg.APPLICATION.environ[p])
+                val = self.cfg.APPLICATION.environ[p]
+                # "_" means that the value must be prepended
+                if p.startswith("_"):
+                    # separator exception for PV_PLUGIN_PATH
+                    if p[1:] == 'PV_PLUGIN_PATH':
+                        self.prepend(p[1:], val, ';')
+                    else:
+                        self.prepend(p[1:], val)
+                elif p.endswith("_"):
+                    # separator exception for PV_PLUGIN_PATH
+                    if p[:-1] == 'PV_PLUGIN_PATH':
+                        self.append(p[:-1], val, ';')
+                    else:
+                        self.append(p[:-1], val)
+                else:
+                    self.set(p, val)
             self.add_line(1)
 
         # If there is an "environ_script" section, load the scripts
@@ -339,7 +360,8 @@ class SalomeEnviron:
                 self.add_line(1)
         
         # If there is profile (SALOME), then define additional variables
-        if 'profile' in self.cfg.APPLICATION:
+        if ('profile' in self.cfg.APPLICATION and 
+                                    "product" in self.cfg.APPLICATION.profile):
             profile_product = self.cfg.APPLICATION.profile.product
             product_info_profile = src.product.get_product_config(self.cfg,
                                                             profile_product)
@@ -352,10 +374,6 @@ class SalomeEnviron:
                                    "resources",
                                    profile_product.lower() ) )
         
-        # The list of products to launch
-        lProductsName = self.get_names(self.cfg.APPLICATION.products.keys())
-        
-        self.set( "SALOME_MODULES",    ','.join(lProductsName))
 
     def set_salome_minimal_product_env(self, product_info, logger):
         """Sets the minimal environment for a SALOME product.
@@ -372,20 +390,19 @@ class SalomeEnviron:
             elif not self.silent:
                 logger.write("  " + _("No install_dir for product %s\n") %
                               product_info.name, 5)
+        
+        if not self.for_package:
+            # set source dir, unless no source dir
+            if not src.product.product_is_fixed(product_info):
+                src_dir = product_info.name + "_SRC_DIR"
+                if not self.is_defined(src_dir):
+                    self.set(src_dir, product_info.source_dir)
 
-        # set source dir, unless no source dir
-        if not src.product.product_is_fixed(product_info):
-            src_dir = product_info.name + "_SRC_DIR"
-            if not self.is_defined(src_dir):
-                self.set(src_dir, product_info.source_dir)
-
-    def set_salome_generic_product_env(self, product):
+    def set_salome_generic_product_env(self, pi):
         """Sets the generic environment for a SALOME product.
         
-        :param product str: The product name    
+        :param pi Config: The product description
         """
-        # get the product descritption
-        pi = src.product.get_product_config(self.cfg, product)
         # Construct XXX_ROOT_DIR
         env_root_dir = self.get(pi.name + "_ROOT_DIR")
         l_binpath_libpath = []
@@ -393,7 +410,7 @@ class SalomeEnviron:
         # create additional ROOT_DIR for CPP components
         if 'component_name' in pi:
             compo_name = pi.component_name
-            if compo_name + "CPP" == product:
+            if compo_name + "CPP" == pi.name:
                 compo_root_dir = compo_name + "_ROOT_DIR"
                 envcompo_root_dir = os.path.join(
                             self.cfg.TOOLS.common.install_root, compo_name )
@@ -427,6 +444,35 @@ class SalomeEnviron:
                 ]
             self.prepend('PYTHONPATH', l)
 
+    def set_cpp_env(self, product_info):
+        """Sets the generic environment for a SALOME cpp product.
+        
+        :param product_info Config: The product description
+        """
+        # Construct XXX_ROOT_DIR
+        env_root_dir = self.get(product_info.name + "_ROOT_DIR")
+        l_binpath_libpath = []
+
+        # Construct the paths to prepend to PATH and LD_LIBRARY_PATH and 
+        # PYTHONPATH
+        bin_path = os.path.join(env_root_dir, 'bin')
+        lib_path = os.path.join(env_root_dir, 'lib')
+        l_binpath_libpath.append( (bin_path, lib_path) )
+
+        for bin_path, lib_path in l_binpath_libpath:
+            if not self.forBuild:
+                self.prepend('PATH', bin_path)
+                if src.architecture.is_windows():
+                    self.prepend('PATH', lib_path)
+                else :
+                    self.prepend('LD_LIBRARY_PATH', lib_path)
+
+            l = [ bin_path, lib_path,
+                  os.path.join(env_root_dir, self.python_lib0),
+                  os.path.join(env_root_dir, self.python_lib1)
+                ]
+            self.prepend('PYTHONPATH', l)
+
     def load_cfg_environment(self, cfg_env):
         """Loads environment defined in cfg_env 
         
@@ -478,6 +524,11 @@ class SalomeEnviron:
         # Get the informations corresponding to the product
         pi = src.product.get_product_config(self.cfg, product)
         
+        if self.for_package:
+            pi.install_dir = os.path.join("out_dir_Path",
+                                          self.for_package,
+                                          pi.name)
+                    
         # Do not define environment if the product is native
         if src.product.product_is_native(pi):
             return
@@ -492,8 +543,35 @@ class SalomeEnviron:
         if src.product.product_is_salome(pi):
             # set environment using definition of the product
             self.set_salome_minimal_product_env(pi, logger)
-            self.set_salome_generic_product_env(product)
-
+            self.set_salome_generic_product_env(pi)
+        
+        if src.product.product_is_cpp(pi):
+            # set a specific environment for cpp modules
+            self.set_salome_minimal_product_env(pi, logger)
+            self.set_cpp_env(pi)
+            
+            if src.product.product_is_generated(pi):
+                if "component_name" in pi:
+                    # hack the source and install directories in order to point  
+                    # on the generated product source install directories
+                    install_dir_save = pi.install_dir
+                    source_dir_save = pi.source_dir
+                    name_save = pi.name
+                    pi.install_dir = os.path.join(self.cfg.APPLICATION.workdir,
+                                                  "INSTALL",
+                                                  pi.component_name)
+                    pi.source_dir = os.path.join(self.cfg.APPLICATION.workdir,
+                                                  "GENERATED",
+                                                  pi.component_name)
+                    pi.name = pi.component_name
+                    self.set_salome_minimal_product_env(pi, logger)
+                    self.set_salome_generic_product_env(pi)
+                    
+                    # Put original values
+                    pi.install_dir = install_dir_save
+                    pi.source_dir = source_dir_save
+                    pi.name = name_save
+        
         # Put the environment define in the configuration of the product
         if "environ" in pi:
             self.load_cfg_environment(pi.environ)
@@ -578,8 +656,6 @@ class SalomeEnviron:
         self.add_line(1)
         self.add_comment('setting environ for all products')
 
-        self.set_python_libdirs()
-
         # Set the application working directory
         if src_root is None:
             src_root = self.cfg.APPLICATION.workdir
@@ -592,8 +668,15 @@ class SalomeEnviron:
         self.set("SALOME_APPLI_ROOT",
                  os.path.join(self.cfg.APPLICATION.workdir, appli_name))
 
+        # Make sure that the python lib dirs are set after python
+        if "Python" in self.cfg.APPLICATION.products:
+            self.set_a_product("Python", logger)
+            self.set_python_libdirs()
+
         # The loop on the products
         for product in self.cfg.APPLICATION.products.keys():
+            if product == "Python":
+                continue
             self.set_a_product(product, logger)
             self.finish(False)
  
@@ -659,6 +742,11 @@ class FileEnvWriter:
         else:
             # set env from the APPLICATION
             env.set_application_env(self.logger)
+            
+            # The list of products to launch
+            lProductsName = env.get_names(self.config.APPLICATION.products.keys())
+            env.set( "SALOME_MODULES",    ','.join(lProductsName))
+            
             # set the products
             env.set_products(self.logger,
                             src_root=self.src_root)
@@ -669,24 +757,32 @@ class FileEnvWriter:
 
         return env_file.name
    
-    def write_cfgForPy_file(self, filename, additional_env = {}):
+    def write_cfgForPy_file(self,
+                            filename,
+                            additional_env = {},
+                            for_package = None):
         """Append to current opened aFile a cfgForPy 
            environment (SALOME python launcher).
            
         :param filename str: the file path
         :param additional_env dict: a dictionary of additional variables 
                                     to add to the environment
+        :param for_package str: If not None, produce a relative environment 
+                                designed for a package. 
         """
         if not self.silent:
             self.logger.write(_("Create configuration file %s\n") % 
-                              src.printcolors.printcLabel(aFile.name), 3)
+                              src.printcolors.printcLabel(filename.name), 3)
 
         # create then env object
         tmp = src.fileEnviron.get_file_environ(filename, 
                                                "cfgForPy", 
                                                {})
         # environment for launch
-        env = SalomeEnviron(self.config, tmp, forBuild=False)
+        env = SalomeEnviron(self.config,
+                            tmp,
+                            forBuild=False,
+                            for_package=for_package)
         env.silent = self.silent
 
         if self.env_info is not None:
@@ -695,6 +791,10 @@ class FileEnvWriter:
             # set env from PRODUCT
             env.set_application_env(self.logger)
 
+            # The list of products to launch
+            lProductsName = env.get_names(self.config.APPLICATION.products.keys())
+            env.set( "SALOME_MODULES",    ','.join(lProductsName))
+
             # set the products
             env.set_products(self.logger,
                             src_root=self.src_root)