Salome HOME
sat prepare and sat install with pip, triggered by pip properties
[tools/sat.git] / commands / compile.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20 import re
21 import subprocess
22 import src
23 import src.debug as DBG
24
25 # Compatibility python 2/3 for input function
26 # input stays input for python 3 and input = raw_input for python 2
27 try: 
28     input = raw_input
29 except NameError: 
30     pass
31
32
33 # Define all possible option for the compile command :  sat compile <options>
34 parser = src.options.Options()
35 parser.add_option('p', 'products', 'list2', 'products',
36     _('Optional: products to compile. This option accepts a comma separated list.'))
37 parser.add_option('', 'with_fathers', 'boolean', 'fathers',
38     _("Optional: build all necessary products to the given product (KERNEL is "
39       "build before building GUI)."), False)
40 parser.add_option('', 'with_children', 'boolean', 'children',
41     _("Optional: build all products using the given product (all SMESH plugins"
42       " are build after SMESH)."), False)
43 parser.add_option('', 'clean_all', 'boolean', 'clean_all',
44     _("Optional: clean BUILD dir and INSTALL dir before building product."),
45     False)
46 parser.add_option('', 'clean_install', 'boolean', 'clean_install',
47     _("Optional: clean INSTALL dir before building product."), False)
48 parser.add_option('', 'make_flags', 'string', 'makeflags',
49     _("Optional: add extra options to the 'make' command."))
50 parser.add_option('', 'show', 'boolean', 'no_compile',
51     _("Optional: DO NOT COMPILE just show if products are installed or not."),
52     False)
53 parser.add_option('', 'stop_first_fail', 'boolean', 'stop_first_fail', _(
54                   "Optional: Stops the command at first product compilation"
55                   " fail."), False)
56 parser.add_option('', 'check', 'boolean', 'check', _(
57                   "Optional: execute the unit tests after compilation"), False)
58
59 parser.add_option('', 'clean_build_after', 'boolean', 'clean_build_after', 
60                   _('Optional: remove the build directory after successful compilation'), False)
61
62
63 # from sat product infos, represent the product dependencies in a simple python graph
64 # keys are nodes, the list of dependencies are values
65 def get_dependencies_graph(p_infos):
66     graph={}
67     for (p_name,p_info) in p_infos:
68         graph[p_name]=p_info.depend
69     return graph
70
71 # this recursive function calculates all the dependencies of node start
72 def depth_search_graph(graph, start, visited=[]):
73     visited= visited+ [start]
74     for node in graph[start]:  # for all nodes in start dependencies
75         if node not in visited:
76             visited=depth_search_graph(graph, node, visited)
77     return visited
78
79 # find a path from start node to end (a group of nodes)
80 def find_path_graph(graph, start, end, path=[]):
81     path = path + [start]
82     if start in end:
83         return path
84     if not graph.has_key(start):
85         return None
86     for node in graph[start]:
87         if node not in path:
88             newpath = find_path_graph(graph, node, end, path)
89             if newpath: return newpath
90     return None
91
92 # Topological sorting algo
93 # return in sorted_nodes the list of sorted nodes
94 def depth_first_topo_graph(graph, start, visited=[], sorted_nodes=[]):
95     visited = visited + [start]
96     for node in graph[start]:
97         if node not in visited:
98             visited,sorted_nodes=depth_first_topo_graph(graph, node, visited,sorted_nodes)
99         else:
100             assert node in sorted_nodes, 'Error : cycle detection for node %s and %s !' % (start,node)
101     
102     sorted_nodes = sorted_nodes + [start]
103     return visited,sorted_nodes
104
105
106 # check for p_name that all dependencies are installed
107 def check_dependencies(config, p_name_p_info, all_products_dict):
108     l_depends_not_installed = []
109     for prod in p_name_p_info[1]["depend_all"]:
110         # for each dependency, check the install
111         prod_name, prod_info=all_products_dict[prod]
112         if not(src.product.check_installation(prod_info)):
113             l_depends_not_installed.append(prod_name)
114     return l_depends_not_installed   # non installed deps
115
116 def log_step(logger, header, step):
117     logger.write("\r%s%s" % (header, " " * 30), 3)
118     logger.write("\r%s%s" % (header, step), 3)
119     logger.flush()
120
121 def log_res_step(logger, res):
122     if res == 0:
123         logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
124         logger.flush()
125     else:
126         logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
127         logger.flush()
128
129 def compile_all_products(sat, config, options, products_infos, all_products_dict, logger):
130     '''Execute the proper configuration commands 
131        in each product build directory.
132
133     :param config Config: The global configuration
134     :param products_info list: List of 
135                                  (str, Config) => (product_name, product_info)
136     :param all_products_dict: Dict of all products 
137     :param logger Logger: The logger instance to use for the display and logging
138     :return: the number of failing commands.
139     :rtype: int
140     '''
141     res = 0
142     for p_name_info in products_infos:
143         
144         p_name, p_info = p_name_info
145         
146         # Logging
147         len_end_line = 30
148         header = _("Compilation of %s") % src.printcolors.printcLabel(p_name)
149         header += " %s " % ("." * (len_end_line - len(p_name)))
150         logger.write(header, 3)
151         logger.flush()
152
153         # Do nothing if the product is not compilable
154         if not src.product.product_compiles(p_info):
155             log_step(logger, header, "ignored")
156             logger.write("\n", 3, False)
157             continue
158
159         # Do nothing if the product is native
160         if src.product.product_is_native(p_info):
161             log_step(logger, header, "native")
162             logger.write("\n", 3, False)
163             continue
164
165         # Do nothing if the product is fixed (already compiled by third party)
166         if src.product.product_is_fixed(p_info):
167             log_step(logger, header, "native")
168             logger.write("\n", 3, False)
169             continue
170
171         # Clean the build and the install directories 
172         # if the corresponding options was called
173         if options.clean_all:
174             log_step(logger, header, "CLEAN BUILD AND INSTALL ")
175             sat.clean(config.VARS.application + 
176                       " --products " + p_name + 
177                       " --build --install",
178                       batch=True,
179                       verbose=0,
180                       logger_add_link = logger)
181
182
183         # Clean the the install directory 
184         # if the corresponding option was called
185         if options.clean_install and not options.clean_all:
186             log_step(logger, header, "CLEAN INSTALL ")
187             sat.clean(config.VARS.application + 
188                       " --products " + p_name + 
189                       " --install",
190                       batch=True,
191                       verbose=0,
192                       logger_add_link = logger)
193         
194         # Recompute the product information to get the right install_dir
195         # (it could change if there is a clean of the install directory)
196         p_info = src.product.get_product_config(config, p_name)
197         
198         # Check if sources was already successfully installed
199         check_source = src.product.check_source(p_info)
200         if not options.no_compile: # don't check sources with option --show!
201             if not check_source:
202                 logger.write(_("Sources of product not found (try 'sat -h prepare') \n"))
203                 res += 1 # one more error
204                 continue
205         
206         if src.product.product_is_salome(p_info):
207             # For salome modules, we check if the sources of configuration modules are present
208             # configuration modules have the property "configure_dependency"
209
210             # get the list of all modules in application 
211             all_products_infos = src.product.get_products_infos(config.APPLICATION.products,
212                                                                 config)
213             check_source = True
214             # for configuration modules, check if sources are present
215             for prod in all_products_dict:
216                 product_name, product_info = all_products_dict[prod]
217                 if ("properties" in product_info and
218                     "configure_dependency" in product_info.properties and
219                     product_info.properties.configure_dependency == "yes"):
220                     check_source = check_source and src.product.check_source(product_info)
221                     if not check_source:
222                         logger.write(_("\nERROR : SOURCES of %s not found! It is required for" 
223                                        " the configuration\n" % product_name))
224                         logger.write(_("        Get it with the command : sat prepare %s -p %s \n" % 
225                                       (config.APPLICATION.name, product_name)))
226             if not check_source:
227                 # if at least one configuration module is not present, we stop compilation
228                 res += 1
229                 continue
230         
231         # Check if it was already successfully installed
232         if src.product.check_installation(p_info):
233             logger.write(_("Already installed"))
234             logger.write(_(" in %s" % p_info.install_dir), 4)
235             logger.write(_("\n"))
236             continue
237         
238         # If the show option was called, do not launch the compilation
239         if options.no_compile:
240             logger.write(_("Not installed in %s\n" % p_info.install_dir))
241             continue
242         
243         # Check if the dependencies are installed
244         l_depends_not_installed = check_dependencies(config, p_name_info, all_products_dict)
245         if len(l_depends_not_installed) > 0:
246             log_step(logger, header, "")
247             logger.write(src.printcolors.printcError(
248                     _("ERROR : the following mandatory product(s) is(are) not installed: ")))
249             for prod_name in l_depends_not_installed:
250                 logger.write(src.printcolors.printcError(prod_name + " "))
251             logger.write("\n")
252             continue
253         
254         # Call the function to compile the product
255         res_prod, len_end_line, error_step = compile_product(
256              sat, p_name_info, config, options, logger, header, len_end_line)
257         
258         if res_prod != 0:
259             res += 1
260             
261             if error_step != "CHECK":
262                 # Clean the install directory if there is any
263                 logger.write(_(
264                             "Cleaning the install directory if there is any\n"),
265                              5)
266                 sat.clean(config.VARS.application + 
267                           " --products " + p_name + 
268                           " --install",
269                           batch=True,
270                           verbose=0,
271                           logger_add_link = logger)
272         else:
273             # Clean the build directory if the compilation and tests succeed
274             if options.clean_build_after:
275                 log_step(logger, header, "CLEAN BUILD")
276                 sat.clean(config.VARS.application + 
277                           " --products " + p_name + 
278                           " --build",
279                           batch=True,
280                           verbose=0,
281                           logger_add_link = logger)
282
283         # Log the result
284         if res_prod > 0:
285             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
286             logger.write("\r" + header + src.printcolors.printcError("KO ") + error_step)
287             logger.write("\n==== %(KO)s in compile of %(name)s \n" %
288                 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
289             if error_step == "CHECK":
290                 logger.write(_("\nINSTALL directory = %s" % 
291                            src.printcolors.printcInfo(p_info.install_dir)), 3)
292             logger.flush()
293         else:
294             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
295             logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
296             logger.write(_("\nINSTALL directory = %s" % 
297                            src.printcolors.printcInfo(p_info.install_dir)), 3)
298             logger.write("\n==== %s \n" % src.printcolors.printcInfo("OK"), 4)
299             logger.write("\n==== Compilation of %(name)s %(OK)s \n" %
300                 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
301             logger.flush()
302         logger.write("\n", 3, False)
303         
304         
305         if res_prod != 0 and options.stop_first_fail:
306             break
307         
308     return res
309
310 def compile_product(sat, p_name_info, config, options, logger, header, len_end):
311     '''Execute the proper configuration command(s) 
312        in the product build directory.
313     
314     :param p_name_info tuple: (str, Config) => (product_name, product_info)
315     :param config Config: The global configuration
316     :param logger Logger: The logger instance to use for the display 
317                           and logging
318     :param header Str: the header to display when logging
319     :param len_end Int: the lenght of the the end of line (used in display)
320     :return: 1 if it fails, else 0.
321     :rtype: int
322     '''
323     
324     p_name, p_info = p_name_info
325           
326     # Get the build procedure from the product configuration.
327     # It can be :
328     # build_sources : autotools -> build_configure, configure, make, make install
329     # build_sources : cmake     -> cmake, make, make install
330     # build_sources : script    -> script executions
331     res = 0
332
333     
334     # check if pip should be used : the application and product have pip property
335     if (src.appli_test_property(config,"pip", "yes") and 
336        src.product.product_test_property(p_info,"pip", "yes")):
337             res, len_end_line, error_step = compile_product_pip(sat,
338                                                                 p_name_info,
339                                                                 config,
340                                                                 options,
341                                                                 logger,
342                                                                 header,
343                                                                 len_end)
344     else:
345         if (src.product.product_is_autotools(p_info) or 
346                                               src.product.product_is_cmake(p_info)):
347             res, len_end_line, error_step = compile_product_cmake_autotools(sat,
348                                                                       p_name_info,
349                                                                       config,
350                                                                       options,
351                                                                       logger,
352                                                                       header,
353                                                                       len_end)
354         if src.product.product_has_script(p_info):
355             res, len_end_line, error_step = compile_product_script(sat,
356                                                                    p_name_info,
357                                                                    config,
358                                                                    options,
359                                                                    logger,
360                                                                    header,
361                                                                    len_end)
362
363     # Check that the install directory exists
364     if res==0 and not(os.path.exists(p_info.install_dir)):
365         res = 1
366         error_step = "NO INSTALL DIR"
367         msg = _("Error: despite the fact that all the steps ended successfully,"
368                 " no install directory was found !")
369         logger.write(src.printcolors.printcError(msg), 4)
370         logger.write("\n", 4)
371         return res, len_end, error_step
372     
373     # Add the config file corresponding to the dependencies/versions of the 
374     # product that have been successfully compiled
375     if res==0:       
376         logger.write(_("Add the config file in installation directory\n"), 5)
377         src.product.add_compile_config_file(p_info, config)
378         
379         if options.check:
380             # Do the unit tests (call the check command)
381             log_step(logger, header, "CHECK")
382             res_check = sat.check(
383                               config.VARS.application + " --products " + p_name,
384                               verbose = 0,
385                               logger_add_link = logger)
386             if res_check != 0:
387                 error_step = "CHECK"
388                 
389             res += res_check
390     
391     return res, len_end_line, error_step
392
393
394 def compile_product_pip(sat,
395                         p_name_info,
396                         config,
397                         options,
398                         logger,
399                         header,
400                         len_end):
401     '''Execute the proper build procedure for pip products
402     :param p_name_info tuple: (str, Config) => (product_name, product_info)
403     :param config Config: The global configuration
404     :param logger Logger: The logger instance to use for the display 
405                           and logging
406     :param header Str: the header to display when logging
407     :param len_end Int: the lenght of the the end of line (used in display)
408     :return: 1 if it fails, else 0.
409     :rtype: int
410     '''
411     p_name, p_info = p_name_info
412     
413     # Execute "sat configure", "sat make" and "sat install"
414     res = 0
415     error_step = ""
416     pip_install_in_python=False
417     if src.appli_test_property(config,"pip_install_dir", "python"):
418         # pip will install product in python directory"
419         pip_install_cmd="pip3 install --disable-pip-version-check --no-index --find-links=%s --build %s %s==%s" %\
420         (config.LOCAL.archive_dir, p_info.build_dir, p_name, p_info.version)
421         pip_install_in_python=True
422         
423     else: 
424         # pip will install product in product install_dir
425         pip_install_dir=os.path.join(p_info.install_dir, "lib", "python${PYTHON_VERSION:0:3}", "site-packages")
426         pip_install_cmd="pip3 install --disable-pip-version-check --no-index --find-links=%s --build %s --target %s %s==%s" %\
427         (config.LOCAL.archive_dir, p_info.build_dir, pip_install_dir, p_name, p_info.version)
428     log_step(logger, header, "PIP")
429     logger.write("\n"+pip_install_cmd+"\n", 4)
430     len_end_line = len_end + 3
431     error_step = ""
432     build_environ = src.environment.SalomeEnviron(config,
433                              src.environment.Environ(dict(os.environ)),
434                              True)
435     environ_info = src.product.get_product_dependencies(config,
436                                                         p_info)
437     build_environ.silent = (config.USER.output_verbose_level < 5)
438     build_environ.set_full_environ(logger, environ_info)
439     
440     if pip_install_in_python and (options.clean_install or options.clean_all):
441         # for products installed by pip inside python install dir
442         # finish the clean by uninstalling the product from python install dir
443         pip_clean_cmd="pip3 uninstall -y  %s==%s" % (p_name, p_info.version)
444         res_pipclean = (subprocess.call(pip_clean_cmd, 
445                                    shell=True, 
446                                    cwd=config.LOCAL.workdir,
447                                    env=build_environ.environ.environ,
448                                    stdout=logger.logTxtFile, 
449                                    stderr=subprocess.STDOUT) == 0)        
450         if not res_pipclean:
451             logger.write("\n",1)
452             logger.warning("pip3 uninstall failed!")
453
454     res_pip = (subprocess.call(pip_install_cmd, 
455                                shell=True, 
456                                cwd=config.LOCAL.workdir,
457                                env=build_environ.environ.environ,
458                                stdout=logger.logTxtFile, 
459                                stderr=subprocess.STDOUT) == 0)        
460     if res_pip:
461         res=0
462         if pip_install_in_python:
463             # when product is installed in python, create install_dir 
464             # (to put inside product info and mark the installation success)
465             os.mkdir(p_info.install_dir)
466     else:
467         #log_res_step(logger, res)
468         res=1
469         error_step = "PIP"
470
471     return res, len_end_line, error_step 
472
473
474
475 def compile_product_cmake_autotools(sat,
476                                     p_name_info,
477                                     config,
478                                     options,
479                                     logger,
480                                     header,
481                                     len_end):
482     '''Execute the proper build procedure for autotools or cmake
483        in the product build directory.
484     
485     :param p_name_info tuple: (str, Config) => (product_name, product_info)
486     :param config Config: The global configuration
487     :param logger Logger: The logger instance to use for the display 
488                           and logging
489     :param header Str: the header to display when logging
490     :param len_end Int: the lenght of the the end of line (used in display)
491     :return: 1 if it fails, else 0.
492     :rtype: int
493     '''
494     p_name, p_info = p_name_info
495     
496     # Execute "sat configure", "sat make" and "sat install"
497     res = 0
498     error_step = ""
499     
500     # Logging and sat command call for configure step
501     len_end_line = len_end
502     log_step(logger, header, "CONFIGURE")
503     res_c = sat.configure(config.VARS.application + " --products " + p_name,
504                           verbose = 0,
505                           logger_add_link = logger)
506     log_res_step(logger, res_c)
507     res += res_c
508     
509     if res_c > 0:
510         error_step = "CONFIGURE"
511     else:
512         # Logging and sat command call for make step
513         # Logging take account of the fact that the product has a compilation 
514         # script or not
515         if src.product.product_has_script(p_info):
516             # if the product has a compilation script, 
517             # it is executed during make step
518             scrit_path_display = src.printcolors.printcLabel(
519                                                         p_info.compil_script)
520             log_step(logger, header, "SCRIPT " + scrit_path_display)
521             len_end_line = len(scrit_path_display)
522         else:
523             log_step(logger, header, "MAKE")
524         make_arguments = config.VARS.application + " --products " + p_name
525         # Get the make_flags option if there is any
526         if options.makeflags:
527             make_arguments += " --option -j" + options.makeflags
528         res_m = sat.make(make_arguments,
529                          verbose = 0,
530                          logger_add_link = logger)
531         log_res_step(logger, res_m)
532         res += res_m
533         
534         if res_m > 0:
535             error_step = "MAKE"
536         else: 
537             # Logging and sat command call for make install step
538             log_step(logger, header, "MAKE INSTALL")
539             res_mi = sat.makeinstall(config.VARS.application + 
540                                      " --products " + 
541                                      p_name,
542                                     verbose = 0,
543                                     logger_add_link = logger)
544
545             log_res_step(logger, res_mi)
546             res += res_mi
547             
548             if res_mi > 0:
549                 error_step = "MAKE INSTALL"
550                 
551     return res, len_end_line, error_step 
552
553 def compile_product_script(sat,
554                            p_name_info,
555                            config,
556                            options,
557                            logger,
558                            header,
559                            len_end):
560     '''Execute the script build procedure in the product build directory.
561     
562     :param p_name_info tuple: (str, Config) => (product_name, product_info)
563     :param config Config: The global configuration
564     :param logger Logger: The logger instance to use for the display 
565                           and logging
566     :param header Str: the header to display when logging
567     :param len_end Int: the lenght of the the end of line (used in display)
568     :return: 1 if it fails, else 0.
569     :rtype: int
570     '''
571     p_name, p_info = p_name_info
572     
573     # Execute "sat configure", "sat make" and "sat install"
574     error_step = ""
575     
576     # Logging and sat command call for the script step
577     scrit_path_display = src.printcolors.printcLabel(p_info.compil_script)
578     log_step(logger, header, "SCRIPT " + scrit_path_display)
579     len_end_line = len_end + len(scrit_path_display)
580     res = sat.script(config.VARS.application + " --products " + p_name,
581                      verbose = 0,
582                      logger_add_link = logger)
583     log_res_step(logger, res)
584               
585     return res, len_end_line, error_step 
586
587     
588 def description():
589     '''method that is called when salomeTools is called with --help option.
590     
591     :return: The text to display for the compile command description.
592     :rtype: str
593     '''
594     return _("The compile command constructs the products of the application"
595              "\n\nexample:\nsat compile SALOME-master --products KERNEL,GUI,"
596              "MEDCOUPLING --clean_all")
597   
598 def run(args, runner, logger):
599     '''method that is called when salomeTools is called with compile parameter.
600     '''
601     # DBG.write("compile runner.cfg", runner.cfg, True)
602     # Parse the options
603     (options, args) = parser.parse_args(args)
604
605     # Warn the user if he invoked the clean_all option 
606     # without --products option
607     if (options.clean_all and 
608         options.products is None and 
609         not runner.options.batch):
610         rep = input(_("You used --clean_all without specifying a product"
611                           " are you sure you want to continue? [Yes/No] "))
612         if rep.upper() != _("YES").upper():
613             return 0
614         
615     # check that the command has been called with an application
616     src.check_config_has_application( runner.cfg )
617
618     # Print some informations
619     logger.write(_('Executing the compile commands in the build '
620                                 'directories of the products of '
621                                 'the application %s\n') % 
622                 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
623     
624     info = [
625             (_("SOURCE directory"),
626              os.path.join(runner.cfg.APPLICATION.workdir, 'SOURCES')),
627             (_("BUILD directory"),
628              os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))
629             ]
630     src.print_info(logger, info)
631
632     # Get the list of all application products, and create its dependency graph
633     all_products_infos = src.product.get_products_infos(runner.cfg.APPLICATION.products,
634                                                         runner.cfg)
635     all_products_graph=get_dependencies_graph(all_products_infos)
636     logger.write("Dependency graph of all application products : %s\n" % all_products_graph, 6)
637
638     # Get the list of products we have to compile
639     products_infos = src.product.get_products_list(options, runner.cfg, logger)
640     products_list = [pi[0] for pi in products_infos]
641
642     logger.write("Product we have to compile (as specified by user) : %s\n" % products_list, 5)
643     if options.fathers:
644         # Extend the list with all recursive dependencies of the given products
645         visited=[]
646         for p_name in products_list:
647             visited=depth_search_graph(all_products_graph, p_name, visited)
648         products_list = visited
649
650     logger.write("Product list to compile with fathers : %s\n" % products_list, 5)
651     if options.children:
652         # Extend the list with all products that depends upon the given products
653         children=[]
654         for n in all_products_graph:
655             # for all products (that are not in products_list):
656             # if we we find a path from the product to the product list,
657             # then we product is a child and we add it to the children list 
658             if (n not in children) and (n not in products_list):
659                 if find_path_graph(all_products_graph, n, products_list):
660                     children = children + [n]
661         # complete products_list (the products we have to compile) with the list of children
662         products_list = products_list + children
663         logger.write("Product list to compile with children : %s\n" % products_list, 5)
664
665     # Sort the list of all products (topological sort).
666     # the products listed first do not depend upon products listed after
667     visited_nodes=[]
668     sorted_nodes=[]
669     for n in all_products_graph:
670         if n not in visited_nodes:
671             visited_nodes,sorted_nodes=depth_first_topo_graph(all_products_graph, n, visited_nodes,sorted_nodes)
672     logger.write("Complete depndency graph topological search (sorting): %s\n" % sorted_nodes, 6)
673
674 #   use the sorted list of all products to sort the list of products we have to compile
675     sorted_product_list=[]
676     for n in sorted_nodes:
677         if n in products_list:
678             sorted_product_list.append(n)
679     logger.write("Sorted list of products to compile : %s\n" % sorted_product_list, 5)
680
681     
682     # from the sorted list of products to compile, build a sorted list of products infos
683     #  a- create a dict to facilitate products_infos sorting
684     all_products_dict={}
685     for (pname,pinfo) in all_products_infos:
686         all_products_dict[pname]=(pname,pinfo)
687     #  b- build a sorted list of products infos in products_infos
688     products_infos=[]
689     for product in sorted_product_list:
690         products_infos.append(all_products_dict[product])
691
692     # for all products to compile, store in "depend_all" field the complete dependencies (recursive) 
693     # (will be used by check_dependencies funvtion)
694     for pi in products_infos:
695         dep_prod=[]
696         dep_prod=depth_search_graph(all_products_graph,pi[0], dep_prod)
697         pi[1]["depend_all"]=dep_prod[1:]
698         
699
700     # Call the function that will loop over all the products and execute
701     # the right command(s)
702     res = compile_all_products(runner, runner.cfg, options, products_infos, all_products_dict, logger)
703     
704     # Print the final state
705     nb_products = len(products_infos)
706     if res == 0:
707         final_status = "OK"
708     else:
709         final_status = "KO"
710    
711     logger.write(_("\nCompilation: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
712         { 'status': src.printcolors.printc(final_status), 
713           'valid_result': nb_products - res,
714           'nb_products': nb_products }, 1)    
715     
716     code = res
717     if code != 0:
718         code = 1
719     return code