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