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 # Define all possible option for the make command : sat make <options>
25 parser = src.options.Options()
26 parser.add_option('p', 'products', 'list2', 'products',
27 _('products to configure. This option can be'
28 ' passed several time to configure several products.'))
29 parser.add_option('o', 'option', 'string', 'option',
30 _('Option to add to the make command.'), "")
32 def get_products_list(options, cfg, logger):
33 '''method that gives the product list with their informations from
34 configuration regarding the passed options.
36 :param options Options: The Options instance that stores the commands
38 :param cfg Config: The global configuration
39 :param logger Logger: The logger instance to use for the display and logging
40 :return: The list of (product name, product_informations).
43 # Get the products to be prepared, regarding the options
44 if options.products is None:
45 # No options, get all products sources
46 products = cfg.APPLICATION.products
48 # if option --products, check that all products of the command line
49 # are present in the application.
50 products = options.products
52 if p not in cfg.APPLICATION.products:
53 raise src.SatException(_("Product %(product)s "
54 "not defined in application %(application)s") %
55 { 'product': p, 'application': cfg.VARS.application} )
57 # Construct the list of tuple containing
58 # the products name and their definition
59 products_infos = src.product.get_products_infos(products, cfg)
61 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]))]
65 def log_step(logger, header, step):
66 logger.write("\r%s%s" % (header, " " * 20), 3)
67 logger.write("\r%s%s" % (header, step), 3)
68 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
71 def log_res_step(logger, res):
73 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
76 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
79 def make_all_products(config, products_infos, make_option, logger):
80 '''Execute the proper configuration commands
81 in each product build directory.
83 :param config Config: The global configuration
84 :param products_info list: List of
85 (str, Config) => (product_name, product_info)
86 :param make_option str: The options to add to the command
87 :param logger Logger: The logger instance to use for the display and logging
88 :return: the number of failing commands.
92 for p_name_info in products_infos:
93 res_prod = make_product(p_name_info, make_option, config, logger)
98 def make_product(p_name_info, make_option, config, logger):
99 '''Execute the proper configuration command(s)
100 in the product build directory.
102 :param p_name_info tuple: (str, Config) => (product_name, product_info)
103 :param make_option str: The options to add to the command
104 :param config Config: The global configuration
105 :param logger Logger: The logger instance to use for the display
107 :return: 1 if it fails, else 0.
111 p_name, p_info = p_name_info
114 logger.write("\n", 4, False)
115 logger.write("################ ", 4)
116 header = _("Make of %s") % src.printcolors.printcLabel(p_name)
117 header += " %s " % ("." * (20 - len(p_name)))
118 logger.write(header, 3)
119 logger.write("\n", 4, False)
122 # Instantiate the class that manages all the construction commands
123 # like cmake, make, make install, make test, environment management, etc...
124 builder = src.compilation.Builder(config, logger, p_info)
126 # Prepare the environment
127 log_step(logger, header, "PREPARE ENV")
128 res_prepare = builder.prepare()
129 log_res_step(logger, res_prepare)
131 # Execute buildconfigure, configure if the product is autotools
132 # Execute cmake if the product is cmake
134 if not src.product.product_has_script(p_info):
135 nb_proc, make_opt_without_j = get_nb_proc(p_info, config, make_option)
136 log_step(logger, header, "MAKE -j" + str(nb_proc))
137 res_m = builder.make(nb_proc, make_opt_without_j)
138 log_res_step(logger, res_m)
143 logger.write("\r%s%s" % (header, " " * 20), 3)
144 logger.write("\r" + header + src.printcolors.printcError("KO"))
145 logger.write("==== %(KO)s in make of %(name)s \n" %
146 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
149 logger.write("\r%s%s" % (header, " " * 20), 3)
150 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
151 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
152 logger.write("==== Make of %(name)s %(OK)s \n" %
153 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
155 logger.write("\n", 3, False)
159 def get_nb_proc(product_info, config, make_option):
162 new_make_option = make_option
163 if "-j" in make_option:
164 oExpr = re.compile("-j[0-9]+")
165 found = oExpr.search(make_option)
166 opt_nb_proc = int(re.findall('\d+', found.group())[0])
167 new_make_option = make_option.replace(found.group(), "")
170 if "nb_proc" in product_info:
171 # nb proc is specified in module definition
172 nbproc = product_info.nb_proc
173 if opt_nb_proc and opt_nb_proc < product_info.nb_proc:
174 # use command line value only if it is lower than module definition
177 # nb proc is not specified in module definition
181 nbproc = config.VARS.nb_proc
184 return nbproc, new_make_option
187 '''method that is called when salomeTools is called with --help option.
189 :return: The text to display for the make command description.
192 return _("The make command executes the \"make\" command in"
193 " the build directory")
195 def run(args, runner, logger):
196 '''method that is called when salomeTools is called with make parameter.
200 (options, args) = parser.parse_args(args)
202 # check that the command has been called with an application
203 src.check_config_has_application( runner.cfg )
205 # Get the list of products to threat
206 products_infos = get_products_list(options, runner.cfg, logger)
208 # Print some informations
209 logger.write(_('Executing the make command in the build directories of the application %s\n') %
210 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
212 info = [(_("BUILD directory"),
213 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
214 src.print_info(logger, info)
216 # Call the function that will loop over all the products and execute
217 # the right command(s)
218 res = make_all_products(runner.cfg, products_infos, options.option, logger)
220 # Print the final state
221 nb_products = len(products_infos)
227 logger.write(_("\nMake: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
228 { 'status': src.printcolors.printc(final_status),
229 'valid_result': nb_products - res,
230 'nb_products': nb_products }, 1)