From: Christian Van Wambeke Date: Thu, 31 May 2018 14:45:53 +0000 (+0200) Subject: fix sat compile X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=89b4348949e24979163e49eab3f32c834e3cbce7;p=tools%2Fsat.git fix sat compile --- diff --git a/commands/check.py b/commands/check.py index fbd0dc0..9bfdc0d 100644 --- a/commands/check.py +++ b/commands/check.py @@ -139,8 +139,7 @@ def check_product(p_name_info, config, logger): p_name, p_info = p_name_info header = _("Check of %s") % UTS.label(p_name) - header += " %s " % ("." * (20 - len(p_name))) - logger.info(header) + UTS.init_log_step(logger,header) # Verify if the command has to be launched or not ignored = False @@ -170,7 +169,7 @@ is not defined in the definition of %(name)\n""") % p_name logger.warning(msg) if ignored or not cmd_found: - UTS.log_step(logger, header, "ignored") + UTS.log_step(logger, "ignored") logger.debug("==== %s %s\n" % (p_name, "IGNORED")) if not cmd_found: return 1 @@ -181,27 +180,14 @@ is not defined in the definition of %(name)\n""") % p_name builder = COMP.Builder(config, logger, p_info) # Prepare the environment - UTS.log_step(logger, header, "PREPARE ENV") + UTS.log_step(logger, "PREPARE ENV") res_prepare = builder.prepare() - UTS.log_res_step(logger, res_prepare) - - len_end_line = 20 + UTS.log_step(logger, res_prepare) # Launch the check - UTS.log_step(logger, header, "CHECK") + UTS.log_step(logger, "CHECK") res = builder.check(command=command) - UTS.log_res_step(logger, res) - - # Log the result - if res > 0: - logger.info("\r%s%s" % (header, " " * len_end_line)) - logger.info("\r" + header + "\n") - logger.debug("==== in check of %s\n" % p_name) - else: - logger.info("\r%s%s" % (header, " " * len_end_line)) - logger.info("\r" + header + "\n") - logger.debug("==== in check of %s\n" % p_name) - logger.info("\n") + UTS.log_step(logger, res) return res diff --git a/commands/clean.py b/commands/clean.py index 7dcd9d8..f218e1a 100644 --- a/commands/clean.py +++ b/commands/clean.py @@ -221,11 +221,14 @@ def suppress_directories(l_paths, logger): The logger instance to use for the display and logging """ for path in l_paths: - strpath = str(path) - if not path.isdir(): - msg = _("The path %s does not exists (or is not a directory)") % UTS.info(strpath) - logger.warning(msg) - else: - path.rm() - logger.info(_("Remove %s ...") % UTS.info(strpath)) + strpath = str(path) + if path.isfile(): + msg = _("The path %s is file, expected directory)") % UTS.info(strpath) + logger.warning(msg) + if not path.isdir(): + msg = _("The path %s does not exists (or is not a directory)") % UTS.info(strpath) + logger.trace(msg) + else: + path.rm() + logger.trace(_("Remove %s ") % UTS.info(strpath)) diff --git a/commands/compile.py b/commands/compile.py index 1bea3d4..d2fbbe9 100644 --- a/commands/compile.py +++ b/commands/compile.py @@ -26,12 +26,6 @@ import src.pyconf as PYCONF import src.product as PROD from src.salomeTools import _BaseCommand -# Compatibility python 2/3 for input function -# input stays input for python 3 and input = raw_input for python 2 -try: - input = raw_input -except NameError: - pass ######################################################################## # Command class @@ -106,14 +100,13 @@ class Command(_BaseCommand): # Warn the user if he invoked the clean_all option # without --products option - if (options.clean_all and - options.products is None and - not runner.options.batch): - rep = input(_("You used --clean_all without specifying a product" - " are you sure you want to continue? [Yes/No] ")) - if rep.upper() != _("YES").upper(): - return 0 - + + if (options.clean_all and options.products is None): + msg = _("You used --clean_all without specifying a product, erasing all.") + if runner.getAnswer(msg) == "NO": + return RCO.ReturnCode("OK", "user do not want to continue") + runner.setConfirmMode(False) # user agree for all next + # check that the command has been called with an application UTS.check_config_has_application(config).raiseIfKo() @@ -122,12 +115,12 @@ class Command(_BaseCommand): srcDir = os.path.join(config.APPLICATION.workdir, 'SOURCES') buildDir = os.path.join(config.APPLICATION.workdir, 'BUILD') - msg = _("Application %s, executing compile commands in build directories of products.\n") - logger.info(msg % UTS.label(nameApp)) - + msg = _("Application %s, executing compile commands in build directories of products.") % \ + UTS.label(nameApp) info = [ (_("SOURCE directory"), UTS.info(srcDir)), - (_("BUILD directory"), UTS.info(buildDir)) ] - UTS.logger_info_tuples(logger, info) + (_("BUILD directory"), UTS.info(buildDir)) ] + msg += "\n" + UTS.formatTuples(info) + logger.info(msg) # Get the list of products to treat products_infos = self.get_products_list(options, config) @@ -178,33 +171,40 @@ class Command(_BaseCommand): res = [] # list of results for each products DBG.write("compile", [p for p, tmp in products_infos]) + header = None for p_name_info in products_infos: p_name, p_info = p_name_info + if header is not None: # close previous step in for loop + UTS.end_log_step(logger, res[-1]) + # Logging - len_end_line = 30 header = _("Compilation of %s ...") % UTS.label(p_name) - logger.info(header) + UTS.init_log_step(logger, header) # Do nothing if the product is not compilable if ("properties" in p_info and \ "compilation" in p_info.properties and \ p_info.properties.compilation == "no"): - UTS.log_step(logger, header, "ignored") + UTS.log_step(logger, "ignored") res.append(RCO.ReturnCode("OK", "compile %s ignored" % p_name)) continue # Do nothing if the product is native if PROD.product_is_native(p_info): - UTS.log_step(logger, header, "native") + UTS.log_step(logger, "native") res.append(RCO.ReturnCode("OK", "no compile %s as native" % p_name)) continue # Clean the build and the install directories # if the corresponding options was called if options.clean_all: - UTS.log_step(logger, header, "CLEAN BUILD AND INSTALL") + UTS.log_step(logger, "CLEAN BUILD AND INSTALL") + # import time + # time.sleep(5) + # UTS.log_step(logger, header, "IIYOO") + # raise Exception('YOO') cmd_args = "--products %s --build --install" % p_name rc = self.executeMicroCommand("clean", nameAppli, cmd_args) if not rc.isOk(): @@ -214,7 +214,7 @@ class Command(_BaseCommand): # Clean the the install directory # if the corresponding option was called if options.clean_install and not options.clean_all: - UTS.log_step(logger, header, "CLEAN INSTALL") + UTS.log_step(logger, "CLEAN INSTALL") cmd_args = "--products %s --install" % p_name rc = self.executeMicroCommand("clean", nameAppli, cmd_args) if not rc.isOk(): @@ -227,20 +227,20 @@ class Command(_BaseCommand): # Check if it was already successfully installed if PROD.check_installation(p_info): - logger.info(_("Already installed")) + UTS.log_step(logger, _("already installed")) res.append(RCO.ReturnCode("OK", "no compile %s as already installed" % p_name)) continue # If the show option was called, do not launch the compilation if options.no_compile: - logger.info(_("No compile and install as show option")) + UTS.log_step(logger, _("No compile and install as show option")) res.append(RCO.ReturnCode("OK", "no compile %s as show option" % p_name)) continue # Check if the dependencies are installed l_depends_not_installed = check_dependencies(config, p_name_info) if len(l_depends_not_installed) > 0: - UTS.log_step(logger, header, "") + UTS.log_step(logger, "") msg = _("the following products are mandatory:\n") for prod_name in sorted(l_depends_not_installed): msg += "%s\n" % prod_name @@ -249,8 +249,6 @@ class Command(_BaseCommand): continue # Call the function to compile the product - #res_prod, len_end_line, error_step = self.compile_product(p_name_info) - #sat, p_name_info, config, options, logger, header, len_end_line) rc = self.compile_product(p_name_info) error_step, nameprod, install_dir = rc.getValue() res.append(rc) @@ -265,18 +263,18 @@ class Command(_BaseCommand): else: # Ok Clean the build directory if the compilation and tests succeed if options.clean_build_after: - UTS.log_step(logger, header, "CLEAN BUILD") + UTS.log_step(logger, "CLEAN BUILD") cmd_args = "--products %s --build" % p_name rc0 = self.executeMicroCommand("clean", nameAppli, cmd_args) - # Log the result - if rc.isOk(): - logger.info(" " + rc.getWhy()) - else: - logger.info(" " + rc.getWhy()) if not rc.isOk() and options.stop_first_fail: - break # stop at first problem + logger.warning("Stop on first fail option activated") + break # stop at first problem + + + if header is not None: # close last step in for loop + UTS.end_log_step(logger, res[-1]) resAll = RCO.ReturnCodeFromList(res) nbOk = len([r for r in res if r.isOk()]) @@ -286,23 +284,17 @@ class Command(_BaseCommand): else: return RCO.ReturnCode("KO", "Existing %s failing compile product(s)" % nbKo, nbOk) - def compile_product(self, p_name_info): #sat, p_name_info, config, options, logger, header, len_end): + def compile_product(self, p_name_info): """ Execute the proper configuration command(s) in the product build directory. :param p_name_info: (tuple) (str, Config) => (product_name, product_info) - :param config: (Config) The global configuration - :param logger: (Logger) - The logger instance to use for the display and logging - :param header: (str) the header to display when logging - :param len_end: (int) the length of the the end of line (used in display) :return: (RCO.ReturnCode) KO if it fails. """ config = self.getConfig() options = self.getOptions() logger = self.getLogger() - header = "yyyy" # TODO nameAppli = config.VARS.application p_name, p_info = p_name_info @@ -314,10 +306,9 @@ class Command(_BaseCommand): # build_sources : script -> script executions if (PROD.product_is_autotools(p_info) or PROD.product_is_cmake(p_info)): rc = self.compile_product_cmake_autotools(p_name_info) - # sat, p_name_info, config, options, logger, header, len_end) + if PROD.product_has_script(p_info): rc = self.compile_product_script(p_name_info) - # sat, p_name_info, config, options, logger, header, len_end) # Check that the install directory exists if rc.isOk() and not(os.path.exists(p_info.install_dir)): @@ -334,7 +325,7 @@ class Command(_BaseCommand): if options.check: # Do the unit tests (call the check command) - UTS.log_step(logger, header, "CHECK") + UTS.log_step(logger, "CHECK") cmd_args = "--products %s" % p_name rc0 = self.executeMicroCommand("check", nameAppli, cmd_args) if not rc0.isOk(): @@ -346,102 +337,85 @@ class Command(_BaseCommand): rc.setValue( ("COMPILE", p_name, p_info.install_dir) ) return rc - def compile_product_cmake_autotools(self, p_name_info): #sat, p_name_info, config, options, logger, header, len_end): + def compile_product_cmake_autotools(self, p_name_info): """ Execute the proper build procedure for autotools or cmake in the product build directory. :param p_name_info: (tuple) (str, Config) => (product_name, product_info) - :param config: (Config) The global configuration - :param logger: (Logger) - The logger instance to use for the display and logging - :param header: (str) the header to display when logging - :param len_end: (int) the length of the the end of line (used in display) - :return: (int) 1 if it fails, else 0. + :return: (RCO.ReturnCode) KO if it fails. """ config = self.getConfig() options = self.getOptions() logger = self.getLogger() - + + nameAppli = config.VARS.application p_name, p_info = p_name_info # Execute "sat configure", "sat make" and "sat install" - res = 0 + res = [] error_step = "" # Logging and sat command call for configure step - len_end_line = len_end - UTS.log_step(logger, header, "CONFIGURE") - res_c = sat.configure(config.VARS.application + " --products " + p_name, - verbose = 0, - logger_add_link = logger) - UTS.log_res_step(logger, res_c) - res += res_c - - if res_c > 0: - error_step = "CONFIGURE" + UTS.log_step(logger, "CONFIGURE") + cmd_args = "--products %s" % p_name + rc = self.executeMicroCommand("configure", nameAppli, cmd_args) + if not rc.isOk(): + error_step = "CONFIGURE" + msg = _("sat configure problem") + logger.error(msg) + return RCO.ReturnCode("KO", "sat configure %s problem" % p_name, (error_step, p_name, p_info.install_dir)) + + res.append(rc) + + # Logging and sat command call for make step + # Logging take account of the fact that the product has a compilation script or not + if PROD.product_has_script(p_info): + # if the product has a compilation script, + # it is executed during make step + script_path_display = UTS.label(p_info.compil_script) + UTS.log_step(logger, "SCRIPT " + script_path_display) else: - # Logging and sat command call for make step - # Logging take account of the fact that the product has a compilation - # script or not - if PROD.product_has_script(p_info): - # if the product has a compilation script, - # it is executed during make step - scrit_path_display = UTS.label( - p_info.compil_script) - UTS.log_step(logger, header, "SCRIPT " + scrit_path_display) - len_end_line = len(scrit_path_display) - else: - UTS.log_step(logger, header, "MAKE") - make_arguments = config.VARS.application + " --products " + p_name - # Get the make_flags option if there is any - if options.makeflags: - make_arguments += " --option -j" + options.makeflags - res_m = sat.make(make_arguments, - verbose = 0, - logger_add_link = logger) - UTS.log_res_step(logger, res_m) - res += res_m - - if res_m > 0: - error_step = "MAKE" - else: - # Logging and sat command call for make install step - UTS.log_step(logger, header, "MAKE INSTALL") - res_mi = sat.makeinstall(config.VARS.application + - " --products " + - p_name, - verbose = 0, - logger_add_link = logger) - - UTS.log_res_step(logger, res_mi) - res += res_mi - - if res_mi > 0: - error_step = "MAKE INSTALL" - - return res, len_end_line, error_step - - def compile_product_script(self, p_name_info): # sat, p_name_info, config, options, logger, header, len_end): + UTS.log_step(logger, "MAKE") + + cmd_args = "--products %s" % p_name + # Get the make_flags option if there is any + if options.makeflags: + cmd_args += " --option -j%s" % options.makeflags + rc = self.executeMicroCommand("make", nameAppli, cmd_args) + if not rc.isOk(): + error_step = "MAKE" + msg = _("sat make problem") + logger.error(msg) + return RCO.ReturnCode("KO", "sat make %s problem" % p_name, (error_step, p_name, p_info.install_dir)) + + res.append(rc) + + # Logging and sat command call for make install step + UTS.log_step(logger, "MAKE INSTALL") + cmd_args = "--products %s" % p_name + rc = self.executeMicroCommand("makeinstall", nameAppli, cmd_args) + if not rc.isOk(): + error_step = "MAKEINSTALL" + msg = _("sat makeinstall problem") + logger.error(msg) + return RCO.ReturnCode("KO", "sat makeinstall %s problem" % p_name, (error_step, p_name, p_info.install_dir)) + + return RCO.ReturnCode("OK", "compile cmake autotools %s done" % p_name) + + def compile_product_script(self, p_name_info): """Execute the script build procedure in the product build directory. :param p_name_info: (tuple) (str, Config) => (product_name, product_info) - :param config: (Config) The global configuration - :param logger: (Logger) - The logger instance to use for the display and logging - :param header: (str) the header to display when logging - :param len_end: (int) the length of the the end of line (used in display) - :return: (int) 1 if it fails, else 0. + :return: (RCO.ReturnCode) KO if it fails. """ config = self.getConfig() options = self.getOptions() logger = self.getLogger() nameAppli = config.VARS.application - header = "xxxx" # TODO - p_name, p_info = p_name_info # Execute "sat configure", "sat make" and "sat install" @@ -449,12 +423,12 @@ class Command(_BaseCommand): # Logging and sat command call for the script step script_path_display = UTS.label(p_info.compil_script) - UTS.log_step(logger, header, "SCRIPT %s ..." % script_path_display) + UTS.log_step(logger, "SCRIPT %s ..." % script_path_display) # res = sat.script(config.VARS.application + " --products " + p_name, verbose = 0, logger_add_link = logger) cmd_args = "--products %s" % p_name res = self.executeMicroCommand("script", nameAppli, cmd_args) - UTS.log_res_step(logger, res) + UTS.log_step(logger, res) return res diff --git a/commands/configure.py b/commands/configure.py index 2bf40d1..9a6e24f 100644 --- a/commands/configure.py +++ b/commands/configure.py @@ -17,6 +17,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import os import src.debug as DBG import src.returnCode as RCO @@ -30,8 +31,9 @@ from src.salomeTools import _BaseCommand ######################################################################## class Command(_BaseCommand): """ - The configure command executes in the build directory commands - corresponding to the compilation mode of the application products. + The configure command executes in the build directory + some commands corresponding to the compilation mode of + the application products. The possible compilation modes are 'cmake', 'autotools', or 'script'. | Here are the commands to be run: @@ -87,8 +89,7 @@ class Command(_BaseCommand): logger.info(_('Configuring the sources of the application %s\n') % UTS.label(config.VARS.application)) - info = [(_("BUILD directory"), - os.path.join(config.APPLICATION.workdir, 'BUILD'))] + info = [(_("BUILD directory"), os.path.join(config.APPLICATION.workdir, 'BUILD'))] UTS.logger_info_tuples(logger, info) # Call the function that will loop over all the products and execute @@ -141,61 +142,48 @@ def configure_product(p_name_info, conf_option, config, logger): :param config: (Config) The global configuration :param logger: (Logger) The logger instance to use for the display and logging - :return: (int) 1 if it fails, else 0. + :return: (RCO.ReturnCode) """ p_name, p_info = p_name_info # Logging header = _("Configuration of %s") % UTS.label(p_name) - header += " %s " % ("." * (20 - len(p_name))) - logger.info(header) + UTS.init_log_step(logger, header) # Do nothing if he product is not compilable if ("properties" in p_info and \ "compilation" in p_info.properties and \ p_info.properties.compilation == "no"): - - UTS.log_step(logger, header, "ignored") - logger.info("\n") - return 0 + UTS.end_log_step(logger, "ignored") + return RCO.ReturnCode("OK", "configure %s ignored" % p_name) # Instantiate the class that manages all the construction commands # like cmake, make, make install, make test, environment management, etc... builder = COMP.Builder(config, logger, p_info) # Prepare the environment - UTS.log_step(logger, header, "PREPARE ENV") + UTS.log_step(logger, "PREPARE ENV") res_prepare = builder.prepare() - UTS.log_res_step(logger, res_prepare) + UTS.log_step(logger, res_prepare) # Execute buildconfigure, configure if the product is autotools # Execute cmake if the product is cmake - res = 0 + res = [] if PROD.product_is_autotools(p_info): - UTS.log_step(logger, header, "BUILDCONFIGURE") - res_bc = builder.build_configure() - UTS.log_res_step(logger, res_bc) - res += res_bc - UTS.log_step(logger, header, "CONFIGURE") - res_c = builder.configure(conf_option) - UTS.log_res_step(logger, res_c) - res += res_c + UTS.log_step(logger, "BUILDCONFIGURE") + rc = builder.build_configure() + UTS.log_step(logger, rc) + res.append(rc) + UTS.log_step(logger, "CONFIGURE") + rc = builder.configure(conf_option) + UTS.log_step(logger, rc) + res.append(rc) if PROD.product_is_cmake(p_info): - UTS.log_step(logger, header, "CMAKE") - res_cm = builder.cmake(conf_option) - UTS.log_res_step(logger, res_cm) - res += res_cm - - # Log the result - if res > 0: - logger.info("\r%s%s" % (header, " " * 20)) - logger.info("\r" + header + "") - logger.debug("==== in configuration of %s\n" % p_name) - else: - logger.info("\r%s%s" % (header, " " * 20)) - logger.info("\r" + header + "") - logger.debug("==== in configuration of %s\n" % p_name) - logger.info("\n") - - return res + UTS.log_step(logger, "CMAKE") + rc = builder.cmake(conf_option) + UTS.log_step(logger, rc) + res.append(rc) + + UTS.end_log_step(logger, rc.getStatus()) + return RCO.ReturnCode(rc.getStatus(), "in configure %s" % p_name) diff --git a/commands/make.py b/commands/make.py index 147e990..02e3d6f 100644 --- a/commands/make.py +++ b/commands/make.py @@ -141,14 +141,13 @@ def make_product(p_name_info, make_option, config, logger): # Logging header = _("Make of %s") % UTS.label(p_name) - header += " %s " % ("." * (20 - len(p_name))) - logger.info(header) + UTS.init_log_step(logger, header) # Do nothing if he product is not compilable if ("properties" in p_info and \ "compilation" in p_info.properties and \ p_info.properties.compilation == "no"): - UTS.log_step(logger, header, "ignored") + UTS.log_step(logger, "ignored") return 0 # Instantiate the class that manages all the construction commands @@ -156,32 +155,21 @@ def make_product(p_name_info, make_option, config, logger): builder = COMP.Builder(config, logger, p_info) # Prepare the environment - UTS.log_step(logger, header, "PREPARE ENV") + UTS.log_step(logger, "PREPARE ENV") res_prepare = builder.prepare() - UTS.log_res_step(logger, res_prepare) + UTS.log_step(logger, res_prepare) # Execute buildconfigure, configure if the product is autotools # Execute cmake if the product is cmake - len_end_line = 20 nb_proc, make_opt_without_j = get_nb_proc(p_info, config, make_option) - UTS.log_step(logger, header, "MAKE -j" + str(nb_proc)) + UTS.log_step(logger, "MAKE -j" + str(nb_proc)) if ARCH.is_windows(): res = builder.wmake(nb_proc, make_opt_without_j) else: res = builder.make(nb_proc, make_opt_without_j) - UTS.log_res_step(logger, res) + UTS.log_step(logger, res) - # Log the result - if res > 0: - logger.info("\r%s%s" % (header, " " * len_end_line)) - logger.info("\r" + header + "") - logger.debug("==== in make of %s\n" % p_name) - else: - logger.info("\r%s%s" % (header, " " * len_end_line)) - logger.info("\r" + header + "") - logger.debug("==== in make of %s\n" % p_name) - logger.info("\n") return res def get_nb_proc(product_info, config, make_option): diff --git a/commands/makeinstall.py b/commands/makeinstall.py index 5404bad..2513e26 100644 --- a/commands/makeinstall.py +++ b/commands/makeinstall.py @@ -135,14 +135,13 @@ def makeinstall_product(p_name_info, config, logger): # Logging header = _("Make install of %s") % UTS.label(p_name) - header += " %s " % ("." * (20 - len(p_name))) - logger.info(header) + UTS.init_log_step(logger, header) # Do nothing if he product is not compilable if ("properties" in p_info and \ "compilation" in p_info.properties and \ p_info.properties.compilation == "no"): - UTS.log_step(logger, header, "ignored") + UTS.log_step(logger, "ignored") return RCO.ReturnCode("OK", "product %s is not compilable" % p_name) # Instantiate the class that manages all the construction commands @@ -150,28 +149,17 @@ def makeinstall_product(p_name_info, config, logger): builder = COMP.Builder(config, logger, p_info) # Prepare the environment - UTS.log_step(logger, header, "PREPARE ENV") + UTS.log_step(logger, "PREPARE ENV") res_prepare = builder.prepare() - UTS.log_res_step(logger, res_prepare) + UTS.log_step(logger, res_prepare) # Execute buildconfigure, configure if the product is autotools # Execute cmake if the product is cmake - res = 0 + res = TODO if not PROD.product_has_script(p_info): - UTS.log_step(logger, header, "MAKE INSTALL") + UTS.log_step(logger, "MAKE INSTALL") res_m = builder.install() - UTS.log_res_step(logger, res_m) + UTS.log_step(logger, res_m) res += res_m - - # Log the result - if res > 0: - logger.info("\r%s%s" % (header, " " * 20)) - logger.info("\r" + header + "") - logger.debug("==== in make install of s\n" % p_name) - else: - logger.info("\r%s%s" % (header, " " * 20)) - logger.info("\r" + header + "") - logger.debug("==== in make install of %s\n" % p_name) - logger.info("\n") return res diff --git a/commands/script.py b/commands/script.py index a1a40cd..b2d846f 100644 --- a/commands/script.py +++ b/commands/script.py @@ -84,10 +84,9 @@ class Command(_BaseCommand): # Print some informations msg = ('Executing the script in the build directories of the application %s') % \ UTS.label(config.VARS.application) - logger.info(msg) - info = [(_("BUILD directory"), os.path.join(config.APPLICATION.workdir, 'BUILD'))] - UTS.logger_info_tuples(logger, info) + msg += "\n" + UTS.formatTuples(info) + logger.trace(msg) # Call the function that will loop over all the products and execute # the right command(s) @@ -101,11 +100,11 @@ class Command(_BaseCommand): if good_result == nbExpected: status = "OK" msg = _("Execute script") - logger.info("\n%s %s: <%s>.\n" % (msg, msgCount, status)) + logger.trace("%s %s: <%s>" % (msg, msgCount, status)) else: status = "KO" msg = _("Problem executing script") - logger.info("\n%s %s: <%s>.\n" % (msg, msgCount, status)) + logger.warning("%s %s: <%s>" % (msg, msgCount, status)) return RCO.ReturnCode(status, "%s %s" % (msg, msgCount)) @@ -149,17 +148,16 @@ def run_script_of_product(p_name_info, nb_proc, config, logger): """ p_name, p_info = p_name_info - header = "zzzz" # TODO # Logging msg = _("Running script of %s ...") % UTS.label(p_name) - logger.info(msg) + logger.trace(msg) # Do nothing if he product is not compilable or has no compilation script test1 = "properties" in p_info and \ "compilation" in p_info.properties and \ p_info.properties.compilation == "no" if ( test1 or (not PROD.product_has_script(p_info)) ): - UTS.log_step(logger, header, "ignored") + UTS.log_step(logger, "ignored") return res.append(RCO.ReturnCode("OK", "run script %s ignored" % p_name)) @@ -168,16 +166,14 @@ def run_script_of_product(p_name_info, nb_proc, config, logger): builder = COMP.Builder(config, logger, p_info) # Prepare the environment - UTS.log_step(logger, header, "PREPARE ENV ...") + UTS.log_step(logger, "PREPARE ENV") res_prepare = builder.prepare() - UTS.log_res_step(logger, res_prepare) + UTS.log_step(logger, res_prepare) # Execute the script script_path_display = UTS.label(p_info.compil_script) - UTS.log_step(logger, header, "SCRIPT " + script_path_display) + UTS.log_step(logger, "SCRIPT " + script_path_display) res = builder.do_script_build(p_info.compil_script, number_of_proc=nb_proc) - UTS.log_res_step(logger, res) + UTS.log_step(logger, res) - #logger.info("") - return res diff --git a/data/templates/Application/config/compile.py b/data/templates/Application/config/compile.py index 3286f00..2f0900f 100755 --- a/data/templates/Application/config/compile.py +++ b/data/templates/Application/config/compile.py @@ -15,12 +15,12 @@ def compil(config, builder, logger): # test lrelease #.pyconf needs in ..._APPLI pre_depend : ['qt'] env = builder.build_environ.environ.environ command = "which lrelease" - res = UTS.Popen(command, shell=True ,env=env) + res = UTS.Popen(command, shell=True ,env=env, logger=logger) if not res.isOk(): return res # run lrelease command = "lrelease *.ts" cwd = str(builder.install_dir + "resources") - res = UTS.Popen(command, shell=True, cwd=cwd, env=env) + res = UTS.Popen(command, shell=True, cwd=cwd, env=env, logger=logger) return res diff --git a/src/coloringSat.py b/src/coloringSat.py index 3bf179d..cba70bb 100755 --- a/src/coloringSat.py +++ b/src/coloringSat.py @@ -166,7 +166,10 @@ def toColor(msg): # clean the message color (if the terminal is redirected by user) return replace(msg, _tagsNone) else: - return replace(msg, _tags) + # https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences + # rc + CSI 0 K as clear from cursor to the end of the line + s = msg.replace("", "\r\033[0;K") + return replace(s, _tags) def cleanColors(msg): """clean the message of color tags ' ... """ diff --git a/src/compilation.py b/src/compilation.py index b14f1af..d45b13d 100644 --- a/src/compilation.py +++ b/src/compilation.py @@ -103,6 +103,7 @@ install_dir = %s def cmake(self, options=""): """Runs cmake with the given options.""" + logger = self.logger cmake_option = options # cmake_option +=' -DCMAKE_VERBOSE_MAKEFILE=ON -DSALOME_CMAKE_DEBUG=ON' if 'cmake_options' in self.product_info: @@ -131,12 +132,13 @@ cmake %s -DCMAKE_INSTALL_PREFIX=%s %s print key, " ", self.build_environ.environ.environ[key] """ env = self.build_environ.environ.environ - res = UTS.Popen(cmd, cwd=str(self.build_dir),env=env) + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=logger) return res def build_configure(self, options=""): """Runs build_configure with the given options.""" + logger = self.logger if 'buildconfigure_options' in self.product_info: options += " %s " % self.product_info.buildconfigure_options @@ -147,12 +149,13 @@ set -x """ % (bconf, options) env = self.build_environ.environ.environ - res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env) + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=logger) return res def configure(self, options=""): """Runs configure with the given options.""" + logger = self.logger if 'configure_options' in self.product_info: options += " %s " % self.product_info.configure_options @@ -163,10 +166,11 @@ set -x """ % (conf, self.install_dir, options) env = self.build_environ.environ.environ - res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env) + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=logger) return res def hack_libtool(self): + logger = self.logger libtool = os.path.join(str(self.build_dir), "libtool") if not os.path.exists(libtool): return RCO.ReturnCode("OK", "file libtool not existing '%s'" % libtool) @@ -206,25 +210,27 @@ CC=\"hack_libtool\"%g" libtool ''' env = self.build_environ.environ.environ - res = UTS.Popen(hack_cmd, cwd=str(self.build_dir), env=env) + res = UTS.Popen(hack_cmd, cwd=str(self.build_dir), env=env, logger=logger) return res def make(self, nb_proc, make_opt=""): """Runs make to build the module.""" # make + logger = self.logger cmd = """ set -x make -j %s %s """ % (nb_proc, make_opt) env = self.build_environ.environ.environ - res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=self.logger) + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=logger) return res def wmake(self, nb_proc, opt_nb_proc = None): """Runs msbuild to build the module.""" + logger = self.logger hh = 'MSBUILD /m:%s' % str(nb_proc) if self.debug_mode: hh += " " + UTS.red("DEBUG") @@ -237,12 +243,13 @@ make -j %s %s cmd += cmd + " ALL_BUILD.vcxproj" env = self.build_environ.environ.environ - res = UTS.Popen(command, cwd=str(self.build_dir), env=env, logger=self.logger) + res = UTS.Popen(command, cwd=str(self.build_dir), env=env, logger=logger) return res def install(self): """Runs 'make install'.""" + logger = self.logger if self.config.VARS.dist_name=="Win": cmd = "msbuild INSTALL.vcxproj" if self.debug_mode: @@ -253,11 +260,12 @@ make -j %s %s cmd = 'make install' env = self.build_environ.environ.environ - res = UTS.Popen(command, cwd=str(self.build_dir), env=env, logger=self.logger) + res = UTS.Popen(command, cwd=str(self.build_dir), env=env, logger=logger) return res def check(self, command=""): """Runs 'make_check'.""" + logger = self.logger if ARCH.is_windows(): cmd = "msbuild RUN_TESTS.vcxproj" else : @@ -270,7 +278,7 @@ make -j %s %s cmd = command env = self.build_environ.environ.environ - res = UTS.Popen(command, cwd=str(self.build_dir), env=env , logger=self.logger) + res = UTS.Popen(command, cwd=str(self.build_dir), env=env , logger=logger) return res @@ -370,13 +378,13 @@ make -j %s %s self.build_environ.set("VERSION", self.product_info.version) def do_batch_script_build(self, script, nb_proc): - + logger = self.logger if ARCH.is_windows(): make_options = "/maxcpucount:%s" % nb_proc else : make_options = "-j%s" % nb_proc - self.logger.trace(_("Run build script '%s'") % script) + self.logger.trace(_("Run build script %s") % UTS.label(script)) self.complete_environment(make_options) # linux or win compatible, have to be chmod +x ? @@ -386,7 +394,7 @@ make -j %s %s """ % script env = self.build_environ.environ.environ - res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env) + res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=logger) return res def do_script_build(self, script, number_of_proc=0): diff --git a/src/salomeTools.py b/src/salomeTools.py index 6695397..4a1f530 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -28,6 +28,13 @@ This file is the main API file for salomeTools _KOSYS = 1 # avoid import src +# Compatibility python 2/3 for input function +# input stays input for python 3 and input = raw_input for python 2 +try: + input = raw_input +except NameError: + pass + ######################################################################## # NO __main__ entry allowed, use sat ######################################################################## @@ -113,7 +120,7 @@ def launchSat(command): env["PATH"] = rootdir + ":" + env["PATH"] # TODO setLocale not 'fr' on subprocesses, why not? # env["LANG"] == '' - res = UTS.Popen(command, env=env) + res = UTS.Popen(command, env=env, logger=None) # no logger! return res def setNotLocale(): @@ -463,6 +470,7 @@ class Sat(object): self.nameAppliLoaded = None self.parser = self._getParser() + self._confirmMode = True def __repr__(self): aDict = { @@ -692,27 +700,33 @@ development mode (more verbose error/exception messages) return msg def getConfirmMode(self): - return False + return self._confirmMode + + def setConfirmMode(self, value): + self._confirmMode = value def getBatchMode(self): - return True + return self.options.batch def getAnswer(self, msg): """ - question and user answer (in console) if confirm mode and not batch mode - returns 'YES' or 'NO' if confirm mode and not batch mode - returns 'YES' if batch mode + question and user answer (in console) + if confirm mode and not batch mode. + + | returns 'YES' or 'NO' if confirm mode and not batch mode + | returns 'YES' if batch mode """ + logger = self.getLogger() if self.getConfirmMode() and not self.getBatchMode(): - self.getLogger().info(msg) - rep = input(_("Are you sure you want to continue? [yes/no]")) + logger.info("\n" + msg) + rep = input(_("Do you want to continue? [yes/no] ")) if rep.upper() == _("YES"): return "YES" else: return "NO" else: - self.getLogger().info(msg) - self.getLogger().info("YES (as automatic answer)") + logger.debug(msg) # silent message + logger.debug("YES (as automatic answer)") return "YES" diff --git a/src/utilsSat.py b/src/utilsSat.py index f1308fc..a43939c 100644 --- a/src/utilsSat.py +++ b/src/utilsSat.py @@ -436,15 +436,36 @@ def logger_info_tuples(logger, tuples): msg = formatTuples(tuples) logger.info(msg) -def log_step(logger, header, step): - #logger.info("\r%s%s" % (header, step)) - logger.info("%s" % step) - -def log_res_step(logger, res): - if res.isOk(): - logger.info("") +_log_step_header = ["No log step header ..."] + +def init_log_step(logger, header, step=""): + _log_step_header.append(header) + log_step(logger, step) + +def log_step(logger, step): + header = _log_step_header[-1] + if type(step) == str: + logger.info("%s%s ..." % (header, step)) + return + #as ReturnCode type step + if step.isOk(): + logger.info("%s ..." % header) + else: + logger.info("%s%s ..." % (header, step.getwhy())) + +def end_log_step(logger, step): + header = _log_step_header[-1] + if type(step) == str: + logger.info("%s%s" % (header, step)) + if len(_log_step_header) > 1: _log_step_header.pop() + return + #as ReturnCode type + if step.isOk(): + logger.info("%s " % header) else: - logger.info("") + logger.info("%s <%s>" % (header, step.getStatus())) + if len(_log_step_header) > 1: _log_step_header.pop() + def isSilent(output_verbose_level): """is silent fort self.build_environ""" @@ -742,16 +763,16 @@ def Popen(command, shell=True, cwd=None, env=None, stdout=SP.PIPE, stderr=SP.PIP if logger is not None: logger.trace(" launch command rc=%s cwd=%s:\n%s" % (rc, cwd, command)) logger.trace(" result command stdout&stderr:\n%s" % res_out) - return RCO.ReturnCode("OK", "command done", value=res_out) + return RCO.ReturnCode("OK", "Popen command done", value=res_out) else: if logger is not None: logger.warning(" launch command rc=%s cwd=%s:\n%s" % (rc, cwd, command)) logger.warning(" result command stdout&stderr:\n%s" % res_out) - return RCO.ReturnCode("KO", "command problem", value=res_out) + return RCO.ReturnCode("KO", "Popen command problem", value=res_out) else: #except Exception as e: logger.error(" launch command cwd=%s:\n%s" % (cwd, command)) logger.error("launch command exception:\n%s" % e) - return RCO.ReturnCode("KO", "launch command problem") + return RCO.ReturnCode("KO", "Popen command problem") def generate_catalog(machines, config, logger): @@ -783,7 +804,7 @@ def generate_catalog(machines, config, logger): logger.info(" ssh %s " % (k + " ").ljust(20, '.'), 4) ssh_cmd = 'ssh -o "StrictHostKeyChecking no" %s %s' % (k, cmd) - res = UTS.Popen(ssh_cmd, shell=True) + res = UTS.Popen(ssh_cmd, shell=True, logger=logger) if res.isOk(): lines = p.stdout.readlines() freq = lines[0][:-1].split(':')[-1].split('.')[0].strip() diff --git a/src/xsl/command.xsl b/src/xsl/command.xsl index efe2465..9646151 100644 --- a/src/xsl/command.xsl +++ b/src/xsl/command.xsl @@ -109,8 +109,8 @@ - - + +