Salome HOME
sat #17766 et sat #17848 : traitement des modules par ordre de dépendance, correction...
[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 start not in graph:
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(config, 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         is_pip= (src.appli_test_property(config,"pip", "yes") and src.product.product_test_property(p_info,"pip", "yes"))
201         # don't check sources with option --show 
202         # or for products managed by pip (there sources are in wheels stored in LOCAL.ARCHIVE
203         if not (options.no_compile or is_pip): 
204             if not check_source:
205                 logger.write(_("Sources of product not found (try 'sat -h prepare') \n"))
206                 res += 1 # one more error
207                 continue
208         
209         if src.product.product_is_salome(p_info):
210             # For salome modules, we check if the sources of configuration modules are present
211             # configuration modules have the property "configure_dependency"
212
213             # get the list of all modules in application 
214             all_products_infos = src.product.get_products_infos(config.APPLICATION.products,
215                                                                 config)
216             check_source = True
217             # for configuration modules, check if sources are present
218             for prod in all_products_dict:
219                 product_name, product_info = all_products_dict[prod]
220                 if ("properties" in product_info and
221                     "configure_dependency" in product_info.properties and
222                     product_info.properties.configure_dependency == "yes"):
223                     check_source = check_source and src.product.check_source(product_info)
224                     if not check_source:
225                         logger.write(_("\nERROR : SOURCES of %s not found! It is required for" 
226                                        " the configuration\n" % product_name))
227                         logger.write(_("        Get it with the command : sat prepare %s -p %s \n" % 
228                                       (config.APPLICATION.name, product_name)))
229             if not check_source:
230                 # if at least one configuration module is not present, we stop compilation
231                 res += 1
232                 continue
233         
234         # Check if it was already successfully installed
235         if src.product.check_installation(config, p_info):
236             logger.write(_("Already installed"))
237             logger.write(_(" in %s" % p_info.install_dir), 4)
238             logger.write(_("\n"))
239             continue
240         
241         # If the show option was called, do not launch the compilation
242         if options.no_compile:
243             logger.write(_("Not installed in %s\n" % p_info.install_dir))
244             continue
245         
246         # Check if the dependencies are installed
247         l_depends_not_installed = check_dependencies(config, p_name_info, all_products_dict)
248         if len(l_depends_not_installed) > 0:
249             log_step(logger, header, "")
250             logger.write(src.printcolors.printcError(
251                     _("ERROR : the following mandatory product(s) is(are) not installed: ")))
252             for prod_name in l_depends_not_installed:
253                 logger.write(src.printcolors.printcError(prod_name + " "))
254             logger.write("\n")
255             continue
256         
257         # Call the function to compile the product
258         res_prod, len_end_line, error_step = compile_product(
259              sat, p_name_info, config, options, logger, header, len_end_line)
260         
261         if res_prod != 0:
262             res += 1
263             # there was an error, we clean install dir, unless :
264             #  - the error step is "check", or
265             #  - the product is managed by pip and installed in python dir
266             do_not_clean_install=False
267             if (error_step == "CHECK") or (is_pip and \
268                 src.appli_test_property(config,"pip_install_dir", "python")) :
269                 do_not_clean_install=True
270             if not do_not_clean_install:
271                 # Clean the install directory if there is any
272                 logger.write(_(
273                             "Cleaning the install directory if there is any\n"),
274                              5)
275                 sat.clean(config.VARS.application + 
276                           " --products " + p_name + 
277                           " --install",
278                           batch=True,
279                           verbose=0,
280                           logger_add_link = logger)
281         else:
282             # Clean the build directory if the compilation and tests succeed
283             if options.clean_build_after:
284                 log_step(logger, header, "CLEAN BUILD")
285                 sat.clean(config.VARS.application + 
286                           " --products " + p_name + 
287                           " --build",
288                           batch=True,
289                           verbose=0,
290                           logger_add_link = logger)
291
292         # Log the result
293         if res_prod > 0:
294             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
295             logger.write("\r" + header + src.printcolors.printcError("KO ") + error_step)
296             logger.write("\n==== %(KO)s in compile of %(name)s \n" %
297                 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
298             if error_step == "CHECK":
299                 logger.write(_("\nINSTALL directory = %s" % 
300                            src.printcolors.printcInfo(p_info.install_dir)), 3)
301             logger.flush()
302         else:
303             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
304             logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
305             logger.write(_("\nINSTALL directory = %s" % 
306                            src.printcolors.printcInfo(p_info.install_dir)), 3)
307             logger.write("\n==== %s \n" % src.printcolors.printcInfo("OK"), 4)
308             logger.write("\n==== Compilation of %(name)s %(OK)s \n" %
309                 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
310             logger.flush()
311         logger.write("\n", 3, False)
312         
313         
314         if res_prod != 0 and options.stop_first_fail:
315             break
316         
317     return res
318
319 def compile_product(sat, p_name_info, config, options, logger, header, len_end):
320     '''Execute the proper configuration command(s) 
321        in the product build directory.
322     
323     :param p_name_info tuple: (str, Config) => (product_name, product_info)
324     :param config Config: The global configuration
325     :param logger Logger: The logger instance to use for the display 
326                           and logging
327     :param header Str: the header to display when logging
328     :param len_end Int: the lenght of the the end of line (used in display)
329     :return: 1 if it fails, else 0.
330     :rtype: int
331     '''
332     
333     p_name, p_info = p_name_info
334           
335     # Get the build procedure from the product configuration.
336     # It can be :
337     # build_sources : autotools -> build_configure, configure, make, make install
338     # build_sources : cmake     -> cmake, make, make install
339     # build_sources : script    -> script executions
340     res = 0
341
342     
343     # check if pip should be used : the application and product have pip property
344     if (src.appli_test_property(config,"pip", "yes") and 
345        src.product.product_test_property(p_info,"pip", "yes")):
346             res, len_end_line, error_step = compile_product_pip(sat,
347                                                                 p_name_info,
348                                                                 config,
349                                                                 options,
350                                                                 logger,
351                                                                 header,
352                                                                 len_end)
353     else:
354         if (src.product.product_is_autotools(p_info) or 
355                                               src.product.product_is_cmake(p_info)):
356             res, len_end_line, error_step = compile_product_cmake_autotools(sat,
357                                                                       p_name_info,
358                                                                       config,
359                                                                       options,
360                                                                       logger,
361                                                                       header,
362                                                                       len_end)
363         if src.product.product_has_script(p_info):
364             res, len_end_line, error_step = compile_product_script(sat,
365                                                                    p_name_info,
366                                                                    config,
367                                                                    options,
368                                                                    logger,
369                                                                    header,
370                                                                    len_end)
371
372     # Check that the install directory exists
373     if res==0 and not(os.path.exists(p_info.install_dir)):
374         res = 1
375         error_step = "NO INSTALL DIR"
376         msg = _("Error: despite the fact that all the steps ended successfully,"
377                 " no install directory was found !")
378         logger.write(src.printcolors.printcError(msg), 4)
379         logger.write("\n", 4)
380         return res, len_end, error_step
381     
382     # Add the config file corresponding to the dependencies/versions of the 
383     # product that have been successfully compiled
384     if res==0:       
385         logger.write(_("Add the config file in installation directory\n"), 5)
386         src.product.add_compile_config_file(p_info, config)
387         
388         if options.check:
389             # Do the unit tests (call the check command)
390             log_step(logger, header, "CHECK")
391             res_check = sat.check(
392                               config.VARS.application + " --products " + p_name,
393                               verbose = 0,
394                               logger_add_link = logger)
395             if res_check != 0:
396                 error_step = "CHECK"
397                 
398             res += res_check
399     
400     return res, len_end_line, error_step
401
402
403 def compile_product_pip(sat,
404                         p_name_info,
405                         config,
406                         options,
407                         logger,
408                         header,
409                         len_end):
410     '''Execute the proper build procedure for pip products
411     :param p_name_info tuple: (str, Config) => (product_name, product_info)
412     :param config Config: The global configuration
413     :param logger Logger: The logger instance to use for the display 
414                           and logging
415     :param header Str: the header to display when logging
416     :param len_end Int: the lenght of the the end of line (used in display)
417     :return: 1 if it fails, else 0.
418     :rtype: int
419     '''
420     # a) initialisation
421     p_name, p_info = p_name_info
422     res = 0
423     error_step = ""
424     pip_install_in_python=False
425     pip_wheels_dir=os.path.join(config.LOCAL.archive_dir,"wheels")
426     pip_install_cmd=config.INTERNAL.command.pip_install # parametrized in src/internal
427
428     # b) get the build environment (useful to get the installed python & pip3)
429     build_environ = src.environment.SalomeEnviron(config,
430                              src.environment.Environ(dict(os.environ)),
431                              True)
432     environ_info = src.product.get_product_dependencies(config,
433                                                         p_info)
434     build_environ.silent = (config.USER.output_verbose_level < 5)
435     build_environ.set_full_environ(logger, environ_info)
436
437     # c- download : check/get pip wheel in pip_wheels_dir
438     pip_download_cmd=config.INTERNAL.command.pip_download +\
439                      " --destination-directory %s --no-deps %s==%s " %\
440                      (pip_wheels_dir, p_info.name, p_info.version)
441     logger.write("\n"+pip_download_cmd+"\n", 4, False) 
442     res_pip_dwl = (subprocess.call(pip_download_cmd, 
443                                    shell=True, 
444                                    cwd=config.LOCAL.workdir,
445                                    env=build_environ.environ.environ,
446                                    stdout=logger.logTxtFile, 
447                                    stderr=subprocess.STDOUT) == 0)
448     # error is not managed at the stage. error will be handled by pip install
449     # here we just print a message
450     if not res_pip_dwl:
451         logger.write("Error in pip download\n", 4, False)
452
453
454     # d- install (in python or in separate product directory)
455     if src.appli_test_property(config,"pip_install_dir", "python"):
456         # pip will install product in python directory"
457         pip_install_cmd+=" --find-links=%s --build %s %s==%s" %\
458         (pip_wheels_dir, p_info.build_dir, p_info.name, p_info.version)
459         pip_install_in_python=True
460         
461     else: 
462         # pip will install product in product install_dir
463         pip_install_dir=os.path.join(p_info.install_dir, "lib", "python${PYTHON_VERSION:0:3}", "site-packages")
464         pip_install_cmd+=" --find-links=%s --build %s --target %s %s==%s" %\
465         (pip_wheels_dir, p_info.build_dir, pip_install_dir, p_info.name, p_info.version)
466     log_step(logger, header, "PIP")
467     logger.write("\n"+pip_install_cmd+"\n", 4)
468     len_end_line = len_end + 3
469     error_step = ""
470
471     res_pip = (subprocess.call(pip_install_cmd, 
472                                shell=True, 
473                                cwd=config.LOCAL.workdir,
474                                env=build_environ.environ.environ,
475                                stdout=logger.logTxtFile, 
476                                stderr=subprocess.STDOUT) == 0)        
477     if res_pip:
478         res=0
479     else:
480         #log_res_step(logger, res)
481         res=1
482         error_step = "PIP"
483         logger.write("\nError in pip command, please consult details with sat log command's internal traces\n", 3)
484
485     return res, len_end_line, error_step 
486
487
488
489 def compile_product_cmake_autotools(sat,
490                                     p_name_info,
491                                     config,
492                                     options,
493                                     logger,
494                                     header,
495                                     len_end):
496     '''Execute the proper build procedure for autotools or cmake
497        in the product build directory.
498     
499     :param p_name_info tuple: (str, Config) => (product_name, product_info)
500     :param config Config: The global configuration
501     :param logger Logger: The logger instance to use for the display 
502                           and logging
503     :param header Str: the header to display when logging
504     :param len_end Int: the lenght of the the end of line (used in display)
505     :return: 1 if it fails, else 0.
506     :rtype: int
507     '''
508     p_name, p_info = p_name_info
509     
510     # Execute "sat configure", "sat make" and "sat install"
511     res = 0
512     error_step = ""
513     
514     # Logging and sat command call for configure step
515     len_end_line = len_end
516     log_step(logger, header, "CONFIGURE")
517     res_c = sat.configure(config.VARS.application + " --products " + p_name,
518                           verbose = 0,
519                           logger_add_link = logger)
520     log_res_step(logger, res_c)
521     res += res_c
522     
523     if res_c > 0:
524         error_step = "CONFIGURE"
525     else:
526         # Logging and sat command call for make step
527         # Logging take account of the fact that the product has a compilation 
528         # script or not
529         if src.product.product_has_script(p_info):
530             # if the product has a compilation script, 
531             # it is executed during make step
532             scrit_path_display = src.printcolors.printcLabel(
533                                                         p_info.compil_script)
534             log_step(logger, header, "SCRIPT " + scrit_path_display)
535             len_end_line = len(scrit_path_display)
536         else:
537             log_step(logger, header, "MAKE")
538         make_arguments = config.VARS.application + " --products " + p_name
539         # Get the make_flags option if there is any
540         if options.makeflags:
541             make_arguments += " --option -j" + options.makeflags
542         res_m = sat.make(make_arguments,
543                          verbose = 0,
544                          logger_add_link = logger)
545         log_res_step(logger, res_m)
546         res += res_m
547         
548         if res_m > 0:
549             error_step = "MAKE"
550         else: 
551             # Logging and sat command call for make install step
552             log_step(logger, header, "MAKE INSTALL")
553             res_mi = sat.makeinstall(config.VARS.application + 
554                                      " --products " + 
555                                      p_name,
556                                     verbose = 0,
557                                     logger_add_link = logger)
558
559             log_res_step(logger, res_mi)
560             res += res_mi
561             
562             if res_mi > 0:
563                 error_step = "MAKE INSTALL"
564                 
565     return res, len_end_line, error_step 
566
567 def compile_product_script(sat,
568                            p_name_info,
569                            config,
570                            options,
571                            logger,
572                            header,
573                            len_end):
574     '''Execute the script build procedure in the product build directory.
575     
576     :param p_name_info tuple: (str, Config) => (product_name, product_info)
577     :param config Config: The global configuration
578     :param logger Logger: The logger instance to use for the display 
579                           and logging
580     :param header Str: the header to display when logging
581     :param len_end Int: the lenght of the the end of line (used in display)
582     :return: 1 if it fails, else 0.
583     :rtype: int
584     '''
585     p_name, p_info = p_name_info
586     
587     # Execute "sat configure", "sat make" and "sat install"
588     error_step = ""
589     
590     # Logging and sat command call for the script step
591     scrit_path_display = src.printcolors.printcLabel(p_info.compil_script)
592     log_step(logger, header, "SCRIPT " + scrit_path_display)
593     len_end_line = len_end + len(scrit_path_display)
594     res = sat.script(config.VARS.application + " --products " + p_name,
595                      verbose = 0,
596                      logger_add_link = logger)
597     log_res_step(logger, res)
598               
599     return res, len_end_line, error_step 
600
601     
602 def description():
603     '''method that is called when salomeTools is called with --help option.
604     
605     :return: The text to display for the compile command description.
606     :rtype: str
607     '''
608     return _("The compile command constructs the products of the application"
609              "\n\nexample:\nsat compile SALOME-master --products KERNEL,GUI,"
610              "MEDCOUPLING --clean_all")
611   
612 def run(args, runner, logger):
613     '''method that is called when salomeTools is called with compile parameter.
614     '''
615     # Parse the options
616     (options, args) = parser.parse_args(args)
617
618     # Warn the user if he invoked the clean_all option 
619     # without --products option
620     if (options.clean_all and 
621         options.products is None and 
622         not runner.options.batch):
623         rep = input(_("You used --clean_all without specifying a product"
624                           " are you sure you want to continue? [Yes/No] "))
625         if rep.upper() != _("YES").upper():
626             return 0
627         
628     # check that the command has been called with an application
629     src.check_config_has_application( runner.cfg )
630
631     # Print some informations
632     logger.write(_('Executing the compile commands in the build '
633                                 'directories of the products of '
634                                 'the application %s\n') % 
635                 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
636     
637     info = [
638             (_("SOURCE directory"),
639              os.path.join(runner.cfg.APPLICATION.workdir, 'SOURCES')),
640             (_("BUILD directory"),
641              os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))
642             ]
643     src.print_info(logger, info)
644
645     # Get the list of all application products, and create its dependency graph
646     all_products_infos = src.product.get_products_infos(runner.cfg.APPLICATION.products,
647                                                         runner.cfg)
648     all_products_graph=get_dependencies_graph(all_products_infos)
649     #logger.write("Dependency graph of all application products : %s\n" % all_products_graph, 6)
650     DBG.write("Dependency graph of all application products : ", all_products_graph)
651
652     # Get the list of products we have to compile
653     products_infos = src.product.get_products_list(options, runner.cfg, logger)
654     products_list = [pi[0] for pi in products_infos]
655
656     logger.write("Product we have to compile (as specified by user) : %s\n" % products_list, 5)
657     if options.fathers:
658         # Extend the list with all recursive dependencies of the given products
659         visited=[]
660         for p_name in products_list:
661             visited=depth_search_graph(all_products_graph, p_name, visited)
662         products_list = visited
663
664     logger.write("Product list to compile with fathers : %s\n" % products_list, 5)
665     if options.children:
666         # Extend the list with all products that depends upon the given products
667         children=[]
668         for n in all_products_graph:
669             # for all products (that are not in products_list):
670             # if we we find a path from the product to the product list,
671             # then we product is a child and we add it to the children list 
672             if (n not in children) and (n not in products_list):
673                 if find_path_graph(all_products_graph, n, products_list):
674                     children = children + [n]
675         # complete products_list (the products we have to compile) with the list of children
676         products_list = products_list + children
677         logger.write("Product list to compile with children : %s\n" % products_list, 5)
678
679     # Sort the list of all products (topological sort).
680     # the products listed first do not depend upon products listed after
681     visited_nodes=[]
682     sorted_nodes=[]
683     for n in all_products_graph:
684         if n not in visited_nodes:
685             visited_nodes,sorted_nodes=depth_first_topo_graph(all_products_graph, n, visited_nodes,sorted_nodes)
686     logger.write("Complete dependency graph topological search (sorting): %s\n" % sorted_nodes, 6)
687
688 #   use the sorted list of all products to sort the list of products we have to compile
689     sorted_product_list=[]
690     for n in sorted_nodes:
691         if n in products_list:
692             sorted_product_list.append(n)
693     logger.write("Sorted list of products to compile : %s\n" % sorted_product_list, 5)
694
695     
696     # from the sorted list of products to compile, build a sorted list of products infos
697     #  a- create a dict to facilitate products_infos sorting
698     all_products_dict={}
699     for (pname,pinfo) in all_products_infos:
700         all_products_dict[pname]=(pname,pinfo)
701     #  b- build a sorted list of products infos in products_infos
702     products_infos=[]
703     for product in sorted_product_list:
704         products_infos.append(all_products_dict[product])
705
706     # for all products to compile, store in "depend_all" field the complete dependencies (recursive) 
707     # (will be used by check_dependencies funvtion)
708     for pi in products_infos:
709         dep_prod=[]
710         dep_prod=depth_search_graph(all_products_graph,pi[0], dep_prod)
711         pi[1]["depend_all"]=dep_prod[1:]
712         
713
714     # Call the function that will loop over all the products and execute
715     # the right command(s)
716     res = compile_all_products(runner, runner.cfg, options, products_infos, all_products_dict, logger)
717     
718     # Print the final state
719     nb_products = len(products_infos)
720     if res == 0:
721         final_status = "OK"
722     else:
723         final_status = "KO"
724    
725     logger.write(_("\nCompilation: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
726         { 'status': src.printcolors.printc(final_status), 
727           'valid_result': nb_products - res,
728           'nb_products': nb_products }, 1)    
729     
730     code = res
731     if code != 0:
732         code = 1
733     return code