Salome HOME
correction bug production de launcher (premier caractère blanc)
[tools/sat.git] / commands / compile.py
index ece2588a9d7956069d5e7e6b30286eb54b9c86e6..9b51a87a56dd1e509874736f264133dbcb82eb10 100644 (file)
@@ -19,6 +19,7 @@
 import os
 
 import src
+import src.debug as DBG
 
 # Compatibility python 2/3 for input function
 # input stays input for python 3 and input = raw_input for python 2
@@ -30,8 +31,8 @@ except NameError:
 # Define all possible option for the compile command :  sat compile <options>
 parser = src.options.Options()
 parser.add_option('p', 'products', 'list2', 'products',
-    _('Optional: products to configure. This option can be'
-    ' passed several time to configure several products.'))
+    _('Optional: products to compile. This option can be'
+    ' passed several time to compile several products.'))
 parser.add_option('', 'with_fathers', 'boolean', 'fathers',
     _("Optional: build all necessary products to the given product (KERNEL is "
       "build before building GUI)."), False)
@@ -54,6 +55,9 @@ parser.add_option('', 'stop_first_fail', 'boolean', 'stop_first_fail', _(
 parser.add_option('', 'check', 'boolean', 'check', _(
                   "Optional: execute the unit tests after compilation"), False)
 
+parser.add_option('', 'clean_build_after', 'boolean', 'clean_build_after', 
+                  _('Optional: remove the build directory after successful compilation'), False)
+
 def get_products_list(options, cfg, logger):
     '''method that gives the product list with their informations from 
        configuration regarding the passed options.
@@ -295,8 +299,10 @@ def compile_all_products(sat, config, options, products_infos, logger):
         logger.flush()
 
         # 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"):
+        if ("properties" in p_info and
+            "compilation" in p_info.properties and
+            p_info.properties.compilation == "no"):
+
             log_step(logger, header, "ignored")
             logger.write("\n", 3, False)
             continue
@@ -310,7 +316,7 @@ def compile_all_products(sat, config, options, products_infos, logger):
         # Clean the build and the install directories 
         # if the corresponding options was called
         if options.clean_all:
-            log_step(logger, header, "CLEAN BUILD AND INSTALL")
+            log_step(logger, header, "CLEAN BUILD AND INSTALL ")
             sat.clean(config.VARS.application + 
                       " --products " + p_name + 
                       " --build --install",
@@ -321,7 +327,7 @@ def compile_all_products(sat, config, options, products_infos, logger):
         # Clean the the install directory 
         # if the corresponding option was called
         if options.clean_install and not options.clean_all:
-            log_step(logger, header, "CLEAN INSTALL")
+            log_step(logger, header, "CLEAN INSTALL ")
             sat.clean(config.VARS.application + 
                       " --products " + p_name + 
                       " --install",
@@ -329,6 +335,41 @@ def compile_all_products(sat, config, options, products_infos, logger):
                       verbose=0,
                       logger_add_link = logger)
         
+        # Recompute the product information to get the right install_dir
+        # (it could change if there is a clean of the install directory)
+        p_info = src.product.get_product_config(config, p_name)
+        
+        # Check if sources was already successfully installed
+        check_source = src.product.check_source(p_info)
+        if not check_source:
+            logger.write(_("Sources of product not found (try 'sat -h prepare') \n"))
+            res += 1 #BUG
+            continue
+        
+        if src.product.product_is_salome(p_info):
+            # For salome modules, we check if the sources of configuration modules are present
+            # configuration modules have the property "configure_dependency"
+
+            # get the list of all modules in application 
+            all_products_infos = src.product.get_products_infos(config.APPLICATION.products,
+                                                                config)
+            check_source = True
+            # for configuration modules, check if sources are present
+            for product_name, product_info in all_products_infos:
+                if ("properties" in product_info and
+                    "configure_dependency" in product_info.properties and
+                    product_info.properties.configure_dependency == "yes"):
+                    check_source = check_source and src.product.check_source(product_info)
+                    if not check_source:
+                        logger.write(_("\nERROR : SOURCES of %s not found! It is required for" 
+                                       " the configuration\n" % product_name))
+                        logger.write(_("        Get it with the command : sat prepare %s -p %s \n" % 
+                                      (config.APPLICATION.name, product_name)))
+            if not check_source:
+                # if at least one configuration module is not present, we stop compilation
+                res += 1
+                continue
+        
         # Check if it was already successfully installed
         if src.product.check_installation(p_info):
             logger.write(_("Already installed\n"))
@@ -351,13 +392,8 @@ def compile_all_products(sat, config, options, products_infos, logger):
             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 = compile_product(
+             sat, p_name_info, config, options, logger, header, len_end_line)
         
         if res_prod != 0:
             res += 1
@@ -373,7 +409,17 @@ def compile_all_products(sat, config, options, products_infos, logger):
                           batch=True,
                           verbose=0,
                           logger_add_link = logger)
-            
+        else:
+            # Clean the build directory if the compilation and tests succeed
+            if options.clean_build_after:
+                log_step(logger, header, "CLEAN BUILD")
+                sat.clean(config.VARS.application + 
+                          " --products " + p_name + 
+                          " --build",
+                          batch=True,
+                          verbose=0,
+                          logger_add_link = logger)
+
         # Log the result
         if res_prod > 0:
             logger.write("\r%s%s" % (header, " " * len_end_line), 3)
@@ -449,7 +495,7 @@ def compile_product(sat, p_name_info, config, options, logger, header, len_end):
                 " no install directory was found !")
         logger.write(src.printcolors.printcError(msg), 4)
         logger.write("\n", 4)
-        return res, len_end_line, error_step
+        return res, len_end, error_step
     
     # Add the config file corresponding to the dependencies/versions of the 
     # product that have been successfully compiled
@@ -618,7 +664,7 @@ def description():
 def run(args, runner, logger):
     '''method that is called when salomeTools is called with compile parameter.
     '''
-    
+    # DBG.write("compile runner.cfg", runner.cfg, True)
     # Parse the options
     (options, args) = parser.parse_args(args)
 
@@ -683,4 +729,4 @@ def run(args, runner, logger):
     code = res
     if code != 0:
         code = 1
-    return code
\ No newline at end of file
+    return code