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 accepts a comma separated list.'))
28 parser.add_option('o', 'option', 'string', 'option',
29 _('Optional: Option to add to the make 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 make_all_products(config, products_infos, make_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 make_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 = make_product(p_name_info, make_option, config, logger)
65 def make_product(p_name_info, make_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 make_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 = _("Make 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
109 nb_proc, make_opt_without_j = get_nb_proc(p_info, config, make_option)
110 log_step(logger, header, "MAKE -j" + str(nb_proc))
111 if src.architecture.is_windows():
112 res = builder.wmake(nb_proc, make_opt_without_j)
114 res = builder.make(nb_proc, make_opt_without_j)
115 log_res_step(logger, res)
119 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
120 logger.write("\r" + header + src.printcolors.printcError("KO"))
121 logger.write("==== %(KO)s in make of %(name)s \n" %
122 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
125 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
126 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
127 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
128 logger.write("==== Make of %(name)s %(OK)s \n" %
129 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
131 logger.write("\n", 3, False)
135 def get_nb_proc(product_info, config, make_option):
138 new_make_option = make_option
139 if "-j" in make_option:
140 oExpr = re.compile("-j[0-9]+")
141 found = oExpr.search(make_option)
142 opt_nb_proc = int(re.findall('\d+', found.group())[0])
143 new_make_option = make_option.replace(found.group(), "")
146 if "nb_proc" in product_info:
147 # nb proc is specified in module definition
148 nbproc = product_info.nb_proc
149 if opt_nb_proc and opt_nb_proc < product_info.nb_proc:
150 # use command line value only if it is lower than module definition
153 # nb proc is not specified in module definition
157 nbproc = config.VARS.nb_proc
160 return nbproc, new_make_option
163 '''method that is called when salomeTools is called with --help option.
165 :return: The text to display for the make command description.
168 return _("The make command executes the \"make\" command in"
169 " the build directory.\nexample:\nsat make SALOME-master "
170 "--products Python,KERNEL,GUI")
172 def run(args, runner, logger):
173 '''method that is called when salomeTools is called with make parameter.
177 (options, args) = parser.parse_args(args)
179 # check that the command has been called with an application
180 src.check_config_has_application( runner.cfg )
182 # Get the list of products to treat
183 products_infos = src.product.get_products_list(options, runner.cfg, logger)
185 # Print some informations
186 logger.write(_('Executing the make command in the build '
187 'directories of the application %s\n') %
188 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
190 info = [(_("BUILD directory"),
191 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
192 src.print_info(logger, info)
194 # Call the function that will loop over all the products and execute
195 # the right command(s)
196 if options.option is None:
198 res = make_all_products(runner.cfg, products_infos, options.option, logger)
200 # Print the final state
201 nb_products = len(products_infos)
207 logger.write(_("\nMake: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
208 { 'status': src.printcolors.printc(final_status),
209 'valid_result': nb_products - res,
210 'nb_products': nb_products }, 1)