From: Christian Van Wambeke Date: Fri, 1 Jun 2018 14:40:31 +0000 (+0200) Subject: sat compile ok but YACS X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=52e2ab50fcad53e2971d46d9113c8251c3fe88b8;p=tools%2Fsat.git sat compile ok but YACS --- diff --git a/commands/application.py b/commands/application.py index 4d3e1c9..d84285f 100644 --- a/commands/application.py +++ b/commands/application.py @@ -134,7 +134,8 @@ Note: this command will ssh to retrieve information to each machine in the l logger.info(fmt % (_("Application directory"), appli_dir)) # get catalog - catalog, catalog_src = "", "" + catalog = "" + catalog_src = "" if options.catalog: # use catalog specified in the command line catalog = options.catalog @@ -162,29 +163,15 @@ Note: this command will ssh to retrieve information to each machine in the l else: logger.info(fmt % (_("Resources Catalog"), catalog)) - details = [] - # remove previous application if os.path.exists(appli_dir): logger.info(get_step(_("Removing previous application directory"))) - rres = "" - try: - shutil.rmtree(appli_dir) - rres = "" - finally: - logger.info(rres) + shutil.rmtree(appli_dir) # generate the application - try: - try: # try/except/finally not supported in all version of python - retcode = create_application(config, appli_dir, catalog, logger) - except Exception as exc: - details.append(str(exc)) - raise - finally: - logger.info("\n") - - return RCO.ReturnCode("OK") + retcode = create_application(config, appli_dir, catalog, logger) + + return retcode def make_alias(appli_path, alias_path, force=False): @@ -261,7 +248,7 @@ def customize_app(config, appli_dir, logger): """Customizes the application by editing SalomeApp.xml.""" if 'configure' not in config.APPLICATION.virtual_app \ or len(config.APPLICATION.virtual_app.configure) == 0: - return + return RCO.ReturnCode("OK", "Nothing in configure") def get_element(parent, name, strtype): """shortcut to get an element (section or parameter) from parent.""" @@ -293,7 +280,6 @@ def customize_app(config, appli_dir, logger): document = tree.getroot() assert document is not None, "document tag not found" - logger.info("\n") for section_name in config.APPLICATION.virtual_app.configure: for parameter_name in config.APPLICATION.virtual_app.configure[section_name]: parameter_value = config.APPLICATION.virtual_app.configure[section_name][parameter_name] @@ -305,10 +291,10 @@ def customize_app(config, appli_dir, logger): parameter.attrib['value'] = parameter_value # write the file - f = open(app_file, "w") - f.write("\n") - f.write(ETREE.tostring(document, encoding='utf-8')) - f.close() + with open(app_file, "w") as f: + f.write("\n") + f.write(ETREE.tostring(document, encoding='utf-8')) + return RCO.ReturnCode("OK", "customize %s done" % app_file) def generate_application(config, appli_dir, config_file, logger): """Generates the application with the config_file.""" @@ -342,25 +328,27 @@ def get_step(logger, message, pad=50): return "%s %s " % (message, '.'*(pad - len(message.decode("UTF-8")))) def create_application(config, appli_dir, catalog, logger, display=True): - """reates a SALOME application.""" + """Creates a SALOME application.""" SALOME_modules = get_SALOME_modules(config) warn = ['KERNEL', 'GUI'] if display: for w in warn: if w not in SALOME_modules: - msg = _("module %s is required to create application\n") % w + msg = _("module %s is required to create application") % w logger.warning(msg) # generate the launch file retcode = generate_launch_file(config, appli_dir, catalog, logger, SALOME_modules) + cmd = UTS.label(os.path.join(appli_dir, "salome")) - if retcode == 0: - cmd = UTS.label("%s/salome" % appli_dir) + if not retcode.isOk(): + logger.error("Problem generating %s" % cmd) + return retcode if display: msg = _("To launch the application, type:") - logger.info("\n%s\n %s\n" % (msg, cmd)) + logger.info("\n%s\n %s" % (msg, cmd)) return retcode def get_SALOME_modules(config): @@ -377,13 +365,10 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules): Obsolescent way of creating the application. This method will use appli_gen to create the application directory. """ - retcode = -1 - if len(catalog) > 0 and not os.path.exists(catalog): raise IOError(_("Catalog not found: %s") % catalog) logger.info(get_step(_("Creating environment files"))) - status = "" VersionSalome = UTS.get_salome_version(config) if VersionSalome >= 820: @@ -394,18 +379,11 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules): app_shell="bash" env_ext="sh" - try: - import environ - # generate only shells the user wants (by default bash, csh, batch) - # the environ command will only generate file compatible - # with the current system. - environ.write_all_source_files(config, - logger, - shells=[app_shell], - silent=True) - status = "" - finally: - logger.info(status + "\n") + import environ + # generate only shells the user wants (by default bash, csh, batch) + # the environ command will only generate file compatible + # with the current system. + environ.write_all_source_files(config, logger, shells=[app_shell], silent=True) # build the application (the name depends upon salome version env_file = os.path.join(config.APPLICATION.workdir, "env_launch." + env_ext) @@ -417,19 +395,18 @@ def generate_launch_file(config, appli_dir, catalog, logger, l_SALOME_modules): os.makedirs(appli_dir) # generate the application - status = "" - try: - retcode = generate_application(config, appli_dir, cf, logger) - customize_app(config, appli_dir, logger) - status = "" - finally: - logger.info(status + "\n") - + retcode = generate_application(config, appli_dir, cf, logger) + if not retcode.isOk(): + return retcode + retcode = customize_app(config, appli_dir, logger) + if not retcode.isOk(): + return retcode + # copy the catalog if one if len(catalog) > 0: shutil.copy(catalog, os.path.join(appli_dir, "CatalogResources.xml")) - return retcode + return RCO.ReturnCode("OK", "generate_launch_file done") diff --git a/commands/generate.py b/commands/generate.py index d1aa646..47fce6b 100644 --- a/commands/generate.py +++ b/commands/generate.py @@ -139,13 +139,13 @@ class Command(_BaseCommand): def generate_component_list(config, product_info, context, logger): - res = "?" - logger.info("\n") + """returns list of ReturnCode of elementary generate_component""" + res = [] for compo in PROD.get_product_components(product_info): - header = " %s %s " % (UTS.label(compo), "." * (20 - len(compo))) - res = generate_component(config, compo, product_info, context, header, logger) - logger.info("\r%s%s\r%s" % (header, " " * 20, header)) - logger.info(res + "\n") + header = " %s ... " % UTS.label(compo) + rc = generate_component(config, compo, product_info, context, header, logger) + res.append(rc) + logger.info("%s %s" % (header, rc)) return res def generate_component(config, compo, product_info, context, header, logger): @@ -160,8 +160,7 @@ def generate_component(config, compo, product_info, context, header, logger): cpplib = "lib" + compo + "CXX.so" cpp_path = product_info.install_dir - msg = "" - msg += "%s\n" % UTS.blue(header) + msg = "%s\n" % UTS.blue(header) msg += "hxxfile = %s\n" % hxxfile msg += "cpplib = %s\n" % cpplib msg += "cpp_path = %s\n" % cpp_path @@ -202,17 +201,16 @@ def generate_component(config, compo, product_info, context, header, logger): os.chdir(generate_dir) # inline class to override bootstrap method - import module_generator + import module_generator as MG - class sat_generator(module_generator.Generator): + class sat_generator(MG.Generator): # old bootstrap for automake (used if salome version <= 7.4) - def bootstrap(self, source_dir, log_file): - # replace call to default bootstrap() by using subprocess call (cleaner) - command = "sh autogen.sh" - ier = SP.call(command, shell=True, cwd=source_dir, stdout=log_file, stderr=SP.STDOUT) - if ier != 0: - raise Exception("bootstrap has ended in error") - + def bootstrap(self, source_dir, logger): + # replace call to default bootstrap() by using subprocess Popen + cmd = "sh autogen.sh" + rc = UTS.Popen(cmd, cwd=source_dir, logger=logger) + rc.raiseIfKo() + return rc # determine salome version VersionSalome = UTS.get_salome_version(config) @@ -226,56 +224,47 @@ def generate_component(config, compo, product_info, context, header, logger): result = "GENERATE" logger.info('GENERATE') - prevstdout = sys.stdout - prevstderr = sys.stderr + if PROD.product_is_mpi(product_info): + salome_compo = MG.HXX2SALOMEParaComponent(hxxfile, cpplib, cpp_path) + else: + salome_compo = MG.HXX2SALOMEComponent(hxxfile, cpplib, cpp_path) - try: - sys.stdout = logger.logTxtFile - sys.stderr = logger.logTxtFile - - if PROD.product_is_mpi(product_info): - salome_compo = module_generator.HXX2SALOMEParaComponent(hxxfile, - cpplib, - cpp_path) - else: - salome_compo = module_generator.HXX2SALOMEComponent(hxxfile, - cpplib, - cpp_path) - - if PROD.product_has_salome_gui(product_info): - # get files to build a template GUI - gui_files = salome_compo.getGUIfilesTemplate(compo) - else: - gui_files = None - - mg = module_generator.Module(compo, components=[salome_compo], - prefix=generate_dir, gui=gui_files) - g = sat_generator(mg, context) - g.generate() - - if use_autotools: - result = "BUID_CONFIGURE" - logger.info('BUID_CONFIGURE (no bootstrap)') - g.bootstrap(compo_info.source_dir, logger.logTxtFile) - - result = RCO._OK_STATUS - finally: - sys.stdout = prevstdout - sys.stderr = prevstderr + if PROD.product_has_salome_gui(product_info): + # get files to build a template GUI + gui_files = salome_compo.getGUIfilesTemplate(compo) + else: + gui_files = None + + mg = MG.Module(compo, components=[salome_compo], prefix=generate_dir, gui=gui_files) + gg = sat_generator(mg, context) + gg.generate() + + if use_autotools: + result = "BUID_CONFIGURE" + logger.info('BUID_CONFIGURE (no bootstrap)') + result = gg.bootstrap(compo_info.source_dir, logger) + else: + result = RCO.ReturnCode("OK", "generate_component no use autotools") # go back to previous directory os.chdir(curdir) + # do the compilation using the builder object - if builder.prepare()!= 0: return "Error in prepare" + rc = builder.prepare() + if not rc.isOk(): return rc if use_autotools: - if builder.configure()!= 0: return "Error in configure" + rc = builder.configure() + if not rc.isOk(): return rc else: - if builder.cmake()!= 0: return "Error in cmake" - - if builder.make(config.VARS.nb_proc, "")!=0: return "Error in make" - if builder.install()!=0: return "Error in make install" + rc = builder.cmake() + if not rc.isOk(): return rc + rc = builder.make(config.VARS.nb_proc, "") + if not rc.isOk(): return rc + rc = builder.install() + if not rc.isOk(): return rc + # copy specified logo in generated component install directory # rem : logo is not copied in source dir because this would require # to modify the generated makefile @@ -284,8 +273,8 @@ def generate_component(config, compo, product_info, context, header, logger): destlogo = os.path.join(compo_info.install_dir, "share", "salome", "resources", compo.lower(), compo + ".png") UTS.Path(logo_path).copyfile(destlogo) - - return result + + return RCO.ReturnCode("OK", "generate_component done") def build_context(config, logger): products_list = [ 'KERNEL', 'GUI' ]