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