--- /dev/null
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+# Copyright (C) 2010-2012 CEA/DEN
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# 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
+
+# Define all possible option for configure command : sat configure <options>
+parser = src.options.Options()
+parser.add_option('p', 'products', 'list2', 'products',
+ _('products to configure. This option can be'
+ ' passed several time to configure several products.'))
+parser.add_option('o', 'option', 'string', 'option',
+ _('Option to add to the configure or cmake command.'), "")
+
+def get_products_list(options, cfg, logger):
+ '''method that gives the product list with their informations from
+ configuration regarding the passed options.
+
+ :param options Options: The Options instance that stores the commands
+ arguments
+ :param cfg Config: The global configuration
+ :param logger Logger: The logger instance to use for the display and logging
+ :return: The list of (product name, product_informations).
+ :rtype: List
+ '''
+ # Get the products to be prepared, regarding the options
+ if options.products is None:
+ # No options, get all products sources
+ products = cfg.APPLICATION.products
+ else:
+ # if option --products, check that all products of the command line
+ # are present in the application.
+ products = options.products
+ for p in products:
+ if p not in cfg.APPLICATION.products:
+ raise src.SatException(_("Product %(product)s "
+ "not defined in application %(application)s") %
+ { 'product': p, 'application': cfg.VARS.application} )
+
+ # Construct the list of tuple containing
+ # the products name and their definition
+ products_infos = src.product.get_products_infos(products, cfg)
+
+ products_infos = [pi for pi in products_infos if not(src.product.product_is_native(pi[1]) or src.product.product_is_fixed(pi[1]))]
+
+ return products_infos
+
+def log_step(logger, header, step):
+ logger.write("\r%s%s" % (header, " " * 20), 3)
+ logger.write("\r%s%s" % (header, step), 3)
+ logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4)
+ logger.flush()
+
+def log_res_step(logger, res):
+ if res == 0:
+ logger.write("%s \n" % src.printcolors.printcSuccess("OK"), 4)
+ logger.flush()
+ else:
+ logger.write("%s \n" % src.printcolors.printcError("KO"), 4)
+ logger.flush()
+
+def configure_all_products(config, products_infos, conf_option, logger):
+ '''Execute the proper configuration commands
+ in each product build directory.
+
+ :param config Config: The global configuration
+ :param products_info list: List of
+ (str, Config) => (product_name, product_info)
+ :param conf_option str: The options to add to the command
+ :param logger Logger: The logger instance to use for the display and logging
+ :return: the number of failing commands.
+ :rtype: int
+ '''
+ res = 0
+ for p_name_info in products_infos:
+ res_prod = configure_product(p_name_info, conf_option, config, logger)
+ if res_prod != 0:
+ res += 1
+ return res
+
+def configure_product(p_name_info, conf_option, config, logger):
+ '''Execute the proper configuration command(s)
+ in the product build directory.
+
+ :param p_name_info tuple: (str, Config) => (product_name, product_info)
+ :param conf_option str: The options to add to the command
+ :param config Config: The global configuration
+ :param logger Logger: The logger instance to use for the display
+ and logging
+ :return: 1 if it fails, else 0.
+ :rtype: int
+ '''
+
+ p_name, p_info = p_name_info
+
+ # Logging
+ logger.write("\n", 4, False)
+ logger.write("################ ", 4)
+ header = _("Configuration of %s") % src.printcolors.printcLabel(p_name)
+ header += " %s " % ("." * (20 - len(p_name)))
+ logger.write(header, 3)
+ logger.write("\n", 4, False)
+ logger.flush()
+
+ # Instantiate the class that manages all the construction commands
+ # like cmake, make, make install, make test, environment management, etc...
+ builder = src.compilation.Builder(config, logger, p_info)
+
+ # Prepare the environment
+ log_step(logger, header, "PREPARE ENV")
+ res_prepare = builder.prepare()
+ log_res_step(logger, res_prepare)
+
+ # Execute buildconfigure, configure if the product is autotools
+ # Execute cmake if the product is cmake
+ res = 0
+ if src.product.product_is_autotools(p_info):
+ log_step(logger, header, "BUILDCONFIGURE")
+ res_bc = builder.build_configure()
+ log_res_step(logger, res_bc)
+ res += res_bc
+ log_step(logger, header, "CONFIGURE")
+ res_c = builder.configure(conf_option)
+ log_res_step(logger, res_c)
+ res += res_c
+ if src.product.product_is_cmake(p_info):
+ log_step(logger, header, "CMAKE")
+ res_cm = builder.cmake(conf_option)
+ log_res_step(logger, res_cm)
+ res += res_cm
+
+ # Log the result
+ if res > 0:
+ logger.write("\r%s%s" % (header, " " * 20), 3)
+ logger.write("\r" + header + src.printcolors.printcError("KO"))
+ logger.write("==== %(KO)s in configuration of %(name)s \n" %
+ { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4)
+ logger.flush()
+ else:
+ logger.write("\r%s%s" % (header, " " * 20), 3)
+ logger.write("\r" + header + src.printcolors.printcSuccess("OK"))
+ logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4)
+ logger.write("==== Configuration of %(name)s %(OK)s \n" %
+ { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4)
+ logger.flush()
+ logger.write("\n", 3, False)
+
+ return res
+
+def description():
+ '''method that is called when salomeTools is called with --help option.
+
+ :return: The text to display for the configure command description.
+ :rtype: str
+ '''
+ return _("The configure command executes in the build directory"
+ " the configure commands corresponding to the compilation mode"
+ " of the application products.\nThe possible compilation modes"
+ " are \"cmake\", \"autotools\", or a script.\n\nHere are the "
+ "commands to be run :\nautotools: build_configure and configure\n"
+ "cmake: cmake\nscript: N\A")
+
+def run(args, runner, logger):
+ '''method that is called when salomeTools is called with prepare parameter.
+ '''
+
+ # Parse the options
+ (options, args) = parser.parse_args(args)
+
+ # check that the command has been called with an application
+ src.check_config_has_application( runner.cfg )
+
+ # Get the list of products to threat
+ products_infos = get_products_list(options, runner.cfg, logger)
+
+ # Print some informations
+ logger.write(_('Configuring the sources of the application %s\n') %
+ src.printcolors.printcLabel(runner.cfg.VARS.application), 1)
+
+ info = [(_("BUILD directory"),
+ os.path.join(runner.cfg.APPLICATION.workdir, 'BUILD'))]
+ src.print_info(logger, info)
+
+ # Call the function that will loop over all the products and execute
+ # the right command(s)
+ res = configure_all_products(runner.cfg, products_infos, options.option, logger)
+
+ # Print the final state
+ nb_products = len(products_infos)
+ if res == 0:
+ final_status = "OK"
+ else:
+ final_status = "KO"
+
+ logger.write(_("\nConfiguration: %(status)s (%(valid_result)d/%(nb_products)d)\n") % \
+ { 'status': src.printcolors.printc(final_status),
+ 'valid_result': nb_products - res,
+ 'nb_products': nb_products }, 1)
+
+ return res
\ No newline at end of file
"LIBS",
"LDFLAGS"]
-class CompilationResult:
- def __init__(self):
- self.prepare = False
- self.buildconfigure = False
- self.configure = False
- self.cmake = False
- self.make = False
- self.install = False
- self.check = False
- self.check_tried = False
- self.ignored = False
- self.reason = ""
-
- def isOK(self):
- if self.ignored:
- return False
-
- return self.prepare \
- and self.buildconfigure \
- and self.configure \
- and self.cmake \
- and self.make \
- and self.install \
- and self.check
-
- def setAllFail(self):
- self.prepare = False
- self.buildconfigure = False
- self.configure = False
- self.cmake = False
- self.make = False
- self.install = False
- self.check = False
-
- def setIgnored(self, reason=None):
- self.ignored = True
- if reason:
- self.reason = reason
- else:
- self.reason = _("ignored")
-
- def getErrorText(self):
- if self.ignored or len(self.reason):
- return self.reason
-
- if not self.prepare: return "PREPARE BUILD"
- if not self.buildconfigure: return "BUILD CONFIGURE"
- if not self.configure: return "CONFIGURE"
- if not self.cmake: return "CMAKE"
- if not self.make: return "MAKE"
- if not self.install: return "INSTALL"
- if not self.check: return "CHECK"
-
- return ""
-
class Builder:
"""Class to handle all construction steps, like cmake, configure, make, ...
"""
- def __init__(self, config, logger, options, product_info, debug_mode=False, check_src=True):
+ def __init__(self, config, logger, product_info, options = src.options.OptResult(), debug_mode=False, check_src=True):
self.config = config
self.logger = logger
self.options = options
if 'install_dir' in dep_info and not os.path.exists(dep_info.install_dir):
raise src.SatException(_("Module %s is required") % dep)
"""
- self.results = CompilationResult()
##
# Shortcut method to log in both log files.
def log(self, text, level, showInfo=True):
self.logger.write(text, level, showInfo)
self.logger.logTxtFile.write(src.printcolors.cleancolor(text))
+ self.logger.flush()
##
# Shortcut method to log a command.
def log_command(self, command):
self.log("> %s\n" % command, 5)
- def log_result(self, res):
- if res == 0:
- self.logger.write("%s\n" % src.printcolors.printc(src.OK_STATUS), 5)
- else:
- self.logger.write("%s, code = %s\n" % (src.printcolors.printc(src.KO_STATUS), res), 5)
-
- ##
- # Logs a compilation step (configure, make ...)
- def log_step(self, step):
- if self.config.USER.output_verbose_level == 3:
- self.logger.write("\r%s%s" % (self.header, " " * 20), 3)
- self.logger.write("\r%s%s" % (self.header, step), 3)
- self.log("==== %s \n" % src.printcolors.printcInfo(step), 4)
- self.logger.flush()
-
- ##
- # Prepares the environment for windows.
- # Build two environment: one for building and one for testing (launch).
- def wprepare(self):
- self.log_step('PREPARE BUILD')
-
- if not self.build_dir.exists():
- # create build dir
- self.build_dir.make()
- elif self.options.clean_all:
- self.log(' %s\n' % src.printcolors.printcWarning("CLEAN ALL"), 4)
- # clean build dir if clean_all option given
- self.log(' clean previous build = %s\n' % str(self.build_dir), 4)
- self.build_dir.rm()
- self.build_dir.make()
-
- if self.options.clean_all or self.options.clean_install:
- if os.path.exists(str(self.install_dir)) and not self.single_dir:
- self.log(' clean previous install = %s\n' % str(self.install_dir), 4)
- self.install_dir.rm()
-
- self.log(' build_dir = %s\n' % str(self.build_dir), 4)
- self.log(' install_dir = %s\n' % str(self.install_dir), 4)
- self.log('\n', 4)
-
- environ_info = {}
-
- # add products in depend and opt_depend list recursively
- environ_info['products'] = src.product.get_product_dependencies(self.config, self.product_info)
-
- # create build environment
- self.build_environ = src.environment.SalomeEnviron(self.config, src.environment.Environ(dict(os.environ)), True)
- self.build_environ.silent = (self.config.USER.output_verbose_level < 5)
- self.build_environ.set_full_environ(self.logger, environ_info)
-
- # create runtime environment
- self.launch_environ = src.environment.SalomeEnviron(self.config, src.environment.Environ(dict(os.environ)), False)
- self.launch_environ.silent = True # no need to show here
- self.launch_environ.set_full_environ(self.logger, environ_info)
-
- for ee in C_COMPILE_ENV_LIST:
- vv = self.build_environ.get(ee)
- if len(vv) > 0:
- self.log(" %s = %s\n" % (ee, vv), 4, False)
-
- self.results.prepare = True
- self.log_result(0)
- return self.results.prepare
-
##
# Prepares the environment.
# Build two environment: one for building and one for testing (launch).
def prepare(self):
- self.log_step('PREPARE BUILD')
if not self.build_dir.exists():
# create build dir
if len(vv) > 0:
self.log(" %s = %s\n" % (ee, vv), 4, False)
- self.results.prepare = True
- self.log_result(0)
- return self.results.prepare
+ return 0
##
# Runs cmake with the given options.
def cmake(self, options=""):
- self.log_step('CMAKE')
-
- # cmake so no (build)configure
- self.results.configure = True
cmake_option = options
- cmake_option +=' -DCMAKE_VERBOSE_MAKEFILE=ON -DSALOME_CMAKE_DEBUG=ON'
+ # cmake_option +=' -DCMAKE_VERBOSE_MAKEFILE=ON -DSALOME_CMAKE_DEBUG=ON'
if 'cmake_options' in self.product_info:
cmake_option += " %s " % " ".join(self.product_info.cmake_options.split())
cmake_option += " -DCMAKE_BUILD_TYPE=Debug"
else :
cmake_option += " -DCMAKE_BUILD_TYPE=Release"
-
- # In case CMAKE_GENERATOR is defined in environment, use it in spite of automatically detect it
- if 'cmake_generator' in self.config.APPLICATION:
- cmake_option += ' -DCMAKE_GENERATOR=%s' % self.config.PRODUCT.cmake_generator
- command = "cmake %s -DCMAKE_INSTALL_PREFIX=%s %s" %(cmake_option, self.install_dir, self.source_dir)
+ command = ("cmake %s -DCMAKE_INSTALL_PREFIX=%s %s" %
+ (cmake_option, self.install_dir, self.source_dir))
self.log_command(command)
res = subprocess.call(command,
stdout=self.logger.logTxtFile,
stderr=subprocess.STDOUT)
- self.results.cmake = (res == 0)
- self.log_result(res)
- return self.results.cmake
+ if res == 0:
+ return res
+ else:
+ return 1
##
# Runs build_configure with the given options.
def build_configure(self, options=""):
- skip = src.get_cfg_param(self.product_info, "build_configure", False)
- if skip:
- self.results.buildconfigure = True
- res = 0
- else:
- self.log_step('BUILD CONFIGURE')
-
- self.results.buildconfigure = False
- if 'buildconfigure_options' in self.product_info:
- options += " %s " % self.product_info.buildconfigure_options
+ if 'buildconfigure_options' in self.product_info:
+ options += " %s " % self.product_info.buildconfigure_options
- command = str('./build_configure')
- command = command + " " + options
- self.log_command(command)
+ command = str('%s/build_configure') % (self.source_dir)
+ command = command + " " + options
+ self.log_command(command)
- res = subprocess.call(command,
- shell=True,
- cwd=str(self.source_dir),
- env=self.build_environ.environ.environ,
- stdout=self.logger.logTxtFile,
- stderr=subprocess.STDOUT)
- self.results.buildconfigure = (res == 0)
+ res = subprocess.call(command,
+ shell=True,
+ cwd=str(self.build_dir),
+ env=self.build_environ.environ.environ,
+ stdout=self.logger.logTxtFile,
+ stderr=subprocess.STDOUT)
- self.log_result(res)
- return self.results.buildconfigure
+ if res == 0:
+ return res
+ else:
+ return 1
##
# Runs configure with the given options.
def configure(self, options=""):
- self.log_step('CONFIGURE')
-
- # configure so no cmake
- self.results.cmake = True
if 'configure_options' in self.product_info:
options += " %s " % self.product_info.configure_options
stdout=self.logger.logTxtFile,
stderr=subprocess.STDOUT)
- self.log_result(res)
- self.results.configure = (res == 0)
- return self.results.configure
+ if res == 0:
+ return res
+ else:
+ return 1
def hack_libtool(self):
if not os.path.exists(str(self.build_dir + 'libtool')):
stdout=self.logger.logTxtFile,
stderr=subprocess.STDOUT)
- self.results.make = (res == 0)
- self.log_result(res)
- return self.results.make
+ if res == 0:
+ return res
+ else:
+ return 1
##
# Runs msbuild to build the module.
stdout=self.logger.logTxtFile,
stderr=subprocess.STDOUT)
- self.results.make = (res == 0)
- self.log_result(res)
- return self.results.make
+ if res == 0:
+ return res
+ else:
+ return 1
##
# Runs 'make install'.
def install(self):
- self.log_step('INSTALL')
if self.config.VARS.dist_name=="Win":
command = 'msbuild INSTALL.vcxproj'
if self.debug_mode:
stdout=self.logger.logTxtFile,
stderr=subprocess.STDOUT)
- self.results.install = (res == 0)
- self.log_result(res)
- return self.results.install
+ if res == 0:
+ return res
+ else:
+ return 1
##
# Runs 'make_check'.
def check(self):
- self.log_step('CHECK')
if src.architecture.is_windows():
command = 'msbuild RUN_TESTS.vcxproj'
else :
self.log_command(command)
- self.results.check_tried = True
res = subprocess.call(command,
shell=True,
cwd=str(self.build_dir),
stdout=self.logger.logTxtFile,
stderr=subprocess.STDOUT)
- self.results.check = (res == 0)
- self.log_result(res)
- return self.results.check
+ if res == 0:
+ return res
+ else:
+ return 1
##
# Performs a default build for this module.
if not self.configure(configure_options): return self.get_result()
if not self.make(): return self.get_result()
if not self.install(): return self.get_result()
- self.results.check = True
if not self.clean(): return self.get_result()
else: # CMake
if self.config.VARS.dist_name=='Win':
if not self.wprepare(): return self.get_result()
- self.results.buildconfigure = True
if not self.cmake(): return self.get_result()
- self.results.ctest = True
if not self.wmake(): return self.get_result()
if not self.install(): return self.get_result()
- self.results.check = True
if not self.clean(): return self.get_result()
else :
if not self.prepare(): return self.get_result()
- self.results.buildconfigure = True
if not self.cmake(): return self.get_result()
- self.results.ctest = True
if not self.make(): return self.get_result()
if not self.install(): return self.get_result()
- self.results.check = True
if not self.clean(): return self.get_result()
return self.get_result()
##
# Performs a build with a script.
def do_script_build(self, script):
- retcode = CompilationResult()
- retcode.setAllFail()
# script found
self.logger.write(_("Compile %(module)s using script %(script)s\n") % \
{ 'module': self.module, 'script': src.printcolors.printcLabel(script) }, 4)
return retcode
- ##
- # Builds the module.
- # If a script is specified used it, else use 'default' method.
- def run_compile(self, no_compile=False):
- retcode = CompilationResult()
- retcode.setAllFail()
-
- if no_compile:
- if os.path.exists(str(self.install_dir)):
- retcode.setIgnored(_("already installed"))
- else:
- retcode.setIgnored(src.printcolors.printcError(_("NOT INSTALLED")))
-
- self.log_file.close()
- os.remove(os.path.realpath(self.log_file.name))
- return retcode
-
- # check if the module is already installed
- if not self.single_dir and os.path.exists(str(self.install_dir)) \
- and not self.options.clean_all and not self.options.clean_install:
-
- retcode.setIgnored(_("already installed"))
- self.log_file.close()
- os.remove(os.path.realpath(self.log_file.name))
- return retcode
-
- if 'compile_method' in self.product_info:
- if self.product_info.compile_method == "copy":
- self.prepare()
- retcode.prepare = self.results.prepare
- retcode.buildconfigure = True
- retcode.configure = True
- retcode.make = True
- retcode.cmake = True
- retcode.ctest = True
-
- if not self.source_dir.smartcopy(self.install_dir):
- raise src.SatException(_("Error when copying %s sources to install dir") % self.module)
- retcode.install = True
- retcode.check = True
-
- elif self.product_info.compile_method == "default":
- retcode = self.do_default_build(show_warning=False)
-
-
- elif os.path.isfile(self.product_info.compile_method):
- retcode = self.do_script_build(self.product_info.compile_method)
-
- else:
- raise src.SatException(_("Unknown compile_method: %s") % self.product_info.compile_method)
-
- else:
- script = os.path.join(self.config.VARS.dataDir, 'compil_scripts', 'modules', self.module + '.py')
-
- if not os.path.exists(script):
- # no script use default method
- retcode = self.do_default_build(show_warning=False)
- else:
- retcode = self.do_script_build(script)
-
- return retcode