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
23 # Define all possible option for configure command : sat configure <options>
24 parser = src.options.Options()
25 parser.add_option('p', 'products', 'list2', 'products',
26 _('Optional: products to configure. This option accepts a comma separated list.'))
27 parser.add_option('o', 'option', 'string', 'option',
28 _('Optional: Option to add to the configure or cmake command.'), "")
31 def log_step(logger, header, step):
32 logger.write("\r%s%s" % (header, " " * 20), 3)
33 logger.write("\r%s%s" % (header, step), 3)
34 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
37 def log_res_step(logger, res):
39 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
42 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
45 def configure_all_products(config, products_infos, conf_option, logger):
46 '''Execute the proper configuration commands
47 in each product build directory.
49 :param config Config: The global configuration
50 :param products_info list: List of
51 (str, Config) => (product_name, product_info)
52 :param conf_option str: The options to add to the command
53 :param logger Logger: The logger instance to use for the display and logging
54 :return: the number of failing commands.
58 for p_name_info in products_infos:
59 res_prod = configure_product(p_name_info, conf_option, config, logger)
64 def configure_product(p_name_info, conf_option, config, logger):
65 '''Execute the proper configuration command(s)
66 in the product build directory.
68 :param p_name_info tuple: (str, Config) => (product_name, product_info)
69 :param conf_option str: The options to add to the command
70 :param config Config: The global configuration
71 :param logger Logger: The logger instance to use for the display
73 :return: 1 if it fails, else 0.
77 p_name, p_info = p_name_info
80 logger.write("\n", 4, False)
81 logger.write("################ ", 4)
82 header = _("Configuration of %s") % src.printcolors.printcLabel(p_name)
83 header += " %s " % ("." * (20 - len(p_name)))
84 logger.write(header, 3)
85 logger.write("\n", 4, False)
88 # Do nothing if he product is not compilable
89 if ("properties" in p_info and "compilation" in p_info.properties and
90 p_info.properties.compilation == "no"):
91 log_step(logger, header, "ignored")
92 logger.write("\n", 3, False)
95 # Instantiate the class that manages all the construction commands
96 # like cmake, make, make install, make test, environment management, etc...
97 builder = src.compilation.Builder(config, logger, p_name, p_info)
99 # Prepare the environment
100 log_step(logger, header, "PREPARE ENV")
101 res_prepare = builder.prepare()
102 log_res_step(logger, res_prepare)
104 # Execute buildconfigure, configure if the product is autotools
105 # Execute cmake if the product is cmake
107 if src.product.product_is_autotools(p_info):
108 log_step(logger, header, "BUILDCONFIGURE")
109 res_bc = builder.build_configure()
110 log_res_step(logger, res_bc)
112 log_step(logger, header, "CONFIGURE")
113 res_c = builder.configure(conf_option)
114 log_res_step(logger, res_c)
116 if src.product.product_is_cmake(p_info):
117 log_step(logger, header, "CMAKE")
118 res_cm = builder.cmake(conf_option)
119 log_res_step(logger, res_cm)
124 logger.write("\r%s%s" % (header, " " * 20), 3)
125 logger.write("\r" + header + src.printcolors.printcError("KO"))
126 logger.write("==== %(KO)s in configuration of %(name)s \n" %
127 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
130 logger.write("\r%s%s" % (header, " " * 20), 3)
131 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
132 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
133 logger.write("==== Configuration of %(name)s %(OK)s \n" %
134 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
136 logger.write("\n", 3, False)
141 '''method that is called when salomeTools is called with --help option.
143 :return: The text to display for the configure command description.
146 return _("The configure command executes in the build directory"
147 " the configure commands corresponding\nto the compilation mode"
148 " of the application products.\nThe possible compilation modes"
149 " are \"cmake\", \"autotools\", or a script.\n\nHere are the "
150 "commands to be run :\nautotools: build_configure and configure\n"
151 "cmake: cmake\nscript: do nothing\n\nexample:\nsat configure "
152 "SALOME-master --products KERNEL,GUI,PARAVIS")
154 def run(args, runner, logger):
155 '''method that is called when salomeTools is called with make parameter.
159 (options, args) = parser.parse_args(args)
161 # check that the command has been called with an application
162 src.check_config_has_application( runner.cfg )
164 # Get the list of products to treat
165 products_infos = src.product.get_products_list(options, runner.cfg, logger)
167 # Print some informations
168 logger.write(_('Configuring the sources of the application %s\n') %
169 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
171 info = [(_("BUILD directory"),
172 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
173 src.print_info(logger, info)
175 # Call the function that will loop over all the products and execute
176 # the right command(s)
177 if options.option is None:
179 res = configure_all_products(runner.cfg, products_infos, options.option, logger)
181 # Print the final state
182 nb_products = len(products_infos)
188 logger.write(_("\nConfiguration: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
189 { 'status': src.printcolors.printc(final_status),
190 'valid_result': nb_products - res,
191 'nb_products': nb_products }, 1)