Salome HOME
integration patch pour version windows
[tools/sat.git] / src / environment.py
index c094300832bbde7613ef0fa3e19c1e1fe454c4a2..5c4c11cd653dcf03e55c7b4899f8cd6e586b2cd3 100644 (file)
@@ -54,10 +54,15 @@ class Environ:
         :return: the replaced variable
         :rtype: str
         """
-        if "$" in value:
+        if src.architecture.is_windows():
+            delim = "%"
+        else:
+            delim = "$"
+        if delim in value:
             # The string.Template class is a string class 
             # for supporting $-substitutions
             zt = string.Template(value)
+            zt.delimiter = delim
             try:
                 value = zt.substitute(self.environ)
             except KeyError as exc:
@@ -212,6 +217,7 @@ class SalomeEnviron:
         self.enable_simple_env_script = enable_simple_env_script
         self.silent = False
         self.has_python = False
+        self.__set_sorted_products_list()
 
     def __repr__(self):
         """easy almost exhaustive quick resume for debug print"""
@@ -222,6 +228,25 @@ class SalomeEnviron:
         }
         return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(res))
 
+    def __set_sorted_products_list(self):
+        from compile import get_dependencies_graph, depth_first_topo_graph
+        all_products_infos = src.product.get_products_infos(
+                                 self.cfg.APPLICATION.products,
+                                 self.cfg)
+        
+        all_products_graph=get_dependencies_graph(all_products_infos)
+        visited_nodes=[]
+        sorted_nodes=[]
+        for n in all_products_graph:
+            if n not in visited_nodes:
+                visited_nodes,sorted_nodes=depth_first_topo_graph(
+                                               all_products_graph, 
+                                               n, 
+                                               visited_nodes,
+                                               sorted_nodes)
+        self.sorted_product_list=sorted_nodes
+
+
     def append(self, key, value, sep=os.pathsep):
         """\
         append value to key using sep
@@ -363,7 +388,8 @@ class SalomeEnviron:
         self.add_line(1)
         self.add_comment("reset these sensitive variables to avoid bad environment interactions")
         self.add_comment("comment these to lines if you wish a different behaviour")
-        self.set("LD_LIBRARY_PATH", "")
+        if not src.architecture.is_windows():
+           self.set("LD_LIBRARY_PATH", "")
         self.set("PYTHONPATH", "")
         self.add_line(1)
 
@@ -415,7 +441,7 @@ class SalomeEnviron:
             compo_name = pi.component_name
         else:
             compo_name = pi.name
-        self.prepend('SALOME_MODULES', compo_name, ',')
+        self.append('SALOME_MODULES', compo_name, ',')
         
         
     def set_salome_generic_product_env(self, pi):
@@ -427,7 +453,6 @@ class SalomeEnviron:
         # Construct XXX_ROOT_DIR
         env_root_dir = self.get(pi.name + "_ROOT_DIR")
         l_binpath_libpath = []
-
         # create additional ROOT_DIR for CPP components
         if 'component_name' in pi:
             compo_name = pi.component_name
@@ -553,7 +578,6 @@ class SalomeEnviron:
 
         # Get the informations corresponding to the product
         pi = src.product.get_product_config(self.cfg, product)
-        
         # skip compile time products at run time 
         if not self.forBuild:
             if src.product.product_is_compile_time(pi):
@@ -707,7 +731,6 @@ class SalomeEnviron:
             traceback.print_tb(exceptionTraceback)
             traceback.print_exc()
 
-
     def set_products(self, logger, src_root=None):
         """\
         Sets the environment for all the products. 
@@ -719,12 +742,12 @@ class SalomeEnviron:
         self.add_comment('setting environ for all products')
 
         # Make sure that the python lib dirs are set after python
-        if "Python" in self.cfg.APPLICATION.products:
+        if "Python" in self.sorted_product_list:
             self.set_a_product("Python", logger)
             self.set_python_libdirs()
 
         # The loop on the products
-        for product in self.cfg.APPLICATION.products.keys():
+        for product in self.sorted_product_list:
             if product == "Python":
                 continue
             self.set_a_product(product, logger)
@@ -739,16 +762,22 @@ class SalomeEnviron:
         """
         DBG.write("set_full_environ for", env_info)
         # DBG.write("set_full_environ config", self.cfg.APPLICATION.environ, True)
-
         # set product environ
         self.set_application_env(logger)
 
-        if "Python" in env_info:
+        # use the sorted list of all products to sort the list of products 
+        # we have to set
+        sorted_product_list=[]
+        for n in self.sorted_product_list:
+            if n in env_info:
+                sorted_product_list.append(n)
+
+        if "Python" in sorted_product_list:
             self.set_a_product("Python", logger)
             self.set_python_libdirs()
 
         # set products
-        for product in env_info:
+        for product in sorted_product_list:
             if product == "Python":
                 continue
             self.set_a_product(product, logger)
@@ -882,7 +911,6 @@ class FileEnvWriter:
         if not self.silent:
             self.logger.write(_("Create environment file %s\n") % 
                               src.printcolors.printcLabel(filename), 3)
-
         # create then env object
         env_file = open(os.path.join(self.out_dir, filename), "w")
 
@@ -910,11 +938,9 @@ class FileEnvWriter:
         else:
             # set env from the APPLICATION
             env.set_application_env(self.logger)
-            
             # set the products
             env.set_products(self.logger,
                             src_root=self.src_root)
-
         # Add the additional environment if it is not empty
         if len(additional_env) != 0:
             env.add_line(1)