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