Salome HOME
add logs to git retry functionality
[tools/sat.git] / src / compilation.py
index bdd789f49f8da42e650d72e4454b503003183d6f..e958f9cddcddd1318336962fb2e11e1b07182baf 100644 (file)
@@ -19,6 +19,7 @@
 import os
 import subprocess
 import sys
+import shutil
 
 import src
 
@@ -50,6 +51,9 @@ class Builder:
         self.debug_mode = False
         if "debug" in self.product_info and self.product_info.debug == "yes":
             self.debug_mode = True
+        self.verbose_mode = False
+        if "verbose" in self.product_info and self.product_info.verbose == "yes":
+            self.verbose_mode = True
 
     ##
     # Shortcut method to log in log file.
@@ -109,18 +113,31 @@ class Builder:
         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:
             cmake_option += " -DCMAKE_BUILD_TYPE=Debug"
         else :
             cmake_option += " -DCMAKE_BUILD_TYPE=Release"
+
+        # add verbose option if specified in application for this product.
+        if self.verbose_mode:
+            cmake_option += " -DCMAKE_VERBOSE_MAKEFILE=ON"
+
+        # 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
         
         command = ("cmake %s -DCMAKE_INSTALL_PREFIX=%s %s" %
                             (cmake_option, self.install_dir, self.source_dir))
 
         self.log_command(command)
+        # for key in sorted(self.build_environ.environ.environ.keys()):
+            # print key, "  ", self.build_environ.environ.environ[key]
         res = subprocess.call(command,
                               shell=True,
                               cwd=str(self.build_dir),
@@ -128,8 +145,8 @@ class Builder:
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT)
 
+        self.put_txt_log_in_appli_log_dir("cmake")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("cmake")
             return res
         else:
             return 1
@@ -151,9 +168,8 @@ class Builder:
                               env=self.build_environ.environ.environ,
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT)
-
+        self.put_txt_log_in_appli_log_dir("build_configure")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("build_configure")
             return res
         else:
             return 1
@@ -165,7 +181,8 @@ class Builder:
         if 'configure_options' in self.product_info:
             options += " %s " % self.product_info.configure_options
 
-        command = "%s/configure --prefix=%s" % (self.source_dir, str(self.install_dir))
+        command = "%s/configure --prefix=%s" % (self.source_dir,
+                                                str(self.install_dir))
 
         command = command + " " + options
         self.log_command(command)
@@ -176,9 +193,9 @@ class Builder:
                               env=self.build_environ.environ.environ,
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT)
-
+        
+        self.put_txt_log_in_appli_log_dir("configure")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("configure")
             return res
         else:
             return 1
@@ -228,28 +245,22 @@ CC=\\"hack_libtool\\"%g" libtool'''
                               env=self.build_environ.environ.environ,
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT)
-
+        self.put_txt_log_in_appli_log_dir("make")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("make")
             return res
         else:
             return 1
     
     ##
     # Runs msbuild to build the module.
-    def wmake(self, opt_nb_proc = None):
-        nbproc = self.get_nb_proc(opt_nb_proc)
+    def wmake(self,nb_proc, opt_nb_proc = None):
 
-        hh = 'MSBUILD /m:%s' % str(nbproc)
+        hh = 'MSBUILD /m:%s' % str(nb_proc)
         if self.debug_mode:
             hh += " " + src.printcolors.printcWarning("DEBUG")
-        self.log_step(hh)
-
         # make
         command = 'msbuild'
-        if self.options.makeflags:
-            command = command + " " + self.options.makeflags
-        command = command + " /maxcpucount:" + str(nbproc)
+        command = command + " /maxcpucount:" + str(nb_proc)
         if self.debug_mode:
             command = command + " /p:Configuration=Debug"
         else:
@@ -263,9 +274,9 @@ CC=\\"hack_libtool\\"%g" libtool'''
                               env=self.build_environ.environ.environ,
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT)
-
+        
+        self.put_txt_log_in_appli_log_dir("make")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("make")
             return res
         else:
             return 1
@@ -290,27 +301,30 @@ CC=\\"hack_libtool\\"%g" libtool'''
                               env=self.build_environ.environ.environ,
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT)
-
+        
+        self.put_txt_log_in_appli_log_dir("makeinstall")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("makeinstall")
             return res
         else:
             return 1
 
     ##
     # Runs 'make_check'.
-    def check(self):
+    def check(self, command=""):
         if src.architecture.is_windows():
-            command = 'msbuild RUN_TESTS.vcxproj'
+            cmd = 'msbuild RUN_TESTS.vcxproj'
         else :
             if self.product_info.build_source=="autotools" :
-                command = 'make check'
+                cmd = 'make check'
             else:
-                command = 'make test'
-            
-        self.log_command(command)
+                cmd = 'make test'
+        
+        if command:
+            cmd = command
+        
+        self.log_command(cmd)
 
-        res = subprocess.call(command,
+        res = subprocess.call(cmd,
                               shell=True,
                               cwd=str(self.build_dir),
                               env=self.launch_environ.environ.environ,
@@ -324,7 +338,10 @@ CC=\\"hack_libtool\\"%g" libtool'''
       
     ##
     # Performs a default build for this module.
-    def do_default_build(self, build_conf_options="", configure_options="", show_warning=True):
+    def do_default_build(self,
+                         build_conf_options="",
+                         configure_options="",
+                         show_warning=True):
         use_autotools = False
         if 'use_autotools' in self.product_info:
             uc = self.product_info.use_autotools
@@ -357,7 +374,8 @@ CC=\\"hack_libtool\\"%g" libtool'''
 
         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()
@@ -392,7 +410,6 @@ CC=\\"hack_libtool\\"%g" libtool'''
             pymodule = imp.load_source(product + "_compile_script", script)
             self.nb_proc = nb_proc
             retcode = pymodule.compil(self.config, self, self.logger)
-            self.put_txt_log_in_appli_log_dir("script")
         except:
             __, exceptionValue, exceptionTraceback = sys.exc_info()
             self.logger.write(str(exceptionValue), 1)
@@ -400,12 +417,15 @@ CC=\\"hack_libtool\\"%g" libtool'''
             traceback.print_tb(exceptionTraceback)
             traceback.print_exc()
             retcode = 1
+        finally:
+            self.put_txt_log_in_appli_log_dir("script")
 
         return retcode
 
     def complete_environment(self, make_options):
         assert self.build_environ is not None
-        # pass additional variables to environment (may be used by the build script)
+        # pass additional variables to environment 
+        # (may be used by the build script)
         self.build_environ.set("SOURCE_DIR", str(self.source_dir))
         self.build_environ.set("INSTALL_DIR", str(self.install_dir))
         self.build_environ.set("PRODUCT_INSTALL", str(self.install_dir))
@@ -426,15 +446,16 @@ CC=\\"hack_libtool\\"%g" libtool'''
 
         self.log_command("  " + _("Run build script %s\n") % script)
         self.complete_environment(make_options)
+        
         res = subprocess.call(script, 
                               shell=True,
                               stdout=self.logger.logTxtFile,
                               stderr=subprocess.STDOUT,
-                              cwd=str(self.build_dir), 
+                              cwd=str(self.build_dir),
                               env=self.build_environ.environ.environ)
 
+        self.put_txt_log_in_appli_log_dir("script")
         if res == 0:
-            self.put_txt_log_in_appli_log_dir("script")
             return res
         else:
             return 1
@@ -473,7 +494,7 @@ CC=\\"hack_libtool\\"%g" libtool'''
         # write the logTxtFile copy it to the destination, and then recreate 
         # it as it was
         self.logger.logTxtFile.close()
-        os.rename(self.logger.txtFilePath, file_path)
+        shutil.move(self.logger.txtFilePath, file_path)
         self.logger.logTxtFile = open(str(self.logger.txtFilePath), 'w')
         self.logger.logTxtFile.write(open(file_path, "r").read())
-        
\ No newline at end of file
+