import os
import shutil
import subprocess
+import threading
import datetime
+import sys
from salome_environ import computeEnv
from salome_misc import *
return s
elif isinstance(srcLoc,tuple):
dirGitLoc=os.path.splitext(os.path.basename(srcLoc[0]))[0]
- p=subprocess.Popen(["git","rev-parse","--verify","HEAD"],cwd=dirGitLoc,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+ p=subprocess.Popen(["git","rev-parse","--verify","HEAD"],cwd=dirGitLoc)
p_out,p_err=p.communicate()
if p.returncode != 0:
msg = "Error in __getCurrentVersion\n" + p_err
config["softwareChanged"][pattern] = True
return myBuildDir,myInstallDir,True
-def __compilePart1(p,buildDir):
- a,b=p.communicate()
- f=file(os.path.join(buildDir,cfgOut),"w") ; f.write(a) ; f.flush()
- f=file(os.path.join(buildDir,cfgErr),"w") ; f.write(b) ; f.flush()
- if p.returncode != 0:
- msg = "Error in build step. See details in %s and %s\n"%(os.path.join(buildDir,cfgOut), os.path.join(buildDir,cfgErr))
- raise Exception(msg)
+def __runCommandAndLogToFileAndStdOut(myCmd,myBuildDir,envAcc,filename_out,filename_err):
+ file_out=file(os.path.join(myBuildDir,filename_out),"w")
+ file_err=file(os.path.join(myBuildDir,filename_err),"w")
+ p=subprocess.Popen(myCmd,cwd=myBuildDir,env=computeEnv(envAcc),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+ def tee_pipe(pipe, f1, f2):
+ for line in pipe:
+ f1.write(line)
+ f2.write(line)
+ pass
+ pass
+ t1 = threading.Thread(target=tee_pipe, args=(p.stdout, file_out, sys.stdout))
+ t2 = threading.Thread(target=tee_pipe, args=(p.stderr, file_err, sys.stderr))
+ t3 = threading.Thread(target=p.wait)
+ t1.start(); t2.start(); t3.start()
+ t1.join(); t2.join(); t3.join()
+ file_out.flush()
+ file_err.flush()
+ return p.returncode
+
+def __compilePart1(myCmd,envAcc,buildDir):
+ returncode = __runCommandAndLogToFileAndStdOut(myCmd,buildDir,envAcc,cfgOut,cfgErr)
+ if returncode != 0:
+ msg = "Error in build step. See details in %s and %s\n"%(os.path.join(buildDir,cfgOut), os.path.join(buildDir,cfgErr))
+ raise Exception(msg)
def __compilePart2(topSrcDir,pattern,config,envAcc,buildDir,splitInstall):
print("make in %s"%(buildDir))
paraCompFlag = config["paraCompFlag"]
if not splitInstall:
- p=subprocess.Popen(["make",paraCompFlag,"install"],cwd=buildDir,env=computeEnv(envAcc),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- a,b=p.communicate()
- f=file(os.path.join(buildDir,compOut),"w") ; f.write(a) ; f.flush()
- f=file(os.path.join(buildDir,compErr),"w") ; f.write(b) ; f.flush()
- if p.returncode != 0:
+ returncode = __runCommandAndLogToFileAndStdOut(["make",paraCompFlag,"install"],buildDir,envAcc,compOut,compErr)
+ if returncode != 0:
msg = "Error in build step. See details in %s and %s\n"%(os.path.join(buildDir,compOut), os.path.join(buildDir,compErr))
raise Exception(msg)
else:
- p=subprocess.Popen(["make",paraCompFlag],cwd=buildDir,env=computeEnv(envAcc),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- a0,b0=p.communicate()
- f=file(os.path.join(buildDir,compOut),"w") ; f.write(a0) ; f.flush()
- f=file(os.path.join(buildDir,compErr),"w") ; f.write(b0) ; f.flush()
- if p.returncode != 0:
+ returncode = __runCommandAndLogToFileAndStdOut(["make",paraCompFlag],buildDir,envAcc,compOut,compErr)
+ if returncode != 0:
msg = "Error in build step. See details in %s and %s\n"%(os.path.join(buildDir,compOut), os.path.join(buildDir,compErr))
raise Exception(msg)
- p=subprocess.Popen(["make",paraCompFlag,"install"],cwd=buildDir,env=computeEnv(envAcc),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- a1,b1=p.communicate()
- f=file(os.path.join(buildDir,compOut),"w") ; f.write(a0+a1) ; f.flush()
- f=file(os.path.join(buildDir,compErr),"w") ; f.write(b0+b1) ; f.flush()
- if p.returncode != 0:
+ returncode = __runCommandAndLogToFileAndStdOut(["make",paraCompFlag,"install"],buildDir,envAcc,compOut,compErr)
+ if returncode != 0:
msg = "Error in build step. See details in %s and %s\n"%(os.path.join(buildDir,compOut), os.path.join(buildDir,compErr))
raise Exception(msg)
pass
return myInstallDir
myCmd=[os.path.join(srcDir,"configure"),"--prefix=%s"%(myInstallDir)]+addCfgParam
print "Command: ", " ".join(myCmd)
- p=subprocess.Popen(myCmd,cwd=myBuildDir,env=computeEnv(envAcc),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- __compilePart1(p,myBuildDir)
+ __compilePart1(myCmd,envAcc,myBuildDir)
__compilePart2(topSrcDir,pattern,config,envAcc,myBuildDir,splitInstall)
return myInstallDir
return myInstallDir
myCmd=["cmake","-DCMAKE_INSTALL_PREFIX=%s"%(myInstallDir)]+addCfgParam+[srcDir]
print(" ".join(myCmd))
- p=subprocess.Popen(myCmd,cwd=myBuildDir,env=computeEnv(envAcc),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- __compilePart1(p,myBuildDir)
+ __compilePart1(myCmd,envAcc,myBuildDir)
__compilePart2(topSrcDir,pattern,config,envAcc,myBuildDir,False)
return myInstallDir