def run(self, cmd_arguments):
"""method called for command 'sat compile <options>'"""
argList = self.assumeAsList(cmd_arguments)
-
- # print general help and returns
- if len(argList) == 0:
- self.print_help()
- return RCO.ReturnCode("OK", "No arguments, as 'sat %s --help'" % self.name)
self._options, remaindersArgs = self.parseArguments(argList)
# Call the function that will loop over all the products and execute
# the right command(s)
- res = compile_all_products(runner, config, options, products_infos, logger)
+ res = self.compile_all_products(products_infos)
# Print the final state
nb_products = len(products_infos)
logger.info(_("\nCompilation: <%(0)s> (%(1)d/%(2)d)\n") % \
{ '0': res.getStatus(),
- '1': nb_products - nb_ok,
+ '1': nb_ok,
'2': nb_products } )
-
return res
-def get_children(config, p_name_p_info):
- l_res = []
- p_name, __ = p_name_p_info
- # Get all products of the application
- products = config.APPLICATION.products
- products_infos = PROD.get_products_infos(products, config)
- for p_name_potential_child, p_info_potential_child in products_infos:
- if ("depend" in p_info_potential_child and \
- p_name in p_info_potential_child.depend):
- l_res.append(p_name_potential_child)
- return l_res
-
-def get_recursive_children(config, p_name_p_info, without_native_fixed=False):
- """
- Get the recursive list of the product that depend on
- the product defined by prod_info
-
- :param config: (Config) The global configuration
- :param prod_info: (Config) The specific config of the product
- :param without_native_fixed: (bool)
- If true, do not include the fixed or native products in the result
- :return: (list) The list of product_informations.
- """
- p_name, __ = p_name_p_info
- # Initialization of the resulting list
- l_children = []
-
- # Get the direct children (not recursive)
- l_direct_children = get_children(config, p_name_p_info)
- # Minimal case : no child
- if l_direct_children == []:
- return []
- # Add the children and call the function to get the children of the
- # children
- for child_name in l_direct_children:
- l_children_name = [pn_pi[0] for pn_pi in l_children]
- if child_name not in l_children_name:
- if child_name not in config.APPLICATION.products:
- msg = _("""\
-The product %(child_name)s that is in %(product_name)s children
-is not present in application %(appli_name)s.""" %
- {"child_name" : child_name,
- "product_name" : p_name.name,
- "appli_name" : config.VARS.application} )
- raise Exception(msg)
- prod_info_child = PROD.get_product_config(config, child_name)
- pname_pinfo_child = (prod_info_child.name, prod_info_child)
- # Do not append the child if it is native or fixed and
- # the corresponding parameter is called
- if without_native_fixed:
- if not(PROD.product_is_native(prod_info_child) or \
- PROD.product_is_fixed(prod_info_child)):
- l_children.append(pname_pinfo_child)
- else:
- l_children.append(pname_pinfo_child)
- # Get the children of the children
- l_grand_children = get_recursive_children(config,
- pname_pinfo_child,
- without_native_fixed = without_native_fixed)
- l_children += l_grand_children
- return l_children
-def get_recursive_fathers(config, p_name_p_info, without_native_fixed=False):
- """
- Get the recursive list of the dependencies of the product defined
- by prod_info
-
- :param config: (Config) The global configuration
- :param prod_info: (Config) The specific config of the product
- :param without_native_fixed: (bool)
- If true, do not include the fixed or native products in the result
- :return: (list) The list of product_informations.
- """
- p_name, p_info = p_name_p_info
- # Initialization of the resulting list
- l_fathers = []
- # Minimal case : no dependencies
- if "depend" not in p_info or p_info.depend == []:
- return []
- # Add the dependencies and call the function to get the dependencies of the
- # dependencies
- for father_name in p_info.depend:
- l_fathers_name = [pn_pi[0] for pn_pi in l_fathers]
- if father_name not in l_fathers_name:
- if father_name not in config.APPLICATION.products:
- msg = _("The product %(father_name)s that is in %(product_nam"
- "e)s dependencies is not present in application %(appli_name)s" % \
- {"father_name" : father_name,
- "product_name" : p_name,
- "appli_name" : config.VARS.application})
- raise Exception(msg)
- prod_info_father = PROD.get_product_config(config, father_name)
- pname_pinfo_father = (prod_info_father.name, prod_info_father)
- # Do not append the father if it is native or fixed and
- # the corresponding parameter is called
- if without_native_fixed:
- if not(PROD.product_is_native(prod_info_father) or \
- PROD.product_is_fixed(prod_info_father)):
- l_fathers.append(pname_pinfo_father)
- else:
- l_fathers.append(pname_pinfo_father)
- # Get the dependencies of the dependency
- l_grand_fathers = get_recursive_fathers(config,
- pname_pinfo_father,
- without_native_fixed = without_native_fixed)
- for item in l_grand_fathers:
- if item not in l_fathers:
- l_fathers.append(item)
- return l_fathers
-
-def sort_products(config, p_infos):
- """Sort the p_infos regarding the dependencies between the products
-
- :param config: (Config) The global configuration
- :param p_infos: (list)
- List of (str, Config) => (product_name, product_info)
- """
- l_prod_sorted = UTS.deepcopy_list(p_infos)
- for prod in p_infos:
- l_fathers = get_recursive_fathers(config,
- prod,
- without_native_fixed=True)
- l_fathers = [father for father in l_fathers if father in p_infos]
- if l_fathers == []:
- continue
- for p_sorted in l_prod_sorted:
- if p_sorted in l_fathers:
- l_fathers.remove(p_sorted)
- if l_fathers==[]:
- l_prod_sorted.remove(prod)
- l_prod_sorted.insert(l_prod_sorted.index(p_sorted)+1, prod)
- break
-
- return l_prod_sorted
-
-def extend_with_fathers(config, p_infos):
- p_infos_res = UTS.deepcopy_list(p_infos)
- for p_name_p_info in p_infos:
- fathers = get_recursive_fathers(config,
- p_name_p_info,
- without_native_fixed=True)
- for p_name_p_info_father in fathers:
- if p_name_p_info_father not in p_infos_res:
- p_infos_res.append(p_name_p_info_father)
- return p_infos_res
-
-def extend_with_children(config, p_infos):
- p_infos_res = UTS.deepcopy_list(p_infos)
- for p_name_p_info in p_infos:
- children = get_recursive_children(config,
- p_name_p_info,
- without_native_fixed=True)
- for p_name_p_info_child in children:
- if p_name_p_info_child not in p_infos_res:
- p_infos_res.append(p_name_p_info_child)
- return p_infos_res
-
-def check_dependencies(config, p_name_p_info):
- l_depends_not_installed = []
- fathers = get_recursive_fathers(config, p_name_p_info, without_native_fixed=True)
- for p_name_father, p_info_father in fathers:
- if not(PROD.check_installation(p_info_father)):
- l_depends_not_installed.append(p_name_father)
- return l_depends_not_installed
-
-def compile_all_products(sat, config, options, products_infos, logger):
+ def compile_all_products(self, products_infos): #sat, config, options, products_infos, logger):
"""
Execute the proper configuration commands
in each product build directory.
The logger instance to use for the display and logging
:return: (RCO.ReturnCode) with value as the number of failing commands.
"""
- res = 0
+ # shortcuts
+ config = self.getConfig()
+ options = self.getOptions()
+ logger = self.getLogger()
+ nameAppli = config.VARS.application
+
+ res = [] # list of results for each products
+ DBG.write("compile", [p for p, tmp in products_infos])
for p_name_info in products_infos:
p_name, p_info = p_name_info
# Logging
len_end_line = 30
- header = _("Compilation of %s") % UTS.label(p_name)
- header += " %s \n" % ("." * (len_end_line - len(p_name)))
+ header = _("Compilation of %s ...") % UTS.label(p_name)
logger.info(header)
# Do nothing if the product is not compilable
"compilation" in p_info.properties and \
p_info.properties.compilation == "no"):
UTS.log_step(logger, header, "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")
+ 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")
- sat.clean(config.VARS.application +
- " --products " + p_name +
- " --build --install",
- batch=True,
- verbose=0,
- logger_add_link = logger)
+ cmd_args = "--products %s --build --install" % p_name
+ rc = self.executeMicroCommand("clean", nameAppli, cmd_args)
+ if not rc.isOk():
+ res.append(rc)
+ continue
# 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")
- sat.clean(config.VARS.application +
- " --products " + p_name +
- " --install",
- batch=True,
- verbose=0,
- logger_add_link = logger)
+ cmd_args = "--products %s --install" % p_name
+ rc = self.executeMicroCommand("clean", nameAppli, cmd_args)
+ if not rc.isOk():
+ res.append(rc)
+ continue
# Recompute the product information to get the right install_dir
# (it could change if there is a clean of the install directory)
# Check if it was already successfully installed
if PROD.check_installation(p_info):
logger.info(_("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(_("Not installed"))
+ logger.info(_("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, header, "<KO>")
msg = _("the following products are mandatory:\n")
- for prod_name in l_depends_not_installed:
+ for prod_name in sorted(l_depends_not_installed):
msg += "%s\n" % prod_name
logger.error(msg)
+ res.append(RCO.ReturnCode("KO", "no compile %s as missing mandatory product(s)" % p_name))
continue
# Call the function to compile the product
- res_prod, len_end_line, error_step = compile_product(sat,
- p_name_info,
- config,
- options,
- logger,
- header,
- len_end_line)
+ #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)
- if res_prod != 0:
- res += 1
-
- if error_step != "CHECK":
- # Clean the install directory if there is any
- logger.debug(_("Cleaning the install directory if there is any\n"))
- sat.clean(config.VARS.application +
- " --products " + p_name +
- " --install",
- batch=True,
- verbose=0,
- logger_add_link = logger)
- else:
- # Clean the build directory if the compilation and tests succeed
- if options.clean_build_after:
- UTS.log_step(logger, header, "CLEAN BUILD")
- sat.clean(config.VARS.application +
- " --products " + p_name +
- " --build",
- batch=True,
- verbose=0,
- logger_add_link = logger)
+ if not rc.isOk():
+ # problem
+ if error_step != "CHECK":
+ # Clean the install directory if there is any
+ logger.debug(_("Cleaning the install directory if there is any"))
+ cmd_args = "--products %s --install" % p_name
+ rc0 = self.executeMicroCommand("clean", nameAppli, cmd_args)
+ else:
+ # Ok Clean the build directory if the compilation and tests succeed
+ if options.clean_build_after:
+ UTS.log_step(logger, header, "CLEAN BUILD")
+ cmd_args = "--products %s --build" % p_name
+ rc0 = self.executeMicroCommand("clean", nameAppli, cmd_args)
# Log the result
- if res_prod > 0:
- logger.info("\r%s%s" % (header, " " * len_end_line))
- logger.info("\r" + header + "<KO> " + error_step)
- logger.debug("\n==== <KO> in compile of %s\n" % p_name)
- if error_step == "CHECK":
- logger.info(_("\nINSTALL directory = %s") % p_info.install_dir)
+ if rc.isOk():
+ logger.info("<KO> " + rc.getWhy())
else:
- logger.info("\r%s%s" % (header, " " * len_end_line))
- logger.info("\r" + header + "<OK>")
- logger.info(_("\nINSTALL directory = %s") % p_info.install_dir)
- logger.debug("\n==== <OK> in compile of %s\n" % p_name)
+ logger.info("<KO> " + rc.getWhy())
-
- if res_prod != 0 and options.stop_first_fail:
- break
-
- if res == 0: # no failing commands
- return RCO.ReturnCode("OK", "no failing compile commands", res)
+ if not rc.isOk() and options.stop_first_fail:
+ break # stop at first problem
+
+ resAll = RCO.ReturnCodeFromList(res)
+ nbOk = len([r for r in res if r.isOk()])
+ nbKo = len([r for r in res if not r.isOk()])
+ if resAll.isOk(): # no failing commands
+ return RCO.ReturnCode("OK", "No failing compile commands", nbOk)
else:
- return RCO.ReturnCode("KO", "existing %i failing compile commands" % res, res)
+ return RCO.ReturnCode("KO", "Existing %s failing compile product(s)" % nbKo, nbOk)
-def compile_product(sat, p_name_info, config, options, logger, header, len_end):
+ def compile_product(self, p_name_info): #sat, p_name_info, config, options, logger, header, len_end):
"""
Execute the proper configuration command(s)
in the product build directory.
: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
# Get the build procedure from the product configuration.
# build_sources : autotools -> build_configure, configure, make, make install
# build_sources : cmake -> cmake, make, make install
# build_sources : script -> script executions
- res = 0
if (PROD.product_is_autotools(p_info) or PROD.product_is_cmake(p_info)):
- res, len_end_line, error_step = compile_product_cmake_autotools(sat,
- p_name_info,
- config,
- options,
- logger,
- header,
- len_end)
+ 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):
- res, len_end_line, error_step = compile_product_script(sat,
- p_name_info,
- config,
- options,
- logger,
- header,
- len_end)
+ 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 res==0 and not(os.path.exists(p_info.install_dir)):
+ if rc.isOk() and not(os.path.exists(p_info.install_dir)):
error_step = "NO INSTALL DIR"
msg = _("All steps ended successfully, but install directory not found")
logger.error(msg)
- return RCO.ReturnCode("KO", "Install directory not found", (error_step, p_name, p_info.install_dir))
+ return RCO.ReturnCode("KO", "Install directory for %s not found" % p_name, (error_step, p_name, p_info.install_dir))
# Add the config file corresponding to the dependencies/versions of the
# product that have been successfully compiled
- if res==0:
- logger.debug(_("Add the config file in installation directory\n"))
+ if rc.isOk():
+ logger.debug(_("Add the config file in installation directory"))
add_compile_config_file(p_info, config)
if options.check:
# Do the unit tests (call the check command)
UTS.log_step(logger, header, "CHECK")
- res_check = sat.check(
- config.VARS.application + " --products " + p_name,
- verbose = 0,
- logger_add_link = logger)
- if res_check != 0:
+ cmd_args = "--products %s" % p_name
+ rc0 = self.executeMicroCommand("check", nameAppli, cmd_args)
+ if not rc0.isOk():
error_step = "CHECK"
-
- res += res_check
+ msg = _("compile steps ended successfully, but check problem")
+ logger.error(msg)
+ return RCO.ReturnCode("KO", "check of compile for %s problem" % p_name, (error_step, p_name, p_info.install_dir))
- return res, len_end_line, error_step
-
-def compile_product_cmake_autotools(sat,
- p_name_info,
- config,
- options,
- logger,
- header,
- len_end):
+ 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):
"""
Execute the proper build procedure for autotools or cmake
in the product build directory.
:param len_end: (int) the length of the the end of line (used in display)
:return: (int) 1 if it fails, else 0.
"""
+ config = self.getConfig()
+ options = self.getOptions()
+ logger = self.getLogger()
+
p_name, p_info = p_name_info
# Execute "sat configure", "sat make" and "sat install"
return res, len_end_line, error_step
-def compile_product_script(sat,
- p_name_info,
- config,
- options,
- logger,
- header,
- len_end):
+ def compile_product_script(self, p_name_info): # sat, p_name_info, config, options, logger, header, len_end):
"""Execute the script build procedure in the product build directory.
:param p_name_info: (tuple)
:param len_end: (int) the length of the the end of line (used in display)
:return: (int) 1 if it fails, else 0.
"""
+ 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"
error_step = ""
# Logging and sat command call for the script step
- scrit_path_display = UTS.label(p_info.compil_script)
- UTS.log_step(logger, header, "SCRIPT " + scrit_path_display)
- len_end_line = len_end + len(scrit_path_display)
- res = sat.script(config.VARS.application + " --products " + p_name,
- verbose = 0,
- logger_add_link = logger)
+ script_path_display = UTS.label(p_info.compil_script)
+ UTS.log_step(logger, header, "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)
-
- return res, len_end_line, error_step
+ return res
+
+
+def get_children(config, p_name_p_info):
+ l_res = []
+ p_name, __ = p_name_p_info
+ # Get all products of the application
+ products = config.APPLICATION.products
+ products_infos = PROD.get_products_infos(products, config)
+ for p_name_potential_child, p_info_potential_child in products_infos:
+ if ("depend" in p_info_potential_child and \
+ p_name in p_info_potential_child.depend):
+ l_res.append(p_name_potential_child)
+ return l_res
+
+def get_recursive_children(config, p_name_p_info, without_native_fixed=False):
+ """
+ Get the recursive list of the product that depend on
+ the product defined by prod_info
+
+ :param config: (Config) The global configuration
+ :param prod_info: (Config) The specific config of the product
+ :param without_native_fixed: (bool)
+ If true, do not include the fixed or native products in the result
+ :return: (list) The list of product_informations.
+ """
+ p_name, __ = p_name_p_info
+ # Initialization of the resulting list
+ l_children = []
+
+ # Get the direct children (not recursive)
+ l_direct_children = get_children(config, p_name_p_info)
+ # Minimal case : no child
+ if l_direct_children == []:
+ return []
+ # Add the children and call the function to get the children of the
+ # children
+ for child_name in l_direct_children:
+ l_children_name = [pn_pi[0] for pn_pi in l_children]
+ if child_name not in l_children_name:
+ if child_name not in config.APPLICATION.products:
+ msg = _("""\
+The product %(child_name)s that is in %(product_name)s children
+is not present in application %(appli_name)s.""" %
+ {"child_name" : child_name,
+ "product_name" : p_name.name,
+ "appli_name" : config.VARS.application} )
+ raise Exception(msg)
+ prod_info_child = PROD.get_product_config(config, child_name)
+ pname_pinfo_child = (prod_info_child.name, prod_info_child)
+ # Do not append the child if it is native or fixed and
+ # the corresponding parameter is called
+ if without_native_fixed:
+ if not(PROD.product_is_native(prod_info_child) or \
+ PROD.product_is_fixed(prod_info_child)):
+ l_children.append(pname_pinfo_child)
+ else:
+ l_children.append(pname_pinfo_child)
+ # Get the children of the children
+ l_grand_children = get_recursive_children(config,
+ pname_pinfo_child,
+ without_native_fixed = without_native_fixed)
+ l_children += l_grand_children
+ return l_children
+
+def get_recursive_fathers(config, p_name_p_info, without_native_fixed=False):
+ """
+ Get the recursive list of the dependencies of the product defined
+ by prod_info
+
+ :param config: (Config) The global configuration
+ :param prod_info: (Config) The specific config of the product
+ :param without_native_fixed: (bool)
+ If true, do not include the fixed or native products in the result
+ :return: (list) The list of product_informations.
+ """
+ p_name, p_info = p_name_p_info
+ # Initialization of the resulting list
+ l_fathers = []
+ # Minimal case : no dependencies
+ if "depend" not in p_info or p_info.depend == []:
+ return []
+ # Add the dependencies and call the function to get the dependencies of the
+ # dependencies
+ for father_name in p_info.depend:
+ l_fathers_name = [pn_pi[0] for pn_pi in l_fathers]
+ if father_name not in l_fathers_name:
+ if father_name not in config.APPLICATION.products:
+ msg = _("The product %(father_name)s that is in %(product_nam"
+ "e)s dependencies is not present in application %(appli_name)s" % \
+ {"father_name" : father_name,
+ "product_name" : p_name,
+ "appli_name" : config.VARS.application})
+ raise Exception(msg)
+ prod_info_father = PROD.get_product_config(config, father_name)
+ pname_pinfo_father = (prod_info_father.name, prod_info_father)
+ # Do not append the father if it is native or fixed and
+ # the corresponding parameter is called
+ if without_native_fixed:
+ if not(PROD.product_is_native(prod_info_father) or \
+ PROD.product_is_fixed(prod_info_father)):
+ l_fathers.append(pname_pinfo_father)
+ else:
+ l_fathers.append(pname_pinfo_father)
+ # Get the dependencies of the dependency
+ l_grand_fathers = get_recursive_fathers(config,
+ pname_pinfo_father,
+ without_native_fixed = without_native_fixed)
+ for item in l_grand_fathers:
+ if item not in l_fathers:
+ l_fathers.append(item)
+ return l_fathers
+
+def sort_products(config, p_infos):
+ """Sort the p_infos regarding the dependencies between the products
+
+ :param config: (Config) The global configuration
+ :param p_infos: (list)
+ List of (str, Config) => (product_name, product_info)
+ """
+ l_prod_sorted = UTS.deepcopy_list(p_infos)
+ for prod in p_infos:
+ l_fathers = get_recursive_fathers(config,
+ prod,
+ without_native_fixed=True)
+ l_fathers = [father for father in l_fathers if father in p_infos]
+ if l_fathers == []:
+ continue
+ for p_sorted in l_prod_sorted:
+ if p_sorted in l_fathers:
+ l_fathers.remove(p_sorted)
+ if l_fathers==[]:
+ l_prod_sorted.remove(prod)
+ l_prod_sorted.insert(l_prod_sorted.index(p_sorted)+1, prod)
+ break
+
+ return l_prod_sorted
+
+def extend_with_fathers(config, p_infos):
+ p_infos_res = UTS.deepcopy_list(p_infos)
+ for p_name_p_info in p_infos:
+ fathers = get_recursive_fathers(config,
+ p_name_p_info,
+ without_native_fixed=True)
+ for p_name_p_info_father in fathers:
+ if p_name_p_info_father not in p_infos_res:
+ p_infos_res.append(p_name_p_info_father)
+ return p_infos_res
+
+def extend_with_children(config, p_infos):
+ p_infos_res = UTS.deepcopy_list(p_infos)
+ for p_name_p_info in p_infos:
+ children = get_recursive_children(config,
+ p_name_p_info,
+ without_native_fixed=True)
+ for p_name_p_info_child in children:
+ if p_name_p_info_child not in p_infos_res:
+ p_infos_res.append(p_name_p_info_child)
+ return p_infos_res
+
+def check_dependencies(config, p_name_p_info):
+ l_depends_not_installed = []
+ fathers = get_recursive_fathers(config, p_name_p_info, without_native_fixed=True)
+ for p_name_father, p_info_father in fathers:
+ if not(PROD.check_installation(p_info_father)):
+ l_depends_not_installed.append(p_name_father)
+ return l_depends_not_installed
+
def add_compile_config_file(p_info, config):
"""
compile_cfg = PYCONF.Config()
for prod_name in p_info.depend:
if prod_name not in compile_cfg:
- compile_cfg.addMapping(prod_name,
- PYCONF.Mapping(compile_cfg),
- "")
+ compile_cfg.addMapping(prod_name, PYCONF.Mapping(compile_cfg), "")
prod_dep_info = PROD.get_product_config(config, prod_name, False)
compile_cfg[prod_name] = prod_dep_info.version
# Write it in the install directory of the product
compile_cfg_path = os.path.join(p_info.install_dir, UTS.get_CONFIG_FILENAME())
- f = open(compile_cfg_path, 'w')
- compile_cfg.__save__(f)
- f.close()
+ with open(compile_cfg_path, 'w') as f:
+ compile_cfg.__save__(f)
import os
import sys
import shutil
-import subprocess as SP
from src.options import OptResult
import returnCode as RCO
Prepares the environment.
Build two environment: one for building and one for testing (launch).
"""
+ # shortcuts
+ logger = self.logger
+ config = self.config
+
if not self.build_dir.exists():
# create build dir
self.build_dir.make()
- 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)
+ msg = """
+build_dir = %s
+install_dir = %s
+""" % (str(self.build_dir), str(self.install_dir))
+ logger.trace(msg)
# add products in depend and opt_depend list recursively
- environ_info = PROD.get_product_dependencies(self.config, self.product_info)
+ environ_info = PROD.get_product_dependencies(config, self.product_info)
#environ_info.append(self.product_info.name)
# create build environment
- self.build_environ = ENVI.SalomeEnviron(self.config, ENVI.Environ(dict(os.environ)), True)
- self.build_environ.silent = UTS.isSilent(self.config.USER.output_verbose_level)
- self.build_environ.set_full_environ(self.logger, environ_info)
+ self.build_environ = ENVI.SalomeEnviron(config, ENVI.Environ(dict(os.environ)), True)
+ self.build_environ.silent = UTS.isSilent(config.USER.output_verbose_level)
+ self.build_environ.set_full_environ(logger, environ_info)
# create runtime environment
- self.launch_environ = ENVI.SalomeEnviron(self.config, ENVI.Environ(dict(os.environ)), False)
+ self.launch_environ = ENVI.SalomeEnviron(config, ENVI.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)
+ self.launch_environ.set_full_environ(logger, environ_info)
+ msg = "build environment:\n"
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)
-
- return 0
+ vv = self.build_environ.get(ee)
+ if len(vv) > 0:
+ msg += " %s = %s\n" % (ee, vv)
+
+ logger.trace(msg)
+ return RCO.ReturnCode("OK", "prepare done")
def cmake(self, options=""):
"""Runs cmake with the given options."""
cmake_option = options
# 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 += " %s " % " ".join(self.product_info.cmake_options.split())
# add debug option
if self.debug_mode:
# 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.APPLICATION.cmake_generator
+ if 'cmake_genepreparerator' in self.config.APPLICATION:
+ cmake_option += " -DCMAKE_GENERATOR=%s" % \
+ self.config.APPLICATION.cmake_generator
cmd = """
# CMAKE
""" % (nb_proc, make_opt)
env = self.build_environ.environ.environ
- res = SP.call(cmd, cwd=str(self.build_dir), env=env)
+ res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env, logger=self.logger)
return res
cmd += cmd + " ALL_BUILD.vcxproj"
env = self.build_environ.environ.environ
- res = SP.Popen(command, cwd=str(self.build_dir), env=env)
+ res = UTS.Popen(command, cwd=str(self.build_dir), env=env, logger=self.logger)
return res
cmd = 'make install'
env = self.build_environ.environ.environ
- res = SP.Popen(command, cwd=str(self.build_dir), env=env)
+ res = UTS.Popen(command, cwd=str(self.build_dir), env=env, logger=self.logger)
return res
def check(self, command=""):
cmd = command
env = self.build_environ.environ.environ
- res = SP.Popen(command, cwd=str(self.build_dir), env=env)
+ res = UTS.Popen(command, cwd=str(self.build_dir), env=env , logger=self.logger)
return res
if use_autotools: cmd = "(autotools)"
if use_ctest: cmd = "(ctest)"
- self.log("\n", 4, False)
- self.log("%(module)s: Run default compilation method %(cmd)s\n" % \
- { "module": self.module, "cmd": cmd }, 4)
+ self.info("%s: Run default compilation method %s" % (self.module, cmd))
if use_autotools:
if not self.prepare(): return self.get_result()
- if not self.build_configure(
- build_conf_options): return self.get_result()
+ if not self.build_configure(build_conf_options): return self.get_result()
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()
def do_python_script_build(self, script, nb_proc):
"""Performs a build with a script."""
+ logger = self.logger
# script found
- self.logger.info(_("Compile %s using script %s\n") % \
+ logger.info(_("Compile %s using script %s\n") % \
(self.product_info.name, UTS.label(script)) )
try:
import imp
product = self.product_info.name
pymodule = imp.load_source(product + "_compile_script", script)
self.nb_proc = nb_proc
- retcode = pymodule.compil(self.config, self, self.logger)
+ retcode = pymodule.compil(self.config, self, logger)
except:
__, exceptionValue, exceptionTraceback = sys.exc_info()
- self.logger.error(str(exceptionValue))
+ logger.error(str(exceptionValue))
import traceback
traceback.print_tb(exceptionTraceback)
traceback.print_exc()
else :
make_options = "-j%s" % nb_proc
- self.logger.info(_("Run build script '%s'") % script)
+ self.logger.trace(_("Run build script '%s'") % script)
self.complete_environment(make_options)
# linux or win compatible, have to be chmod +x ?
# Run build script
%s
""" % script
-
env = self.build_environ.environ.environ
- res = SP.Popen(cmd, cwd=str(self.build_dir), env=env)
+ res = UTS.Popen(cmd, cwd=str(self.build_dir), env=env)
return res
def do_script_build(self, script, number_of_proc=0):
return self.do_python_script_build(script, nb_proc)
msg = _("The script %s must have extension as .sh, .bat or .py.") % script
- raise Exception(msg)
+ return RCO.ReturnCode("KO", msg)