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 _('products to configure. This option can be'
27 ' passed several time to configure several products.'))
28 parser.add_option('o', 'option', 'string', 'option',
29 _('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 # Instantiate the class that manages all the construction commands
122 # like cmake, make, make install, make test, environment management, etc...
123 builder = src.compilation.Builder(config, logger, p_info)
125 # Prepare the environment
126 log_step(logger, header, "PREPARE ENV")
127 res_prepare = builder.prepare()
128 log_res_step(logger, res_prepare)
130 # Execute buildconfigure, configure if the product is autotools
131 # Execute cmake if the product is cmake
133 if src.product.product_is_autotools(p_info):
134 log_step(logger, header, "BUILDCONFIGURE")
135 res_bc = builder.build_configure()
136 log_res_step(logger, res_bc)
138 log_step(logger, header, "CONFIGURE")
139 res_c = builder.configure(conf_option)
140 log_res_step(logger, res_c)
142 if src.product.product_is_cmake(p_info):
143 log_step(logger, header, "CMAKE")
144 res_cm = builder.cmake(conf_option)
145 log_res_step(logger, res_cm)
150 logger.write("\r%s%s" % (header, " " * 20), 3)
151 logger.write("\r" + header + src.printcolors.printcError("KO"))
152 logger.write("==== %(KO)s in configuration of %(name)s \n" %
153 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
156 logger.write("\r%s%s" % (header, " " * 20), 3)
157 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
158 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
159 logger.write("==== Configuration of %(name)s %(OK)s \n" %
160 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
162 logger.write("\n", 3, False)
167 '''method that is called when salomeTools is called with --help option.
169 :return: The text to display for the configure command description.
172 return _("The configure command executes in the build directory"
173 " the configure commands corresponding to the compilation mode"
174 " of the application products.\nThe possible compilation modes"
175 " are \"cmake\", \"autotools\", or a script.\n\nHere are the "
176 "commands to be run :\nautotools: build_configure and configure\n"
177 "cmake: cmake\nscript: N\A")
179 def run(args, runner, logger):
180 '''method that is called when salomeTools is called with make parameter.
184 (options, args) = parser.parse_args(args)
186 # check that the command has been called with an application
187 src.check_config_has_application( runner.cfg )
189 # Get the list of products to treat
190 products_infos = get_products_list(options, runner.cfg, logger)
192 # Print some informations
193 logger.write(_('Configuring the sources of the application %s\n') %
194 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
196 info = [(_("BUILD directory"),
197 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
198 src.print_info(logger, info)
200 # Call the function that will loop over all the products and execute
201 # the right command(s)
202 if options.option is None:
204 res = configure_all_products(runner.cfg, products_infos, options.option, logger)
206 # Print the final state
207 nb_products = len(products_infos)
213 logger.write(_("\nConfiguration: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
214 { 'status': src.printcolors.printc(final_status),
215 'valid_result': nb_products - res,
216 'nb_products': nb_products }, 1)