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 _('Optional: products to configure. This option can be'
28 ' passed several time to configure several products.'))
29 parser.add_option('o', 'option', 'string', 'option',
30 _('Optional: 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
41 :return: The list of (product name, product_informations).
44 # Get the products to be prepared, regarding the options
45 if options.products is None:
46 # No options, get all products sources
47 products = cfg.APPLICATION.products
49 # if option --products, check that all products of the command line
50 # are present in the application.
51 products = options.products
53 if p not in cfg.APPLICATION.products:
54 raise src.SatException(_("Product %(product)s "
55 "not defined in application %(application)s") %
56 { 'product': p, 'application': cfg.VARS.application} )
58 # Construct the list of tuple containing
59 # the products name and their definition
60 products_infos = src.product.get_products_infos(products, cfg)
62 products_infos = [pi for pi in products_infos if not(
63 src.product.product_is_native(pi[1]) or
64 src.product.product_is_fixed(pi[1]))]
68 def log_step(logger, header, step):
69 logger.write("\r%s%s" % (header, " " * 20), 3)
70 logger.write("\r%s%s" % (header, step), 3)
71 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
74 def log_res_step(logger, res):
76 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
79 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
82 def make_all_products(config, products_infos, make_option, logger):
83 '''Execute the proper configuration commands
84 in each product build directory.
86 :param config Config: The global configuration
87 :param products_info list: List of
88 (str, Config) => (product_name, product_info)
89 :param make_option str: The options to add to the command
90 :param logger Logger: The logger instance to use for the display and logging
91 :return: the number of failing commands.
95 for p_name_info in products_infos:
96 res_prod = make_product(p_name_info, make_option, config, logger)
101 def make_product(p_name_info, make_option, config, logger):
102 '''Execute the proper configuration command(s)
103 in the product build directory.
105 :param p_name_info tuple: (str, Config) => (product_name, product_info)
106 :param make_option str: The options to add to the command
107 :param config Config: The global configuration
108 :param logger Logger: The logger instance to use for the display
110 :return: 1 if it fails, else 0.
114 p_name, p_info = p_name_info
117 logger.write("\n", 4, False)
118 logger.write("################ ", 4)
119 header = _("Make of %s") % src.printcolors.printcLabel(p_name)
120 header += " %s " % ("." * (20 - len(p_name)))
121 logger.write(header, 3)
122 logger.write("\n", 4, False)
125 # Do nothing if he product is not compilable
126 if ("properties" in p_info and "compilation" in p_info.properties and
127 p_info.properties.compilation == "no"):
128 log_step(logger, header, "ignored")
129 logger.write("\n", 3, False)
132 # Instantiate the class that manages all the construction commands
133 # like cmake, make, make install, make test, environment management, etc...
134 builder = src.compilation.Builder(config, logger, p_info)
136 # Prepare the environment
137 log_step(logger, header, "PREPARE ENV")
138 res_prepare = builder.prepare()
139 log_res_step(logger, res_prepare)
141 # Execute buildconfigure, configure if the product is autotools
142 # Execute cmake if the product is cmake
145 if not src.product.product_has_script(p_info):
146 nb_proc, make_opt_without_j = get_nb_proc(p_info, config, make_option)
147 log_step(logger, header, "MAKE -j" + str(nb_proc))
148 res_m = builder.make(nb_proc, make_opt_without_j)
149 log_res_step(logger, res_m)
152 scrit_path_display = src.printcolors.printcLabel(p_info.compil_script)
153 log_step(logger, header, "SCRIPT " + scrit_path_display)
154 len_end_line += len(scrit_path_display)
155 res_s = builder.do_script_build(p_info.compil_script)
156 log_res_step(logger, res_s)
161 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
162 logger.write("\r" + header + src.printcolors.printcError("KO"))
163 logger.write("==== %(KO)s in make of %(name)s \n" %
164 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
167 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
168 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
169 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
170 logger.write("==== Make of %(name)s %(OK)s \n" %
171 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
173 logger.write("\n", 3, False)
177 def get_nb_proc(product_info, config, make_option):
180 new_make_option = make_option
181 if "-j" in make_option:
182 oExpr = re.compile("-j[0-9]+")
183 found = oExpr.search(make_option)
184 opt_nb_proc = int(re.findall('\d+', found.group())[0])
185 new_make_option = make_option.replace(found.group(), "")
188 if "nb_proc" in product_info:
189 # nb proc is specified in module definition
190 nbproc = product_info.nb_proc
191 if opt_nb_proc and opt_nb_proc < product_info.nb_proc:
192 # use command line value only if it is lower than module definition
195 # nb proc is not specified in module definition
199 nbproc = config.VARS.nb_proc
202 return nbproc, new_make_option
205 '''method that is called when salomeTools is called with --help option.
207 :return: The text to display for the make command description.
210 return _("The make command executes the \"make\" command in"
211 " the build directory.\nIn case of a product that is constructed "
212 "using a script (build_source : \"script\"), then the make "
213 "command executes the script.\n\nexample:\nsat make SALOME-master "
214 "--products Python,KERNEL,GUI")
216 def run(args, runner, logger):
217 '''method that is called when salomeTools is called with make parameter.
221 (options, args) = parser.parse_args(args)
223 # check that the command has been called with an application
224 src.check_config_has_application( runner.cfg )
226 # Get the list of products to treat
227 products_infos = get_products_list(options, runner.cfg, logger)
229 # Print some informations
230 logger.write(_('Executing the make command in the build '
231 'directories of the application %s\n') %
232 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
234 info = [(_("BUILD directory"),
235 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
236 src.print_info(logger, info)
238 # Call the function that will loop over all the products and execute
239 # the right command(s)
240 if options.option is None:
242 res = make_all_products(runner.cfg, products_infos, options.option, logger)
244 # Print the final state
245 nb_products = len(products_infos)
251 logger.write(_("\nMake: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
252 { 'status': src.printcolors.printc(final_status),
253 'valid_result': nb_products - res,
254 'nb_products': nb_products }, 1)