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 the check command : sat check <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.'))
29 def get_products_list(options, cfg, logger):
30 '''method that gives the product list with their informations from
31 configuration regarding the passed options.
33 :param options Options: The Options instance that stores the commands
35 :param cfg Config: The global configuration
36 :param logger Logger: The logger instance to use for the display and
38 :return: The list of (product name, product_informations).
41 # Get the products to be prepared, regarding the options
42 if options.products is None:
43 # No options, get all products sources
44 products = cfg.APPLICATION.products
46 # if option --products, check that all products of the command line
47 # are present in the application.
48 products = options.products
50 if p not in cfg.APPLICATION.products:
51 raise src.SatException(_("Product %(product)s "
52 "not defined in application %(application)s") %
53 { 'product': p, 'application': cfg.VARS.application} )
55 # Construct the list of tuple containing
56 # the products name and their definition
57 products_infos = src.product.get_products_infos(products, cfg)
59 products_infos = [pi for pi in products_infos if not(
60 src.product.product_is_native(pi[1]) or
61 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 check_all_products(config, products_infos, 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 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 = check_product(p_name_info, config, logger)
97 def check_product(p_name_info, 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 config Config: The global configuration
103 :param logger Logger: The logger instance to use for the display
105 :return: 1 if it fails, else 0.
109 p_name, p_info = p_name_info
112 logger.write("\n", 4, False)
113 logger.write("################ ", 4)
114 header = _("Check of %s") % src.printcolors.printcLabel(p_name)
115 header += " %s " % ("." * (20 - len(p_name)))
116 logger.write(header, 3)
117 logger.write("\n", 4, False)
120 # Instantiate the class that manages all the construction commands
121 # like cmake, check, make install, make test, environment management, etc...
122 builder = src.compilation.Builder(config, logger, p_info)
124 # Prepare the environment
125 log_step(logger, header, "PREPARE ENV")
126 res_prepare = builder.prepare()
127 log_res_step(logger, res_prepare)
129 # Execute buildconfigure, configure if the product is autotools
130 # Execute ccheck if the product is ccheck
133 log_step(logger, header, "CHECK")
134 res = builder.check()
135 log_res_step(logger, res)
139 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
140 logger.write("\r" + header + src.printcolors.printcError("KO"))
141 logger.write("==== %(KO)s in check of %(name)s \n" %
142 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
145 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
146 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
147 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
148 logger.write("==== Check of %(name)s %(OK)s \n" %
149 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
151 logger.write("\n", 3, False)
156 '''method that is called when salomeTools is called with --help option.
158 :return: The text to display for the check command description.
161 return _("The check command executes the \"check\" command in"
162 " the build directory")
164 def run(args, runner, logger):
165 '''method that is called when salomeTools is called with check parameter.
169 (options, args) = parser.parse_args(args)
171 # check that the command has been called with an application
172 src.check_config_has_application( runner.cfg )
174 # Get the list of products to treat
175 products_infos = get_products_list(options, runner.cfg, logger)
177 # Print some informations
178 logger.write(_('Executing the check command in the build '
179 'directories of the application %s\n') %
180 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
182 info = [(_("BUILD directory"),
183 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
184 src.print_info(logger, info)
186 # Call the function that will loop over all the products and execute
187 # the right command(s)
188 res = check_all_products(runner.cfg, products_infos, logger)
190 # Print the final state
191 nb_products = len(products_infos)
197 logger.write(_("\nCheck: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
198 { 'status': src.printcolors.printc(final_status),
199 'valid_result': nb_products - res,
200 'nb_products': nb_products }, 1)