3 # Copyright (C) 2010-2012 CEA/DEN
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.
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.
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
24 import src.debug as DBG
26 # Compatibility python 2/3 for input function
27 # input stays input for python 3 and input = raw_input for python 2
34 # Define all possible option for the compile command : sat compile <options>
35 parser = src.options.Options()
36 parser.add_option('p', 'products', 'list2', 'products',
37 _('Optional: products to compile. This option accepts a comma separated list.'))
38 parser.add_option('f', 'force', 'boolean', 'force',
39 'Optional: force the compilation of product, even if it is already installed. The BUILD directory is cleaned before compilation.')
40 parser.add_option('u', 'update', 'boolean', 'update',
41 'Optional: update mode, compile only products which sources has changed, including the dependencies.')
42 parser.add_option('', 'with_fathers', 'boolean', 'fathers',
43 _("Optional: build all necessary products to the given product (KERNEL is "
44 "build before building GUI)."), False)
45 parser.add_option('', 'with_children', 'boolean', 'children',
46 _("Optional: build all products using the given product (all SMESH plugins"
47 " are build after SMESH)."), False)
48 parser.add_option('', 'clean_all', 'boolean', 'clean_all',
49 _("Optional: clean BUILD dir and INSTALL dir before building product."),
51 parser.add_option('', 'clean_install', 'boolean', 'clean_install',
52 _("Optional: clean INSTALL dir before building product."), False)
53 parser.add_option('', 'make_flags', 'string', 'makeflags',
54 _("Optional: add extra options to the 'make' command."))
55 parser.add_option('', 'show', 'boolean', 'no_compile',
56 _("Optional: DO NOT COMPILE just show if products are installed or not."),
58 parser.add_option('', 'stop_first_fail', 'boolean', 'stop_first_fail', _(
59 "Optional: Stops the command at first product compilation"
61 parser.add_option('', 'check', 'boolean', 'check', _(
62 "Optional: execute the unit tests after compilation"), False)
64 parser.add_option('', 'clean_build_after', 'boolean', 'clean_build_after',
65 _('Optional: remove the build directory after successful compilation'), False)
68 # from sat product infos, represent the product dependencies in a simple python graph
69 # keys are nodes, the list of dependencies are values
70 def get_dependencies_graph(p_infos, compile_time=True):
72 for (p_name,p_info) in p_infos:
74 for d in p_info.depend:
76 if compile_time and "build_depend" in p_info:
77 for d in p_info.build_depend:
82 # this recursive function calculates all the dependencies of node start
83 def depth_search_graph(graph, start, visited=[]):
84 visited= visited+ [start]
85 for node in graph[start]: # for all nodes in start dependencies
86 if node not in visited:
87 visited=depth_search_graph(graph, node, visited)
90 # find a path from start node to end (a group of nodes)
91 def find_path_graph(graph, start, end, path=[]):
95 if start not in graph:
97 for node in graph[start]:
99 newpath = find_path_graph(graph, node, end, path)
100 if newpath: return newpath
103 # Topological sorting algo
104 # return in sorted_nodes the list of sorted nodes
105 def depth_first_topo_graph(graph, start, visited=[], sorted_nodes=[]):
106 visited = visited + [start]
107 if start not in graph:
108 # get more explicit error
109 where = [k for k in graph if start in graph[k]]
110 raise src.SatException('Error in product dependencies : %s product is referenced in products dependencies, but is not present in the application, from %s' % (start, where))
111 # may be in debug mode, continue loop to get all problems, (if comment raise)
112 # print("WARNING : %s product is referenced in products dependencies but is not present in the application, from %s" % (start, where))
113 # sorted_nodes = sorted_nodes + [start]
114 # return visited, sorted_nodes
115 for node in graph[start]:
116 if node not in visited:
117 visited,sorted_nodes=depth_first_topo_graph(graph, node, visited,sorted_nodes)
119 if node not in sorted_nodes:
120 raise src.SatException('Error in product dependencies : cycle detection for node %s and %s' % (start,node))
122 sorted_nodes = sorted_nodes + [start]
123 return visited, sorted_nodes
126 # check for p_name that all dependencies are installed
127 def check_dependencies(config, p_name_p_info, all_products_dict):
128 l_depends_not_installed = []
129 for prod in p_name_p_info[1]["depend_all"]:
130 # for each dependency, check the install
131 prod_name, prod_info=all_products_dict[prod]
132 if not(src.product.check_installation(config, prod_info)):
133 l_depends_not_installed.append(prod_name)
134 return l_depends_not_installed # non installed deps
136 def log_step(logger, header, step):
137 logger.write("\r%s%s" % (header, " " * 30), 3)
138 logger.write("\r%s%s" % (header, step), 3)
141 def log_res_step(logger, res):
143 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
146 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
149 def compile_all_products(sat, config, options, products_infos, all_products_dict, all_products_graph, logger):
150 '''Execute the proper configuration commands
151 in each product build directory.
153 :param config Config: The global configuration
154 :param products_info list: List of
155 (str, Config) => (product_name, product_info)
156 :param all_products_dict: Dict of all products
157 :param all_products_graph: graph of all products
158 :param logger Logger: The logger instance to use for the display and logging
159 :return: the number of failing commands.
162 # first loop for the cleaning
163 check_salome_configuration=False
165 for p_name_info in products_infos:
167 p_name, p_info = p_name_info
168 if src.product.product_is_salome(p_info):
169 check_salome_configuration=True
170 # if product is closed source and git server is public skip the current product
171 if src.product.product_is_not_opensource(p_info) and not src.git_server_has_all_repositories(config, config.APPLICATION.properties.git_server):
173 # nothing to clean for native or fixed products
174 if (not src.product.product_compiles(p_info)) or\
175 src.product.product_is_native(p_info) or\
176 src.product.product_is_fixed(p_info):
179 # Clean the build and the install directories
180 # if the corresponding options was called
181 if options.clean_all:
182 sat.clean(config.VARS.application +
183 " --products " + p_name +
184 " --build --install",
187 logger_add_link = logger)
190 # Clean the the install directory
191 # if the corresponding option was called
192 if options.clean_install:
193 sat.clean(config.VARS.application +
194 " --products " + p_name +
198 logger_add_link = logger)
200 # Clean the the install directory
201 # if the corresponding option was called
203 sat.clean(config.VARS.application +
204 " --products " + p_name +
208 logger_add_link = logger)
210 if options.update and src.product.product_is_vcs(p_info):
211 # only VCS products are concerned by update option
214 if len(updated_products)>0:
215 # if other products where updated, check that the current product is a child
216 # in this case it will be also updated
217 if find_path_graph(all_products_graph, p_name, updated_products):
218 logger.write("\nUpdate product %s (child)" % p_name, 5)
220 if (not do_update) and os.path.isdir(p_info.source_dir) \
221 and os.path.isdir(p_info.install_dir):
222 source_time=os.path.getmtime(p_info.source_dir)
223 install_time=os.path.getmtime(p_info.install_dir)
224 if install_time<source_time:
225 logger.write("\nupdate product %s" % p_name, 5)
228 updated_products.append(p_name)
229 sat.clean(config.VARS.application +
230 " --products " + p_name +
231 " --build --install",
234 logger_add_link = logger)
238 if check_salome_configuration:
239 # For salome applications, we check if the sources of configuration modules are present
240 # configuration modules have the property "configure_dependency"
241 # they are implicit prerequisites of the compilation.
244 # get the list of all modules in application
245 all_products_infos = src.product.get_products_infos(config.APPLICATION.products,
248 # for configuration modules, check if sources are present
249 for prod in all_products_dict:
250 product_name, product_info = all_products_dict[prod]
251 if src.product.product_is_configuration(product_info):
252 check_source = check_source and src.product.check_source(product_info)
254 logger.write(_("\nERROR : SOURCES of %s not found! It is required for"
255 " the configuration\n" % product_name))
256 logger.write(_(" Get it with the command : sat prepare %s -p %s \n" %
257 (config.APPLICATION.name, product_name)))
260 return res # error configure dependency : we stop the compilation
262 # second loop to compile
264 for p_name_info in products_infos:
266 p_name, p_info = p_name_info
270 header = _("Compilation of %s") % src.printcolors.printcLabel(p_name)
271 header += " %s " % ("." * (len_end_line - len(p_name)))
272 logger.write(header, 3)
275 # Do nothing if the product is not compilable
276 if not src.product.product_compiles(p_info):
277 log_step(logger, header, "ignored")
278 logger.write("\n", 3, False)
281 # skip product if git server does not host all git repositories
282 # product is not opensource and git server does not have all repositories (closed and open sources)
283 if src.product.product_is_not_opensource(p_info) and not src.git_server_has_all_repositories(config, config.APPLICATION.properties.git_server):
284 log_step(logger, header, "ignored")
285 logger.write("\n", 3, False)
288 # Do nothing if the product is native
289 if src.product.product_is_native(p_info):
290 log_step(logger, header, "native")
291 logger.write("\n", 3, False)
294 # Do nothing if the product is fixed (already compiled by third party)
295 if src.product.product_is_fixed(p_info):
296 log_step(logger, header, "native")
297 logger.write("\n", 3, False)
301 # Recompute the product information to get the right install_dir
302 # (it could change if there is a clean of the install directory)
303 p_info = src.product.get_product_config(config, p_name)
305 # Check if sources was already successfully installed
306 check_source = src.product.check_source(p_info)
307 is_pip= (src.appli_test_property(config,"pip", "yes") and src.product.product_test_property(p_info,"pip", "yes"))
308 # don't check sources with option --show
309 # or for products managed by pip (there sources are in wheels stored in LOCAL.ARCHIVE
310 if not (options.no_compile or is_pip):
312 logger.write(_("Sources of product not found (try 'sat -h prepare') \n"))
313 res += 1 # one more error
315 # if we don't force compilation, check if the was already successfully installed.
316 # we don't compile in this case.
317 if (not options.force) and src.product.check_installation(config, p_info):
318 logger.write(_("Already installed"))
319 logger.write(_(" in %s" % p_info.install_dir), 4)
320 logger.write(_("\n"))
323 # If the show option was called, do not launch the compilation
324 if options.no_compile:
325 logger.write(_("Not installed in %s\n" % p_info.install_dir))
328 # Check if the dependencies are installed
329 l_depends_not_installed = check_dependencies(config, p_name_info, all_products_dict)
330 if len(l_depends_not_installed) > 0:
331 log_step(logger, header, "")
332 logger.write(src.printcolors.printcError(
333 _("ERROR : the following mandatory product(s) is(are) not installed: ")))
334 for prod_name in l_depends_not_installed:
335 logger.write(src.printcolors.printcError(prod_name + " "))
339 # Call the function to compile the product
340 res_prod, len_end_line, error_step = compile_product(
341 sat, p_name_info, config, options, logger, header, len_end_line)
345 # there was an error, we clean install dir, unless :
346 # - the error step is "check", or
347 # - the product is managed by pip and installed in python dir
348 do_not_clean_install=False
349 is_single_dir=(src.appli_test_property(config,"single_install_dir", "yes") and \
350 src.product.product_test_property(p_info,"single_install_dir", "yes"))
352 if (error_step == "CHECK") or (is_pip and src.appli_test_property(config,"pip_install_dir", "python")) or is_single_dir :
353 # cases for which we do not want to remove install dir
354 # for is_single_dir and is_pip, the test to determine if the product is already
355 # compiled is based on configuration file, not the directory
356 do_not_clean_install=True
358 if not do_not_clean_install:
359 # Clean the install directory if there is any
361 "Cleaning the install directory if there is any\n"),
363 sat.clean(config.VARS.application +
364 " --products " + p_name +
368 logger_add_link = logger)
370 # Clean the build directory if the compilation and tests succeed
371 if options.clean_build_after:
372 log_step(logger, header, "CLEAN BUILD")
373 sat.clean(config.VARS.application +
374 " --products " + p_name +
378 logger_add_link = logger)
382 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
383 logger.write("\r" + header + src.printcolors.printcError("KO ") + error_step)
384 logger.write("\n==== %(KO)s in compile of %(name)s \n" %
385 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
386 if error_step == "CHECK":
387 logger.write(_("\nINSTALL directory = %s" %
388 src.printcolors.printcInfo(p_info.install_dir)), 3)
391 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
392 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
393 logger.write(_("\nINSTALL directory = %s" %
394 src.printcolors.printcInfo(p_info.install_dir)), 3)
395 logger.write("\n==== %s \n" % src.printcolors.printcInfo("OK"), 4)
396 logger.write("\n==== Compilation of %(name)s %(OK)s \n" %
397 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
399 logger.write("\n", 3, False)
402 if res_prod != 0 and options.stop_first_fail:
407 def compile_product(sat, p_name_info, config, options, logger, header, len_end):
408 '''Execute the proper configuration command(s)
409 in the product build directory.
411 :param p_name_info tuple: (str, Config) => (product_name, product_info)
412 :param config Config: The global configuration
413 :param logger Logger: The logger instance to use for the display
415 :param header Str: the header to display when logging
416 :param len_end Int: the lenght of the the end of line (used in display)
417 :return: 1 if it fails, else 0.
421 p_name, p_info = p_name_info
423 # Get the build procedure from the product configuration.
425 # build_sources : autotools -> build_configure, configure, make, make install
426 # build_sources : cmake -> cmake, make, make install
427 # build_sources : script -> script executions
431 # check if pip should be used : the application and product have pip property
432 if (src.appli_test_property(config,"pip", "yes") and
433 src.product.product_test_property(p_info,"pip", "yes")):
434 res, len_end_line, error_step = compile_product_pip(sat,
442 if (src.product.product_is_autotools(p_info) or
443 src.product.product_is_cmake(p_info)):
444 res, len_end_line, error_step = compile_product_cmake_autotools(sat,
451 if src.product.product_has_script(p_info):
452 res, len_end_line, error_step = compile_product_script(sat,
460 # Check that the install directory exists
461 if res==0 and not(os.path.exists(p_info.install_dir)):
463 error_step = "NO INSTALL DIR"
464 msg = _("Error: despite the fact that all the steps ended successfully,"
465 " no install directory was found !")
466 logger.write(src.printcolors.printcError(msg), 4)
467 logger.write("\n", 4)
468 return res, len_end, error_step
470 # Add the config file corresponding to the dependencies/versions of the
471 # product that have been successfully compiled
473 logger.write(_("Add the config file in installation directory\n"), 5)
474 # for git bases : add the description of git tag
475 src_sha1=src.system.git_describe(p_info.source_dir)
477 p_info.git_tag_description=src_sha1
478 src.product.add_compile_config_file(p_info, config)
481 # Do the unit tests (call the check command)
482 log_step(logger, header, "CHECK")
483 res_check = sat.check(
484 config.VARS.application + " --products " + p_name,
486 logger_add_link = logger)
492 return res, len_end_line, error_step
495 def compile_product_pip(sat,
502 '''Execute the proper build procedure for pip products
503 :param p_name_info tuple: (str, Config) => (product_name, product_info)
504 :param config Config: The global configuration
505 :param logger Logger: The logger instance to use for the display
507 :param header Str: the header to display when logging
508 :param len_end Int: the lenght of the the end of line (used in display)
509 :return: 1 if it fails, else 0.
512 # pip needs openssl-dev. If openssl is declared in the application, we check it!
513 if "openssl" in config.APPLICATION.products and not src.architecture.is_windows():
514 openssl_cfg = src.product.get_product_config(config, "openssl")
515 if not src.product.check_installation(config, openssl_cfg):
516 raise src.SatException(_("please install system openssl development package, it is required for products managed by pip."))
518 p_name, p_info = p_name_info
521 pip_install_in_python=False
522 pip_wheels_dir=os.path.join(config.LOCAL.archive_dir,"wheels")
523 pip_install_cmd=config.INTERNAL.command.pip_install # parametrized in src/internal
525 # b) get the build environment (useful to get the installed python & pip3)
526 build_environ = src.environment.SalomeEnviron(config,
527 src.environment.Environ(dict(os.environ)),
529 environ_info = src.product.get_product_dependencies(config,
532 build_environ.silent = (config.USER.output_verbose_level < 5)
533 build_environ.set_full_environ(logger, environ_info)
535 # c- download : check/get pip wheel in pip_wheels_dir
536 pip_download_cmd=config.INTERNAL.command.pip_download +\
537 " --destination-directory %s --no-deps %s==%s " %\
538 (pip_wheels_dir, p_info.name, p_info.version)
539 logger.write("\n"+pip_download_cmd+"\n", 4, False)
540 res_pip_dwl = (subprocess.call(pip_download_cmd,
542 cwd=config.LOCAL.workdir,
543 env=build_environ.environ.environ,
544 stdout=logger.logTxtFile,
545 stderr=subprocess.STDOUT) == 0)
546 # error is not managed at the stage. error will be handled by pip install
547 # here we just print a message
549 logger.write("Error in pip download\n", 4, False)
551 pip_version_cmd = 'python -c "import pip;print(pip.__version__)"'
552 res_pip_version = subprocess.check_output(pip_version_cmd,
554 cwd=config.LOCAL.workdir,
555 env=build_environ.environ.environ,
556 stderr=subprocess.STDOUT).decode(sys.stdout.encoding).strip()
557 pip_build_options=int(res_pip_version.split('.')[0]) < 21
559 pip_build_options= True
560 # d- install (in python or in separate product directory)
561 if src.appli_test_property(config,"pip_install_dir", "python"):
562 # pip will install product in python directory"
563 if pip_build_options:
564 pip_install_cmd+=" --find-links=%s --build %s %s==%s" %\
565 (pip_wheels_dir, p_info.build_dir, p_info.name, p_info.version)
567 pip_install_cmd+=" --find-links=%s --cache-dir %s %s==%s" %\
568 (pip_wheels_dir, p_info.build_dir, p_info.name, p_info.version)
569 pip_install_in_python=True
571 # pip will install product in product install_dir
572 pip_install_dir=os.path.join(p_info.install_dir, "lib", "python${PYTHON}", "site-packages")
573 if pip_build_options:
574 pip_install_cmd+=" --find-links=%s --build %s --target %s %s==%s" %\
575 (pip_wheels_dir, p_info.build_dir, pip_install_dir, p_info.name, p_info.version)
577 pip_install_cmd+=" --find-links=%s --cache-dir %s --target %s %s==%s" %\
578 (pip_wheels_dir, p_info.build_dir, pip_install_dir, p_info.name, p_info.version)
579 log_step(logger, header, "PIP")
580 logger.write("\n"+pip_install_cmd+"\n", 4)
581 len_end_line = len_end + 3
584 res_pip = (subprocess.call(pip_install_cmd,
586 cwd=config.LOCAL.workdir,
587 env=build_environ.environ.environ,
588 stdout=logger.logTxtFile,
589 stderr=subprocess.STDOUT) == 0)
593 #log_res_step(logger, res)
596 logger.write("\nError in pip command, please consult details with sat log command's internal traces\n", 3)
598 return res, len_end_line, error_step
602 def compile_product_cmake_autotools(sat,
609 '''Execute the proper build procedure for autotools or cmake
610 in the product build directory.
612 :param p_name_info tuple: (str, Config) => (product_name, product_info)
613 :param config Config: The global configuration
614 :param logger Logger: The logger instance to use for the display
616 :param header Str: the header to display when logging
617 :param len_end Int: the lenght of the the end of line (used in display)
618 :return: 1 if it fails, else 0.
621 p_name, p_info = p_name_info
623 # Execute "sat configure", "sat make" and "sat install"
627 # Logging and sat command call for configure step
628 len_end_line = len_end
629 log_step(logger, header, "CONFIGURE")
630 res_c = sat.configure(config.VARS.application + " --products " + p_name,
632 logger_add_link = logger)
633 log_res_step(logger, res_c)
637 error_step = "CONFIGURE"
639 # Logging and sat command call for make step
640 # Logging take account of the fact that the product has a compilation
642 if src.product.product_has_script(p_info):
643 # if the product has a compilation script,
644 # it is executed during make step
645 scrit_path_display = src.printcolors.printcLabel(
646 p_info.compil_script)
647 log_step(logger, header, "SCRIPT " + scrit_path_display)
648 len_end_line = len(scrit_path_display)
650 log_step(logger, header, "MAKE")
651 make_arguments = config.VARS.application + " --products " + p_name
652 # Get the make_flags option if there is any
653 if options.makeflags:
654 make_arguments += " --option -j" + options.makeflags
655 res_m = sat.make(make_arguments,
657 logger_add_link = logger)
658 log_res_step(logger, res_m)
664 # Logging and sat command call for make install step
665 log_step(logger, header, "MAKE INSTALL")
666 res_mi = sat.makeinstall(config.VARS.application +
670 logger_add_link = logger)
672 log_res_step(logger, res_mi)
676 error_step = "MAKE INSTALL"
678 return res, len_end_line, error_step
680 def compile_product_script(sat,
687 '''Execute the script build procedure in the product build directory.
689 :param p_name_info tuple: (str, Config) => (product_name, product_info)
690 :param config Config: The global configuration
691 :param logger Logger: The logger instance to use for the display
693 :param header Str: the header to display when logging
694 :param len_end Int: the lenght of the the end of line (used in display)
695 :return: 1 if it fails, else 0.
698 p_name, p_info = p_name_info
700 # Execute "sat configure", "sat make" and "sat install"
703 # Logging and sat command call for the script step
704 scrit_path_display = src.printcolors.printcLabel(p_info.compil_script)
705 log_step(logger, header, "SCRIPT " + scrit_path_display)
706 len_end_line = len_end + len(scrit_path_display)
707 res = sat.script(config.VARS.application + " --products " + p_name,
709 logger_add_link = logger)
710 log_res_step(logger, res)
712 return res, len_end_line, error_step
716 '''method that is called when salomeTools is called with --help option.
718 :return: The text to display for the compile command description.
721 return _("The compile command constructs the products of the application"
722 "\n\nexample:\nsat compile SALOME-master --products KERNEL,GUI,"
723 "MEDCOUPLING --clean_all")
725 def run(args, runner, logger):
726 '''method that is called when salomeTools is called with compile parameter.
729 (options, args) = parser.parse_args(args)
731 # Warn the user if he invoked the clean_all option
732 # without --products option
733 if (options.clean_all and
734 options.products is None and
735 not runner.options.batch):
736 rep = input(_("You used --clean_all without specifying a product"
737 " are you sure you want to continue? [Yes/No] "))
738 if rep.upper() != _("YES").upper():
741 if options.update and (options.clean_all or options.force or options.clean_install):
742 options.update=False # update is useless in this case
744 # check that the command has been called with an application
745 src.check_config_has_application( runner.cfg )
747 # write warning if platform is not declared as supported
748 src.check_platform_is_supported( runner.cfg, logger )
750 # Print some informations
751 logger.write(_('Executing the compile commands in the build '
752 'directories of the products of '
753 'the application %s\n') %
754 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
757 (_("SOURCE directory"),
758 os.path.join(runner.cfg.APPLICATION.workdir, 'SOURCES')),
759 (_("BUILD directory"),
760 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))
762 src.print_info(logger, info)
764 # Get the list of all application products, and create its dependency graph
765 all_products_infos = src.product.get_products_infos(runner.cfg.APPLICATION.products,
767 all_products_graph=get_dependencies_graph(all_products_infos)
768 #logger.write("Dependency graph of all application products : %s\n" % all_products_graph, 6)
769 DBG.write("Dependency graph of all application products : ", all_products_graph)
771 # Get the list of products we have to compile
772 products_infos = src.product.get_products_list(options, runner.cfg, logger)
773 products_list = [pi[0] for pi in products_infos]
775 logger.write("Product we have to compile (as specified by user) : %s\n" % products_list, 5)
777 # Extend the list with all recursive dependencies of the given products
779 for p_name in products_list:
780 visited=depth_search_graph(all_products_graph, p_name, visited)
781 products_list = visited
783 logger.write("Product list to compile with fathers : %s\n" % products_list, 5)
785 # Extend the list with all products that depends upon the given products
787 for n in all_products_graph:
788 # for all products (that are not in products_list):
789 # if we we find a path from the product to the product list,
790 # then we product is a child and we add it to the children list
791 if (n not in children) and (n not in products_list):
792 if find_path_graph(all_products_graph, n, products_list):
793 children = children + [n]
794 # complete products_list (the products we have to compile) with the list of children
795 products_list = products_list + children
796 logger.write("Product list to compile with children : %s\n" % products_list, 5)
798 # Sort the list of all products (topological sort).
799 # the products listed first do not depend upon products listed after
802 for n in all_products_graph:
803 if n not in visited_nodes:
804 visited_nodes,sorted_nodes=depth_first_topo_graph(all_products_graph, n, visited_nodes,sorted_nodes)
805 logger.write("Complete dependency graph topological search (sorting): %s\n" % sorted_nodes, 6)
807 # Create a dict of all products to facilitate products_infos sorting
809 for (pname,pinfo) in all_products_infos:
810 all_products_dict[pname]=(pname,pinfo)
812 # Use the sorted list of all products to sort the list of products we have to compile
813 sorted_product_list=[]
814 product_list_runtime=[]
815 product_list_compiletime=[]
817 # store at beginning compile time products, we need to compile them before!
818 for n in sorted_nodes:
819 if n in products_list:
820 sorted_product_list.append(n)
821 logger.write("Sorted list of products to compile : %s\n" % sorted_product_list, 5)
823 # from the sorted list of products to compile, build a sorted list of products infos
825 for product in sorted_product_list:
826 products_infos.append(all_products_dict[product])
828 # for all products to compile, store in "depend_all" field the complete dependencies (recursive)
829 # (will be used by check_dependencies function)
830 for pi in products_infos:
832 dep_prod=depth_search_graph(all_products_graph,pi[0], dep_prod)
833 pi[1]["depend_all"]=dep_prod[1:]
836 # Call the function that will loop over all the products and execute
837 # the right command(s)
838 res = compile_all_products(runner, runner.cfg, options, products_infos, all_products_dict, all_products_graph, logger)
840 # Print the final state
841 nb_products = len(products_infos)
847 logger.write(_("\nCompilation: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
848 { 'status': src.printcolors.printc(final_status),
849 'valid_result': nb_products - res,
850 'nb_products': nb_products }, 1)