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