-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVistaBuildLinux.py
157 lines (125 loc) · 6.84 KB
/
VistaBuildLinux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Linux build script designed for jenkins
# $Id
import sys, os, time, shutil, VistaPythonCommon
#build project in current directory
def BuildIt(strBuildType='Default', strCompiler = 'GCC_DEFAULT', strCMakeVariables = '', bDeleteCMakeCache = True, strBuildFolder='JenkinsDefault', bRunTests = False, bInstall = False ):
#make sure we are on linux system
if sys.platform != 'linux2':
VistaPythonCommon.ExitError('\n\n*** ERROR *** Linux build on non Linux system\n\n',-1)
sys.stdout.write('Buildtype: ' + strBuildType + '\n')
sys.stdout.write('Compiler: ' + strCompiler + '\n')
sys.stdout.write('CMake Definitions: ' + strCMakeVariables + '\n')
iRC, strUsername = VistaPythonCommon.SysCall('whoami',ExitOnError = False)
sys.stdout.write('Username: '+strUsername+'\n')
iRC, strShell = VistaPythonCommon.SysCall('echo $SHELL',ExitOnError = False)
sys.stdout.write('Shell: '+strShell+'\n')
iRC, strHostname = VistaPythonCommon.SysCall('echo $HOSTNAME',ExitOnError = False)
sys.stdout.write('Hostname: '+strHostname+'\n')
iRC, strPythonVersion = VistaPythonCommon.SysCall('python --version',ExitOnError = False)
sys.stdout.write('PythonVersion: '+strPythonVersion+'\n')
sys.stdout.write('\n')
sys.stdout.flush()
if True == bRunTests:
sys.stdout.write('make tests will be executed\n')
if True == bInstall:
sys.stdout.write('make install will be executed\n')
sys.stdout.flush()
fStartTime=time.time()
# pretty ugly we switch standard build and jenkins by the buildfolder and then ignore it ...
# but that works for windows. the reason behind this is, that you need a folder for debug and one for release anyway
if strBuildFolder is 'JenkinsDefault':
MakeJenkinsBuild(strBuildType, strCompiler, strCMakeVariables, bDeleteCMakeCache, bRunTests, bInstall)
else:
MakeLinuxStandardBuild(strCompiler,bDeleteCMakeCache)
sys.stdout.write("\n\nElapsed time: " + str(int(time.time()-fStartTime)) + " seconds\n")
sys.stdout.flush()
def MakeLinuxStandardBuild(strCompiler,bDeleteCMakeCache):
strBuildFolder='build_LINUX.X86_64'
strCompilerEnv = GetCompilerEnvCall(strCompiler)
strConsoleOutput=''
if not os.path.exists(strBuildFolder):
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv+'$VISTA_CMAKE_COMMON/MakeLinuxBuildStructure.sh')
else:
if True == bDeleteCMakeCache:
shutil.rmtree(strBuildFolder,True)#clean cmake build
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv+'$VISTA_CMAKE_COMMON/MakeLinuxBuildStructure.sh')
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
os.chdir(os.path.join(os.getcwd(), strBuildFolder))
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make -j')
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
def MakeJenkinsBuild(strBuildType, strCompiler, strCMakeVariables, bDeleteCMakeCache, bRunTests, bInstall):
strSysName = os.uname()[0].upper()
strMachine = os.uname()[4].upper()
strBuildFolder = 'build.' + strSysName + '.' + strMachine + '.' + strCompiler + '.' + strBuildType
if strBuildType is 'Default':
VistaPythonCommon.ExitError('right now BuildType Default is not supported for Jenkins and Linux',-1)
if not os.path.exists(strBuildFolder):
VistaPythonCommon.SysCall('mkdir ' + strBuildFolder)
else:
if True == bDeleteCMakeCache:
shutil.rmtree(strBuildFolder)#clean cmake build
VistaPythonCommon.SysCall('mkdir ' + strBuildFolder)
strBasePath = os.getcwd()
os.chdir(os.path.join(strBasePath, strBuildFolder))
#check compiler if we are on gpucluster
strCompilerEnv = GetCompilerEnvCall(strCompiler)
sys.stdout.write('Compiler Environment:\n ' + strCompilerEnv + '\n\nExecution cmake:\n')
VistaPythonCommon.SysCall('cmake -version',ExitOnError = False)
sys.stdout.flush()
#configure cmake
strCMakeCmd = strCompilerEnv + 'cmake -DCMAKE_BUILD_TYPE=' + strBuildType + ' ' + strCMakeVariables + ' ' + os.path.join(strBasePath)
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCMakeCmd)
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
if VistaPythonCommon.CheckForCMakeError(strConsoleOutput):
VistaPythonCommon.ExitError('\n\n*** ERROR *** Cmake failed to generate configuration\n\n',-1)
#log gcc version
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + '$CXX -v')
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
#make it
if (0 == os.uname()[1].find('linuxgpu')):
iRC, strConsoleOutput = VistaPythonCommon.SysCall('who | wc -l')
if 0==int(strConsoleOutput):
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make -j')
else:
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make -j2')
else:
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make')
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
#execute tests
if True == bRunTests:
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make test_outputonfailure',ExitOnError = False)
#if 0 != iRC:
# iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make test_verbose',ExitOnError = True)
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
#install
if True == bInstall:
iRC, strConsoleOutput = VistaPythonCommon.SysCall(strCompilerEnv + 'make install')
sys.stdout.write(strConsoleOutput)
sys.stdout.flush()
#since every syscall opens a new shell we have to set environment each time :(
def GetCompilerEnvCall(strCompiler):
strDefaultModules = 'module unload gcc;module unload intel;module unload cmake;module load cmake/2.8.5;'
if (0 == os.uname()[1].find('linuxgpu')):
liCompilerDef = strCompiler.split('_', 1)
if (len(liCompilerDef) != 0):
if 'INTEL' in liCompilerDef[0]:
return strDefaultModules+'module load intel;'
elif 'GCC' in liCompilerDef[0]:
if (len(liCompilerDef) > 1):
if 'DEFAULT' in liCompilerDef[1]:
return strDefaultModules+'module load gcc;'
else:
return strDefaultModules+'module load gcc/' + liCompilerDef[1] + ';'
else:
sys.stderr.write('unsupported compiler-version: ' + strCompiler)
VistaPythonCommon.ExitGently(-1)
else:
return ''
else:
return ''