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
22 # Define all possible option for the check command : sat check <options>
23 parser = src.options.Options()
29 _("Optional: products to check. This option accepts a comma separated list."),
32 CHECK_PROPERTY = "has_unit_tests"
35 def log_step(logger, header, step):
36 logger.write("\r%s%s" % (header, " " * 20), 3)
37 logger.write("\r%s%s" % (header, step), 3)
38 logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
42 def log_res_step(logger, res):
44 logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
47 logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
51 def check_all_products(config, products_infos, logger):
52 """Execute the proper configuration commands
53 in each product build directory.
55 :param config Config: The global configuration
56 :param products_info list: List of
57 (str, Config) => (product_name, product_info)
58 :param logger Logger: The logger instance to use for the display and logging
59 :return: the number of failing commands.
63 for p_name_info in products_infos:
64 res_prod = check_product(p_name_info, config, logger)
70 def check_product(p_name_info, config, logger):
71 """Execute the proper configuration command(s)
72 in the product build directory.
74 :param p_name_info tuple: (str, Config) => (product_name, product_info)
75 :param config Config: The global configuration
76 :param logger Logger: The logger instance to use for the display
78 :return: 1 if it fails, else 0.
82 p_name, p_info = p_name_info
85 logger.write("\n", 4, False)
86 logger.write("################ ", 4)
87 header = _("Check of %s") % src.printcolors.printcLabel(p_name)
88 header += " %s " % ("." * (20 - len(p_name)))
89 logger.write(header, 3)
90 logger.write("\n", 4, False)
93 # Verify if the command has to be launched or not
95 if src.product.product_is_native(p_info):
97 "The product %s is defined as being native. " "product ignored." % p_name
99 logger.write("%s\n" % msg, 4)
101 elif not src.get_property_in_product_cfg(p_info, CHECK_PROPERTY):
103 "The product %s is defined as not having tests. "
104 "product ignored." % p_name
106 logger.write("%s\n" % msg, 4)
108 elif not src.product.product_compiles(p_info):
110 "The product %s is defined as not compiling. " "product ignored." % p_name
112 logger.write("%s\n" % msg, 4)
114 elif "build_dir" not in p_info:
116 "No build_dir key defined in "
117 "the config file of %s: product ignored." % p_name
119 logger.write("%s\n" % msg, 4)
122 # Get the command to execute for script products
125 if src.product.product_has_script(p_info) and not ignored:
126 command = src.get_cfg_param(p_info, "test_build", "Not found")
127 if command == "Not found":
130 "WARNING: The product %s is defined as having tests. But it"
131 ' is compiled using a script and the key "test_build" is '
132 "not defined in the definition of %s" % (p_name, p_name)
134 logger.write("%s\n" % msg, 4)
136 if ignored or not cmd_found:
137 log_step(logger, header, "ignored")
139 "==== %(name)s %(IGNORED)s\n"
140 % {"name": p_name, "IGNORED": src.printcolors.printcInfo("IGNORED")},
143 logger.write("\n", 3, False)
149 # Instantiate the class that manages all the construction commands
150 # like cmake, check, make install, make test, environment management, etc...
151 builder = src.compilation.Builder(config, logger, p_name, p_info)
153 # Prepare the environment
154 log_step(logger, header, "PREPARE ENV")
155 res_prepare = builder.prepare(add_env_launch=True)
156 log_res_step(logger, res_prepare)
161 log_step(logger, header, "CHECK")
162 res = builder.check(command=command)
163 log_res_step(logger, res)
167 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
168 logger.write("\r" + header + src.printcolors.printcError("KO"))
170 "==== %(KO)s in check of %(name)s \n"
171 % {"name": p_name, "KO": src.printcolors.printcInfo("ERROR")},
176 logger.write("\r%s%s" % (header, " " * len_end_line), 3)
177 logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
178 logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
180 "==== Check of %(name)s %(OK)s \n"
181 % {"name": p_name, "OK": src.printcolors.printcInfo("OK")},
185 logger.write("\n", 3, False)
191 """method that is called when salomeTools is called with --help option.
193 :return: The text to display for the check command description.
197 'The check command executes the "check" command in'
198 " the build directory of all the products of the application."
199 "\nIt is possible to reduce the list of products to check by using"
200 " the --products option\n\nexample\nsat check SALOME-master "
201 "--products KERNEL,GUI,GEOM"
205 def run(args, runner, logger):
206 """method that is called when salomeTools is called with check parameter."""
209 (options, args) = parser.parse_args(args)
211 # check that the command has been called with an application
212 src.check_config_has_application(runner.cfg)
214 # Get the list of products to treat
215 products_infos = src.product.get_products_list(options, runner.cfg, logger)
217 # Print some informations
220 "Executing the check command in the build "
221 "directories of the application %s\n"
223 % src.printcolors.printcLabel(runner.cfg.VARS.application),
228 (_("BUILD directory"), os.path.join(runner.cfg.APPLICATION.workdir, "BUILD"))
230 src.print_info(logger, info)
232 # Call the function that will loop over all the products and execute
233 # the right command(s)
234 res = check_all_products(runner.cfg, products_infos, logger)
236 # Print the final state
237 nb_products = len(products_infos)
244 _("\nCheck: %(status)s (%(valid_result)d/%(nb_products)d)\n")
246 "status": src.printcolors.printc(final_status),
247 "valid_result": nb_products - res,
248 "nb_products": nb_products,