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.'), "")
31 def get_products_list(options, cfg, logger):
32 '''method that gives the product list with their informations from
33 configuration regarding the passed options.
35 :param options Options: The Options instance that stores the commands
37 :param cfg Config: The global configuration
38 :param logger Logger: The logger instance to use for the display and logging
39 :return: The list of (product name, product_informations).
42 # Get the products to be prepared, regarding the options
43 if options.products is None:
44 # No options, get all products sources
45 products = cfg.APPLICATION.products
47 # if option --products, check that all products of the command line
48 # are present in the application.
49 products = options.products
51 if p not in cfg.APPLICATION.products:
52 raise src.SatException(_("Product %(product)s "
53 "not defined in application %(application)s") %
54 { 'product': p, 'application': cfg.VARS.application} )
56 # Construct the list of tuple containing
57 # the products name and their definition
58 products_infos = src.product.get_products_infos(products, cfg)
60 products_infos = [pi for pi in products_infos if not(src.product.product_is_native(pi[1]) or src.product.product_is_fixed(pi[1]))]
64 def log_step(logger, header, step):
65 logger.write("\r%s%s" % (header, " " * 20), 3)
66 logger.write("\r%s%s" % (header, step), 3)
67 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
70 def log_res_step(logger, res):
72 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
75 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
78 def configure_all_products(config, products_infos, conf_option, logger):
79 '''Execute the proper configuration commands
80 in each product build directory.
82 :param config Config: The global configuration
83 :param products_info list: List of
84 (str, Config) => (product_name, product_info)
85 :param conf_option str: The options to add to the command
86 :param logger Logger: The logger instance to use for the display and logging
87 :return: the number of failing commands.
91 for p_name_info in products_infos:
92 res_prod = configure_product(p_name_info, conf_option, config, logger)
97 def configure_product(p_name_info, conf_option, config, logger):
98 '''Execute the proper configuration command(s)
99 in the product build directory.
101 :param p_name_info tuple: (str, Config) => (product_name, product_info)
102 :param conf_option str: The options to add to the command
103 :param config Config: The global configuration
104 :param logger Logger: The logger instance to use for the display
106 :return: 1 if it fails, else 0.
110 p_name, p_info = p_name_info
113 logger.write("\n", 4, False)
114 logger.write("################ ", 4)
115 header = _("Configuration of %s") % src.printcolors.printcLabel(p_name)
116 header += " %s " % ("." * (20 - len(p_name)))
117 logger.write(header, 3)
118 logger.write("\n", 4, False)
121 # Do nothing if he product is not compilable
122 if ("properties" in p_info and "compilation" in p_info.properties and
123 p_info.properties.compilation == "no"):
124 log_step(logger, header, "ignored")
125 logger.write("\n", 3, False)
128 # Instantiate the class that manages all the construction commands
129 # like cmake, make, make install, make test, environment management, etc...
130 builder = src.compilation.Builder(config, logger, p_info)
132 # Prepare the environment
133 log_step(logger, header, "PREPARE ENV")
134 res_prepare = builder.prepare()
135 log_res_step(logger, res_prepare)
137 # Execute buildconfigure, configure if the product is autotools
138 # Execute cmake if the product is cmake
140 if src.product.product_is_autotools(p_info):
141 log_step(logger, header, "BUILDCONFIGURE")
142 res_bc = builder.build_configure()
143 log_res_step(logger, res_bc)
145 log_step(logger, header, "CONFIGURE")
146 res_c = builder.configure(conf_option)
147 log_res_step(logger, res_c)
149 if src.product.product_is_cmake(p_info):
150 log_step(logger, header, "CMAKE")
151 res_cm = builder.cmake(conf_option)
152 log_res_step(logger, res_cm)
157 logger.write("\r%s%s" % (header, " " * 20), 3)
158 logger.write("\r" + header + src.printcolors.printcError("KO"))
159 logger.write("==== %(KO)s in configuration of %(name)s \n" %
160 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
163 logger.write("\r%s%s" % (header, " " * 20), 3)
164 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
165 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
166 logger.write("==== Configuration of %(name)s %(OK)s \n" %
167 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
169 logger.write("\n", 3, False)
174 '''method that is called when salomeTools is called with --help option.
176 :return: The text to display for the configure command description.
179 return _("The configure command executes in the build directory"
180 " the configure commands corresponding\nto the compilation mode"
181 " of the application products.\nThe possible compilation modes"
182 " are \"cmake\", \"autotools\", or a script.\n\nHere are the "
183 "commands to be run :\nautotools: build_configure and configure\n"
184 "cmake: cmake\nscript: do nothing\n\nexample:\nsat configure "
185 "SALOME-master --products KERNEL,GUI,PARAVIS")
187 def run(args, runner, logger):
188 '''method that is called when salomeTools is called with make parameter.
192 (options, args) = parser.parse_args(args)
194 # check that the command has been called with an application
195 src.check_config_has_application( runner.cfg )
197 # Get the list of products to treat
198 products_infos = get_products_list(options, runner.cfg, logger)
200 # Print some informations
201 logger.write(_('Configuring the sources of the application %s\n') %
202 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
204 info = [(_("BUILD directory"),
205 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
206 src.print_info(logger, info)
208 # Call the function that will loop over all the products and execute
209 # the right command(s)
210 if options.option is None:
212 res = configure_all_products(runner.cfg, products_infos, options.option, logger)
214 # Print the final state
215 nb_products = len(products_infos)
221 logger.write(_("\nConfiguration: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
222 { 'status': src.printcolors.printc(final_status),
223 'valid_result': nb_products - res,
224 'nb_products': nb_products }, 1)