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