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 nb_proc, make_opt_without_j = get_nb_proc(p_info, config, make_option)
146 log_step(logger, header, "MAKE -j" + str(nb_proc))
147 res_m = builder.make(nb_proc, make_opt_without_j)
148 log_res_step(logger, res_m)
153 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
154 logger.write("\r" + header + src.printcolors.printcError("KO"))
155 logger.write("==== %(KO)s in make of %(name)s \n" %
156 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
159 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
160 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
161 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
162 logger.write("==== Make of %(name)s %(OK)s \n" %
163 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
165 logger.write("\n", 3, False)
169 def get_nb_proc(product_info, config, make_option):
172 new_make_option = make_option
173 if "-j" in make_option:
174 oExpr = re.compile("-j[0-9]+")
175 found = oExpr.search(make_option)
176 opt_nb_proc = int(re.findall('\d+', found.group())[0])
177 new_make_option = make_option.replace(found.group(), "")
180 if "nb_proc" in product_info:
181 # nb proc is specified in module definition
182 nbproc = product_info.nb_proc
183 if opt_nb_proc and opt_nb_proc < product_info.nb_proc:
184 # use command line value only if it is lower than module definition
187 # nb proc is not specified in module definition
191 nbproc = config.VARS.nb_proc
194 return nbproc, new_make_option
197 '''method that is called when salomeTools is called with --help option.
199 :return: The text to display for the make command description.
202 return _("The make command executes the \"make\" command in"
203 " the build directory.\nIn case of a product that is constructed "
204 "using a script (build_source : \"script\"), then the make "
205 "command executes the script.\n\nexample:\nsat make SALOME-master "
206 "--products Python,KERNEL,GUI")
208 def run(args, runner, logger):
209 '''method that is called when salomeTools is called with make parameter.
213 (options, args) = parser.parse_args(args)
215 # check that the command has been called with an application
216 src.check_config_has_application( runner.cfg )
218 # Get the list of products to treat
219 products_infos = get_products_list(options, runner.cfg, logger)
221 # Print some informations
222 logger.write(_('Executing the make command in the build '
223 'directories of the application %s\n') %
224 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
226 info = [(_("BUILD directory"),
227 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
228 src.print_info(logger, info)
230 # Call the function that will loop over all the products and execute
231 # the right command(s)
232 if options.option is None:
234 res = make_all_products(runner.cfg, products_infos, options.option, logger)
236 # Print the final state
237 nb_products = len(products_infos)
243 logger.write(_("\nMake: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
244 { 'status': src.printcolors.printc(final_status),
245 'valid_result': nb_products - res,
246 'nb_products': nb_products }, 1)