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 can be'
27 ' passed several time to configure several products.'))
28 parser.add_option('o', 'option', 'string', 'option',
29 _('Optional: Option to add to the configure or cmake command.'), "")
32 def log_step(logger, header, step):
33 logger.write("\r%s%s" % (header, " " * 20), 3)
34 logger.write("\r%s%s" % (header, step), 3)
35 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
38 def log_res_step(logger, res):
40 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
43 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
46 def configure_all_products(config, products_infos, conf_option, logger):
47 '''Execute the proper configuration commands
48 in each product build directory.
50 :param config Config: The global configuration
51 :param products_info list: List of
52 (str, Config) => (product_name, product_info)
53 :param conf_option str: The options to add to the command
54 :param logger Logger: The logger instance to use for the display and logging
55 :return: the number of failing commands.
59 for p_name_info in products_infos:
60 res_prod = configure_product(p_name_info, conf_option, config, logger)
65 def configure_product(p_name_info, conf_option, config, logger):
66 '''Execute the proper configuration command(s)
67 in the product build directory.
69 :param p_name_info tuple: (str, Config) => (product_name, product_info)
70 :param conf_option str: The options to add to the command
71 :param config Config: The global configuration
72 :param logger Logger: The logger instance to use for the display
74 :return: 1 if it fails, else 0.
78 p_name, p_info = p_name_info
81 logger.write("\n", 4, False)
82 logger.write("################ ", 4)
83 header = _("Configuration of %s") % src.printcolors.printcLabel(p_name)
84 header += " %s " % ("." * (20 - len(p_name)))
85 logger.write(header, 3)
86 logger.write("\n", 4, False)
89 # Do nothing if he product is not compilable
90 if ("properties" in p_info and "compilation" in p_info.properties and
91 p_info.properties.compilation == "no"):
92 log_step(logger, header, "ignored")
93 logger.write("\n", 3, False)
96 # Instantiate the class that manages all the construction commands
97 # like cmake, make, make install, make test, environment management, etc...
98 builder = src.compilation.Builder(config, logger, p_info)
100 # Prepare the environment
101 log_step(logger, header, "PREPARE ENV")
102 res_prepare = builder.prepare()
103 log_res_step(logger, res_prepare)
105 # Execute buildconfigure, configure if the product is autotools
106 # Execute cmake if the product is cmake
108 if src.product.product_is_autotools(p_info):
109 log_step(logger, header, "BUILDCONFIGURE")
110 res_bc = builder.build_configure()
111 log_res_step(logger, res_bc)
113 log_step(logger, header, "CONFIGURE")
114 res_c = builder.configure(conf_option)
115 log_res_step(logger, res_c)
117 if src.product.product_is_cmake(p_info):
118 log_step(logger, header, "CMAKE")
119 res_cm = builder.cmake(conf_option)
120 log_res_step(logger, res_cm)
125 logger.write("\r%s%s" % (header, " " * 20), 3)
126 logger.write("\r" + header + src.printcolors.printcError("KO"))
127 logger.write("==== %(KO)s in configuration of %(name)s \n" %
128 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
131 logger.write("\r%s%s" % (header, " " * 20), 3)
132 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
133 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
134 logger.write("==== Configuration of %(name)s %(OK)s \n" %
135 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
137 logger.write("\n", 3, False)
142 '''method that is called when salomeTools is called with --help option.
144 :return: The text to display for the configure command description.
147 return _("The configure command executes in the build directory"
148 " the configure commands corresponding\nto the compilation mode"
149 " of the application products.\nThe possible compilation modes"
150 " are \"cmake\", \"autotools\", or a script.\n\nHere are the "
151 "commands to be run :\nautotools: build_configure and configure\n"
152 "cmake: cmake\nscript: do nothing\n\nexample:\nsat configure "
153 "SALOME-master --products KERNEL,GUI,PARAVIS")
155 def run(args, runner, logger):
156 '''method that is called when salomeTools is called with make parameter.
160 (options, args) = parser.parse_args(args)
162 # check that the command has been called with an application
163 src.check_config_has_application( runner.cfg )
165 # Get the list of products to treat
166 products_infos = src.product.get_products_list(options, runner.cfg, logger)
168 # Print some informations
169 logger.write(_('Configuring the sources of the application %s\n') %
170 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
172 info = [(_("BUILD directory"),
173 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
174 src.print_info(logger, info)
176 # Call the function that will loop over all the products and execute
177 # the right command(s)
178 if options.option is None:
180 res = configure_all_products(runner.cfg, products_infos, options.option, logger)
182 # Print the final state
183 nb_products = len(products_infos)
189 logger.write(_("\nConfiguration: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
190 { 'status': src.printcolors.printc(final_status),
191 'valid_result': nb_products - res,
192 'nb_products': nb_products }, 1)