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