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 _('Optional: 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 __, p_info = p_name_info
93 if ("build_dir" not in "build_dir" or
94 not src.product.product_compiles(p_info)):
96 res_prod = check_product(p_name_info, config, logger)
101 def check_product(p_name_info, 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 config Config: The global configuration
107 :param logger Logger: The logger instance to use for the display
109 :return: 1 if it fails, else 0.
113 p_name, p_info = p_name_info
116 logger.write("\n", 4, False)
117 logger.write("################ ", 4)
118 header = _("Check of %s") % src.printcolors.printcLabel(p_name)
119 header += " %s " % ("." * (20 - len(p_name)))
120 logger.write(header, 3)
121 logger.write("\n", 4, False)
124 # Instantiate the class that manages all the construction commands
125 # like cmake, check, make install, make test, environment management, etc...
126 builder = src.compilation.Builder(config, logger, p_info)
128 # Prepare the environment
129 log_step(logger, header, "PREPARE ENV")
130 res_prepare = builder.prepare()
131 log_res_step(logger, res_prepare)
133 # Execute buildconfigure, configure if the product is autotools
134 # Execute ccheck if the product is ccheck
137 log_step(logger, header, "CHECK")
138 res = builder.check()
139 log_res_step(logger, res)
143 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
144 logger.write("\r" + header + src.printcolors.printcError("KO"))
145 logger.write("==== %(KO)s in check of %(name)s \n" %
146 { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
149 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
150 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
151 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
152 logger.write("==== Check of %(name)s %(OK)s \n" %
153 { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
155 logger.write("\n", 3, False)
160 '''method that is called when salomeTools is called with --help option.
162 :return: The text to display for the check command description.
165 return _("The check command executes the \"check\" command in"
166 " the build directory of all the products of the application."
167 "\nIt is possible to reduce the list of products to check by using"
168 " the --products option\n\nexample\nsat check SALOME-master "
169 "--products KERNEL,GUI,GEOM")
171 def run(args, runner, logger):
172 '''method that is called when salomeTools is called with check parameter.
176 (options, args) = parser.parse_args(args)
178 # check that the command has been called with an application
179 src.check_config_has_application( runner.cfg )
181 # Get the list of products to treat
182 products_infos = get_products_list(options, runner.cfg, logger)
184 # Print some informations
185 logger.write(_('Executing the check command in the build '
186 'directories of the application %s\n') %
187 src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
189 info = [(_("BUILD directory"),
190 os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
191 src.print_info(logger, info)
193 # Call the function that will loop over all the products and execute
194 # the right command(s)
195 res = check_all_products(runner.cfg, products_infos, logger)
197 # Print the final state
198 nb_products = len(products_infos)
204 logger.write(_("\nCheck: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
205 { 'status': src.printcolors.printc(final_status),
206 'valid_result': nb_products - res,
207 'nb_products': nb_products }, 1)