forked from iLCSoft/iLCInstall
-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseilc.py
1372 lines (1101 loc) · 58.7 KB
/
baseilc.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##################################################
#
# Base class for ILC Software modules
#
# Author: Jan Engels, DESY
# Date: Jan, 2007
#
##################################################
from __future__ import print_function
# custom imports
from util import *
import logging
import re
import time
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
try:
import simplejson as json
except:
import json
log = logging.getLogger('ilcinstall')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
#ch.setLevel(logging.DEBUG)
#
## bind the console handler to the root logger
##logging.getLogger().addHandler(ch)
#
## bind the console handler to the logger
log.addHandler(ch)
class BaseILC:
""" Base class for ILC Software modules. """
ilcHome = '/afs/desy.de/group/it/ilcsoft/'
os_ver = OSDetect()
# shared libraries extension
if os_ver.type == "Darwin":
shlib_ext=".dylib"
else:
shlib_ext=".so"
def __init__(self, userInput, name, alias):
self.patchPath = ""
self.__userInput = userInput
self.name = name # module name (e.g. LCIO, GEAR, Marlin, CEDViewer)
self.alias = alias # module alias (e.g. lcio, gear, Marlin, CEDViewer)
# self.nightlyBuild = False # flag for nightly builds
self.installSupport = True # flag for install support
self.download = Download(self) # download struct ( groups together a bunch of download variables )
self.download.gitrepo = name
self.hasCMakeBuildSupport = True # can the package be built with cmake?
self.hasCMakeFindSupport = True # if yes package is listed in CMAKE_MODULE_PATH in ILCSoft.cmake
self.makeTests = False # flag for calling "make test" after building the software
self.rebuild = False # flag for calling a "make clean" before building the software
self.skipCompile = False # flag for skipping the compile step of a module
self.useLink = False # flag for "link" packages
self.parent = None # parent class (this should be set to the ilcsoft object)
self.reqfiles = [] # list of required files to "use" this package (libraries, binaries, etc.)
self.optmodules = [] # optional modules (this package will try to build itself with this modules)
self.reqmodules = [] # required modules for building or using the libraries of this package
self.reqmodules_external = [] # required modules for only building the package (their versions do not
# affect the consistency of the package e.g. QT, CMake, Java in some cases..)
self.reqmodules_buildonly = [] # required modules for only building this package (their environment variables
# will only be written in the build_env.sh of this package
self.envcmake = {} # cmake environment (e.g. BUILD_SHARED_LIBS=ON)
self.cmakecache = {} # cmake variables to export in ILCSoft.cmake cache
self.cmakeconfig = None # path to package CMake config file. If None use the installPath
self.envorder = [] # use for environment variables that have priority
self.env = {} # environment variables
self.envcmds = [] # cmds added to the environment script (build_env.sh)
self.envpath = { # path environment variables (e.g. PATH, LD_LIBRARY_PATH, CLASSPATH)
"PATH" : [],
"LD_LIBRARY_PATH" : [],
"PYTHONPATH" : [],
"CLASSPATH" : [],
"LD_RUN_PATH" : [],
"DT_RUN_PATH" : [],
"MARLIN_DLL" : []
}
## fg: this causes problems on (my) mac with Mojave ...
## if self.os_ver.type == "Darwin":
## self.download.cmd="curl"
def __repr__(self):
if( self.mode == "install" ):
print("\n\t+ " + self.name + ":", end=' ')
print("version [ " + self.version + " ]")
if( not os.path.exists(self.installPath) ):
print("\t + will be installed to: [ " + self.installPath + " ]")
print("\t + download sources with [ " + self.download.type + " ] from:")
print(self.download)
if( self.downloadOnly ):
print("\t + download only: True")
else:
mods = self.reqmodules + self.optmodules + self.reqmodules_buildonly
if( len(mods) > 0 ):
print("\t + will be built with:", end=' ')
for modname in mods:
print("[" + modname + "]", end=' ')
if( (len(self.reqmodules) > 0) or (len(self.reqmodules_buildonly) > 0) or (len(self.reqmodules_external) > 0)):
print("\n\t + following modules are required:", end=' ')
reqmods = self.reqmodules + self.reqmodules_buildonly + self.reqmodules_external
for modname in reqmods:
print("[" + modname + "]", end=' ')
print()
if( self.mode == "use" ):
print(" + [ " + self.installPath + " - version: " + self.version + " ]", end=' ')
if self.useLink:
print(" -> [ "+ self.realPath() + " ]", end=' ')
print()
return str("")
def abort(self, msg):
""" used to abort the installation.
displays the module name and the given message """
print()
print("*** ERROR in module [ " + self.name + " ]: DEBUG INFO: " + str(self.parent.debugInfo))
print()
print("*** ERROR in module [ " + self.name + " ]: " + msg)
if ("logfile" in dir(self)):
print()
print("Logfile for failed module: " + self.logfile)
# write error to logfile
try:
getoutput( "echo \"*** Error in module [ " + self.name + " ]: DEBUG INFO: " + str(self.parent.debugInfo).replace("\n","") + "\" >> " + self.logfile )
getoutput( "echo \"*** Error in module [ " + self.name + " ]: " + str(msg).replace("\n","") + "\" >> " + self.logfile )
except:
pass
sys.exit(1)
# def exe_cmd(self, cmd, abort=True):
# log.debug( 'run cmd: ' + cmd )
# r = getstatusoutput( cmd )
#
# log.debug( 'cmd output: \n%s' % r[1] )
# log.debug( 'cmd exit status: %s' % r[0] )
#
# if r[0] != 0 and abort:
# raise Exception( "failed to execute cmd: "+ cmd )
#
# return r
def userInput(self):
return self.__userInput
def autoDetect(self):
""" auto detect module """
self.autoDetected = False
# auto detect settings
self.installPath = self.autoDetectPath()
if self.installPath:
self.version = self.autoDetectVersion()
if self.version:
check = self.checkInstall()
if check:
self.autoDetected=True
def setMode(self, mode):
""" sets this module to be used as an already existing
version or to be installed from scratch.
this method is also a good place to initialize variables
that dependend on the installation mode and need a
default value before the init method is called (e.g.
if you need a default download.url based on the module
version and still want the user to be able to define a
download.url in the config file :) """
# initialize download only flag
self.downloadOnly = self.parent.downloadOnly
# initialize download type flag
if( self.parent.downloadType != "" ):
self.download.type = self.parent.downloadType
# initialize download username
if( self.parent.downloadUser != "" ):
self.download.username = self.parent.downloadUser
# initialize download password
if( self.parent.downloadPass != "" ):
self.download.password = self.parent.downloadPass
# initialize cleanInstall flag
self.cleanInstall = self.parent.cleanInstall
self.rebuild = self.parent.rebuild
self.nightlyTargets = self.parent.nightlyTargets
self.nightlyBuild = self.parent.nightlyBuild
self.envcmake.update(self.parent.envcmake)
self.makeTests = self.parent.makeTests
if( mode == "install" ):
if( not self.installSupport ):
self.abort( "Sorry, it is not possible to install " \
+ self.name + " with this installation script!!" )
# software version
self.version = self.__userInput
# name of the tarball for wget downloads
self.download.tarball = self.alias + "_" + self.version + ".tgz"
# install path
self.installPath = self.parent.installPath + "/" + self.alias + "/" + self.version
elif( mode == "link" ):
# set link flag to true
self.useLink = True
# linkPath
if( len( self.patchPath ) > 0 ):
self.linkPath = fixPath( self.patchPath + "/" + self.alias + "/" + self.__userInput )
else:
self.linkPath = fixPath( self.__userInput )
# check if installation where the link points to is ok
self.checkInstall(True)
# extract version from Path
self.version = basename( self.linkPath )
# now override installPath
newPath = self.parent.installPath + "/" + self.alias + "/" + self.version
self.installPath = fixPath( newPath )
mode = "use"
elif( mode == "use" ):
if( self.__userInput != "auto" ):
# 1st case: full path to installation is given
self.installPath = fixPath(self.__userInput)
# extract version from path
if( not hasattr(self, 'version') ):
self.version = basename( self.installPath )
# 2nd case: use( Mod( "vXX-XX" ) is given
if( not self.checkInstall() ):
self.version = self.__userInput
self.installPath = self.parent.installPath + "/" + self.alias + "/" + self.version
# 1st and 2nd cases failed:
if( not self.checkInstall() ):
print('failed to find', self.name, 'in', self.installPath)
# revert installPath back to user input
self.installPath = fixPath(self.__userInput)
self.version = basename( self.installPath )
# check if installed version is functional, abort otherwise
self.checkInstall(True)
self.buildPath = self.installPath + '/build'
self.mode = mode
def realPath(self):
""" returns the path where the module is actually living.
if module is in link mode the linkPath is returned
else the installPath is returned """
return (self.useLink and [self.linkPath] or [self.installPath])[0]
def init(self):
""" this method is called right after reading the configuration file and
before dependencies are checked """
# init logfile
self.logfile = self.parent.logfile
if( self.mode == "install" ):
# initialize download data
if( not self.download.supportHEAD and self.version == "HEAD" ):
self.abort( "sorry, HEAD version of this package cannot be installed!! " \
+ "Please choose a release version..." )
if( not self.download.type in self.download.supportedTypes ):
#if len(self.download.supportedTypes) != 1:
# print "*** WARNING: "+self.name+" download.type forced from \'"+self.download.type \
# + "\' to \'" + self.download.supportedTypes[0] + "\'"
self.download.type=self.download.supportedTypes[0]
if( self.download.type == "cvs" or self.download.type == "ccvssh" ):
if( not isinPath("cvs") ):
self.abort( "cvs not found!!" )
if( self.download.type == "cvs" ):
self.download.accessmode = "pserver"
if( self.download.type == "ccvssh" ):
if( not isinPath("ccvssh") ):
self.abort( "ccvssh not found!!" )
self.download.env.setdefault('CVS_RSH', 'ccvssh')
self.download.accessmode = "ext"
# if CVSROOT not set by user generate a default one
self.download.env.setdefault('CVSROOT', ":" + self.download.accessmode + ":" \
+ self.download.username + ":" + self.download.password \
+ "@" + self.download.server + ":/" + self.download.root )
elif( self.download.type == "wget" ):
if( not isinPath(self.download.cmd) ):
self.abort( self.download.cmd + " not found on your system!!" )
if( not isinPath("tar") ):
self.abort( "tar not found on your system!!" )
# if download url not set by user generate a default one
if( len(self.download.url) == 0 ):
if Version( self.version ) == 'HEAD':
dir='trunk'
elif '-pre' in self.version or '-dev' in self.version or '-exp' in self.version:
dir='branches/%s' % self.version
else:
dir='tags/%s' % self.version
self.download.url = "http://svnsrv.desy.de/viewvc/%s/%s/%s?view=tar" % ( self.download.root, self.download.project, dir )
elif ( self.download.type[:3] == "svn" ):
if( not isinPath("svn") ):
self.abort( "svn not found on your system!!" )
# if svnurl not set by user generate a default one
if( len(self.download.svnurl) == 0 ):
# initialize svn settings for desy
self.download.accessmode = "https"
self.download.server = "svnsrv.desy.de"
#if( self.download.username == "anonymous" ):
# self.download.root = "public/" + self.download.root
if( self.download.type == 'svn-desy' ):
self.download.root = "desy/" + self.download.root
elif( self.download.type == 'svn-p12cert' ):
self.download.root = "svn/" + self.download.root
else:
self.download.root = "public/" + self.download.root
self.download.svnurl = "%s://%s/%s/%s/" % (self.download.accessmode,self.download.server,self.download.root,self.download.project)
if Version( self.version ) == 'HEAD':
self.download.svnurl += 'trunk'
elif '-pre' in self.version or '-dev' in self.version or '-exp' in self.version:
self.download.svnurl += 'branches/'+self.version
else:
self.download.svnurl += 'tags/'+self.version
# git access to repository
elif ( self.download.type[:3] == "git" or self.download.type[:6] == "GitHub"):
if( not isinPath("git") ):
self.abort( "git not found on your system!!" )
# if svnurl not set by user generate a default one
if( len(self.download.svnurl) == 0 ):
# initialize svn settings for github
self.download.accessmode = "https"
self.download.server = "github.com"
self.download.root = self.download.project
self.download.svnurl = "%s://%s/%s/%s/" % (self.download.accessmode,self.download.server,self.download.root,self.download.project)
else:
self.abort( "download type " + self.download.type + " not recognized!!" )
def checkInstallConsistency(self):
""" check installation consistency """
# switch to use mode if already installed
if( self.mode == "install" and os.path.exists( self.installPath )):
if( os.path.exists( self.installPath + "/.install_failed.tmp" )):
self.rebuild = True
print(" + [%s] %s installation status: failed - set to rebuild" % \
(self.installPath, (55-len(self.installPath))*' '))
elif( not self.checkInstall() ):
print(" + [%s] %s installation status: incomplete" % \
(self.installPath, (55-len(self.installPath))*' '))
elif( self.rebuild ):
print(" + [%s] %s installation status: OK - rebuild flag set to true" % \
(self.installPath, (55-len(self.installPath))*' '))
else:
print(" + [%s] %s installation status: OK - set to use mode" % \
(self.installPath, (55-len(self.installPath))*' '))
#print " + %-55s installation status: OK - set to use mode" % \
# ('['+self.installPath+']',)
self.mode = "use"
def preCheckDeps(self):
""" called before running dependency check
useful for adding or removing dependencies based on
environment variables or some other setting """
# add cmake dependency
if( self.mode == "install" and self.hasCMakeBuildSupport ):
self.addExternalDependency( ["CMake" ] )
if self.name != "LCIO":
self.addExternalDependency( ["ILCUTIL" ] )
if "Boost" in self.reqmodules or "Boost" in self.optmodules:
boost = self.parent.module( "Boost" )
if boost and self.hasCMakeBuildSupport:
self.envcmake["BOOST_ROOT"]=boost.installPath
self.envcmake["Boost_NO_SYSTEM_PATHS"]=True
def postCheckDeps(self):
""" called after running dependency check
useful for checking version incompatibilities
or setting environment variables
also usefull for testing things that depend on
the install modus, since this can change in the
checkDeps phase """
if( self.mode == "install" ):
# check for make
if( not isinPath( "make" )):
self.abort( "make not found on your system!!" )
# check for tee
if( not isinPath( "tee" )):
self.abort( "tee not found on your system!!" )
def checkOptionalDependencies(self):
""" check dependencies for the installation
this is called right after the init method """
# skip dependency check for downloading only
if( self.downloadOnly ):
return
# soft dependencies
failed = []
for opt in self.optmodules:
mod = self.parent.module(opt)
if( mod == None ):
failed.append(opt)
# remove soft dependencies that were not found
self.buildWithout(failed)
def checkRequiredDependencies(self):
""" check for required dependencies """
# skip dependency check for downloading only
if( self.downloadOnly ):
return
# hard dependencies
for req in self.reqmodules:
if( self.parent.module(req) == None ):
# check if there is an auto detected module
if( self.parent.module(req, True) == None ):
self.abort( self.name + " requires " + req \
+ " and it wasn't found in your config file!!" )
else:
# use auto detected module
self.parent.use( self.parent.module(req, True) )
self.parent.module( req ).init()
print(self.name + ": auto-detected " + req + " version " + self.parent.module( req ).version)
# build only dependencies
if( self.mode == "install" ):
mods = self.reqmodules_buildonly + self.reqmodules_external
for req in mods:
if( self.parent.module(req) == None ):
# check if there is an auto detected module
if( self.parent.module(req, True) == None ):
self.abort( req + " not found in your config file!! " + self.name \
+ " cannot be built without " + req )
else:
# use auto detected module
self.parent.use( self.parent.module(req, True) )
self.parent.module( req ).init()
print(" - " + self.name + ": auto-detected " + req + " version " + self.parent.module( req ).version)
def checkDeps( self ):
""" check if a package needs to be rebuilt by checking the
versions of the dependencies used in the build process
against the versions defined in the configuration file
- returns True if test succeeds
- returns False if test fails """
# skip dependency check for downloading only
if( self.downloadOnly ):
return True
# skip dependency check if package is going to be installed
if( self.mode == "install" ):
return True
log.debug( 'Checking dependencies of %s', self.name )
file = self.realPath() + "/.dependencies"
r = True
# if file doesn't exist return True
if( not os.path.exists( file )):
return True
# open dependencies file
f = open( file )
filedeplist = {}
for line in f.readlines():
line = line.strip()
if( (not line.startswith(os.linesep)) and (not line.startswith("#")) \
and (len(line) > 0 )):
tokens = line.split(":")
filedeplist[ tokens[0] ] = tokens[1]
f.close()
log.debug( 'Dependencies read from file: %s', filedeplist )
# get actual dependecies
deplist={}
self.getDepList(deplist)
del deplist[self.name]
log.debug( 'Dependencies found in current cfg file: %s', deplist )
# compare dependencies
for k, v in filedeplist.items():
if( k in deplist):
if( deplist[k] != v ):
if( os.path.basename(deplist[k]) != os.path.basename(v) ):
if( r ):
print("*** WARNING: ***\n***\tFollowing dependencies from " + self.name + " located at [ " \
+ self.realPath() + " ] failed:\n***")
print("***\t * " + k + " " + os.path.basename(v) + " differs from version " \
+ os.path.basename(deplist[k]) + " defined in your config file..")
r = False
else:
if( r ): #just print this once
print("*** WARNING: ***\n***\tFollowing dependencies from " + self.name + " located at [ " + self.realPath() \
+ " ] failed:\n***")
print("***\t * " + k + " not found in your config file!!")
r = False
if( not r ):
print("***")
if( self.useLink ):
print("***\t" + self.name + " is in \"link\" mode, if you want to rebuild it with the new dependencies set it to \"use\" mode...")
r = True
else:
if( not self.parent.noAutomaticRebuilds ):
print("***\t * " + self.name + " changed to \"install\" mode and rebuild flag set to True...")
self.mode = "install"
self.rebuild = True
self.preCheckDeps()
print("***\n***\tUpdating dependency tree ( modules that depend on " + self.name + " need also to be rebuilt )...\n***")
self.updateDepTree([])
print("***\n***\tif you do NOT want to rebuild this module(s) just answer \"no\" later on in the installation process,\n" \
+ "***\tor set the global flag ilcsoft.noAutomaticRebuilds=True in your config file...")
else:
print("***\n***\tglobal flag ilcsoft.noAutomaticRebuilds is set to True, nothing will be done...\n***")
return r
def getDepList(self, dict):
""" helper function for getting a list of the dependencies
and their installPath for this module """
if( self.name in dict ):
return
else:
dict[ self.name ] = self.installPath
if( len( dict ) > 1 ):
mods = self.reqmodules + self.optmodules
else:
mods = self.reqmodules + self.optmodules + self.reqmodules_buildonly
for modname in mods:
if( self.parent.module(modname) != None ):
self.parent.module(modname).getDepList( dict )
def updateDepTree(self,checked):
""" updates the package dependency tree to ensure that every package
gets updated if one or more dependencies changes """
if( self.name in checked ):
return
else:
checked.append(self.name)
for mod in self.parent.modules:
if( mod.name != self.name ):
mods = mod.reqmodules + mod.optmodules + mod.reqmodules_buildonly
if( self.name in mods ):
if( mod.mode != "install" or not mod.rebuild ):
#if( mod.mode != "install" and not mod.rebuild ):
if( mod.useLink ):
print("***\t * WARNING: " + mod.name + " is in \"link\" mode, " \
+ "if you want to rebuild it with the new dependencies set it to \"use\" mode...!!")
else:
if( not self.parent.noAutomaticRebuilds ):
if( mod.mode != "install" ):
print("***\t * " + mod.name + " changed to \"install\" mode and rebuild Flag set to true!!")
mod.mode = "install"
mod.rebuild = True
mod.preCheckDeps()
mod.updateDepTree(checked)
def confirmRebuild( self ):
""" confirms rebuild of module """
if( self.mode == "install" and self.rebuild ):
input = ask_ok( self.name + " at [ " + self.installPath + " ] is going to be rebuild, are you sure? [y/n] " )
if( not input ):
self.mode = "use"
self.rebuild = False
def checkInstall(self, abort=False):
""" check if everything is ok for using this package (libraries, binaries, etc.).
If abort flag is set to True the installation aborts if a test fails.
- returns True if all tests succeed
- returns False if a test fails """
for i in self.reqfiles:
found = False
files = []
for j in i:
if( os.path.exists( self.realPath() + "/" + j )):
found = True
else:
files.append( self.realPath() + "/" + j )
if( not found ):
if( abort ):
if( len( files ) > 1 ):
self.abort( "At least one of these files: " + str(files) + "\n" \
+ "is required for using this installation of " + self.name )
else:
self.abort( "Required file not found: " + str(files) )
return False
return True
def updateSources(self):
""" update sources """
if Version( self.version ) == 'HEAD':
if 'svn' in self.download.type and not 'export' in self.download.type:
cmd = "svn update %s" % self.installPath
print(cmd)
if( os_system( cmd ) != 0 ):
self.abort( "error updating sources" )
elif 'git' in self.download.type:
cmd = "cd %s && git pull origin && cd -" % self.installPath
print(cmd)
if( os_system( cmd ) != 0 ):
self.abort( "error updating sources" )
def downloadSources(self):
""" download sources """
# create install base directory
trymakedir( os.path.dirname( self.installPath ))
os.chdir( os.path.dirname(self.installPath) )
if( self.download.type == "cvs" or self.download.type == "ccvssh" ):
# set env
for k, v in self.download.env.items():
os.environ[k] = v
cvsroot=os.environ["CVSROOT"]
# CVSROOT with pass example:
# :ext:engels:****@cvssrv.ifh.de:/ilctools
# CVSROOT without pass example:
# :ext:[email protected]:/ilctools
# entries in ~/.cvspass
# :pserver:[email protected]:2405/ilctools
i1 = cvsroot.find("@")
# check if there is a password coded in $CVSROOT
if( cvsroot.count(":",0,i1) == 3 ):
i2=cvsroot.rfind(':',0,i1)
cvsroot_nopass = cvsroot[:i2]+cvsroot[i1:]
# use default
else:
cvsroot_nopass = cvsroot
# dirty hack (but works ;)
i2=cvsroot_nopass.rfind(':',0,i1)
i4=cvsroot_nopass.rfind(':')+1
if( os_system( 'grep "'+cvsroot_nopass[i2:i4]+'[0-9]*'+cvsroot_nopass[i4:]+'" ~/.cvspass &>/dev/null' ) != 0 ):
print("logging in to cvs server...")
if( os_system( self.download.type + " login" ) != 0 ):
self.abort( "Problems ocurred downloading sources ("+self.download.type+" login)!!")
else:
print("password found in ~/.cvspass, will skip login...")
os.environ["CVSROOT"] = cvsroot_nopass
# checkout sources
print("checking out sources...")
if( self.version == "HEAD" ):
if( os_system( "cvs co -d " + self.version + " " + self.download.project ) != 0 ):
self.abort( "Problems ocurred downloading sources with "+self.download.type+"!!")
else:
if( os_system( "cvs co -d " + self.version + " -r " + self.version + " " + self.download.project ) != 0 ):
self.abort( "Problems ocurred downloading sources with "+self.download.type+"!!")
elif( self.download.type[:3] == "svn" ):
if( self.download.type == "svn-export" ):
svncmd = "svn export"
else:
svncmd = "svn checkout"
if( self.version == "HEAD" ):
cmd="%s %s HEAD" % (svncmd, self.download.svnurl)
else:
cmd="%s %s %s" % (svncmd, self.download.svnurl, self.version)
print("svn download cmd:",cmd)
if( os_system( cmd ) != 0 ):
self.abort( "Problems ocurred downloading sources with "+self.download.type+"!!")
elif( self.download.type[:3] == "git" ):
# defaults to clone
gitcmd = "git clone"
cmd="%s %s %s" % (gitcmd, self.download.svnurl, self.version)
print("git download cmd:",cmd)
if( os_system( cmd ) != 0 ):
self.abort( "Problems occurred downloading sources with "+self.download.type+"!!")
gittagcmd="cd %s && git checkout %s && cd -" % (self.version, self.version)
print("git checkout tag cmd:",gittagcmd)
if( os_system( gittagcmd ) != 0 ):
self.abort( "Problems occurred checking out tag "+self.version+"!!")
elif self.download.type[:6] == "GitHub":
if self.version =="HEAD" or self.version =="dev" or self.version =="devel" or self.version =="master" or self.download.branch:
#clone the whole repo into the directory
branch = 'master' if self.download.branch is None else self.download.branch
cmd="git clone -b %s https://github.com/%s/%s.git %s" % (branch, self.download.gituser, self.download.gitrepo, self.version)
print("Executing command:",cmd)
if os_system( cmd ) != 0:
self.abort( "Problems occurred during execution of " + cmd + " [!!ERROR!!]")
print("Cloning of repository %s/%s into directory %s sucessfully finished" % (self.download.gituser, self.download.gitrepo, self.version))
elif 'message' not in list(json.loads(urlopen('https://api.github.com/repos/%s/%s/git/refs/tags/%s' % (self.download.gituser, self.download.gitrepo, self.version)).read()).keys()):
cmd = "mkdir -p %s" % (self.version)
if os_system( cmd ) != 0:
self.abort( "Could not create folder" + self.version + " [!!ERROR!!]")
cmd = "curl -L -k https://api.github.com/repos/%s/%s/tarball/refs/tags/%s | tar xz --strip-components=1 -C %s" % (self.download.gituser, self.download.gitrepo, self.version, self.version)
if os_system( cmd ) != 0:
self.abort( "Could not download and extract tag " + self.version + " [!!ERROR!!]")
print("Downloading of the tag %s of repository %s/%s into directory %s sucessfully finished" % (self.version, self.download.gituser, self.download.gitrepo, self.version))
else:
self.abort( "The specified tag " + self.version + " does not exist [!!ERROR!!]")
elif( self.download.type == "wget" ):
# name of the tarball file
self.download.tarball = self.download.project + "_" + self.version + ".tgz"
if self.download.cmd == "wget":
dopt='O'
else:
dopt='o'
if( os_system( '%s "%s" -%s %s' % (self.download.cmd, self.download.url, dopt, self.download.tarball) ) != 0 ):
self.abort( "Problems ocurred downloading sources!!")
if( not os.path.exists( "./" + self.download.tarball) ):
self.abort( "Problems ocurred downloading sources!!")
# find out directory inside tarball
os_system("tar -tzf " + self.download.tarball + " > tarlist.tmp")
self.download.tardir = getoutput( "head -n1 tarlist.tmp" ).strip()
os.unlink( "tarlist.tmp" )
# extract the root directory from the directory tree
if( self.download.tardir.find('/') != -1 ):
self.download.tardir = self.download.tardir[:self.download.tardir.find('/')]
# unpack tarball
print("+ Unpacking " + self.download.tarball)
os_system( "tar -xzvf " + self.download.tarball )
tryrename( self.download.tardir, self.version )
if( self.hasCMakeBuildSupport and not self.skipCompile ):
trymakedir( self.version + "/build" )
def cleanupInstall(self):
""" clean up temporary files used for the installation """
os.chdir( os.path.dirname(self.installPath) )
tryunlink( self.download.tarball )
def createLink(self):
""" if package is to be linked only """
if( self.useLink ):
trymakedir( self.parent.installPath + "/" + self.alias )
os.chdir( self.parent.installPath + "/" + self.alias )
# check for already existing symlinks or dirs
if( os.path.islink( self.version )):
os.unlink( self.version )
elif( os.path.isdir( self.version )):
self.abort( "could not create link to [ " + self.linkPath + " ]\nin [ " \
+ os.path.basename( self.installPath ) + " ]!!!" )
os.symlink( self.linkPath , self.version )
print("+ Linking " + self.parent.installPath + "/" + self.alias + "/" + self.version \
+ " -> " + self.linkPath)
def compile(self):
""" method used for compiling module.
does nothing in the base class """
print("+ Nothing to be done ;)")
def install(self, installed=[]):
""" install this module """
# install
if( self.mode == "install" and not self.downloadOnly ):
# resolve circular dependencies
if( self.name in installed ):
return
else:
installed.append( self.name )
# install dependencies if there are any to be installed
mods = self.reqmodules + self.reqmodules_buildonly + self.reqmodules_external + self.optmodules
for modname in mods:
mod = self.parent.module(modname)
mod.install(installed)
print(80*'#' + "\n##### Compiling " + self.name + " version " + self.version + "...\n" + 80*'#')
# create install directory if it hasn't already been created
trymakedir( self.installPath )
# write environment to file
self.writeLocalEnv()
# set environment
self.setEnv(self, [])
# write snapshot of environment to logfile for debugging
os_system( "echo \"" + 100*'#' + "\" >> " + self.logfile )
os_system( "echo \"" + 10*'#' + " BUILDING " + self.name + "\" >> " + self.logfile )
os_system( "echo \"" + 100*'#' + "\" >> " + self.logfile )
os_system( "echo \"" + 5*'-' + " ENVIRONMENT SNAPSHOT " + 5*'-' + "\" >> " + self.logfile )
os_system( "env >> " + self.logfile )
os_system( "echo \"" + 5*'-' + " END OF ENVIRONMENT SNAPSHOT " + 5*'-' + "\" >> " + self.logfile )
os_system( "touch " + self.installPath + "/.install_failed.tmp" )
# compile module
if( not self.skipCompile ):
if( self.hasCMakeBuildSupport ):
#self.setCMakeVars(self,[])
print("+ Generated cmake build command:")
print(' $ ', self.genCMakeCmd())
print(os.linesep)
self.compile()
os_system( "echo \"" + 100*'#' + "\" >> " + self.logfile )
os_system( "echo \"" + 10*'#' + " FINISHED BUILDING " + self.name + "\" >> " + self.logfile )
os_system( "echo \"" + 100*'#' + "\" >> " + self.logfile )
# set the module to use mode
self.mode = "use"
# just to check if the library was created successfully
self.checkInstall(True)
os.unlink( self.installPath + "/.install_failed.tmp" )
# write dependencies to file
self.writeLocalDeps()
if( self.cleanInstall ):
self.cleanupInstall()
# unset environment
self.unsetEnv([])
def previewinstall(self, installed=[]):
""" preview installation of this module """
if( self.mode == "install"):
# resolve circular dependencies
if( self.name in installed ):
return
else:
installed.append( self.name )
print("\n" + 20*'-' + " Starting " + self.name + " Installation Test " + 20*'-' + '\n')
# additional modules
mods = self.optmodules + self.reqmodules + self.reqmodules_external + self.reqmodules_buildonly
if( len(mods) > 0 ):
for modname in mods:
mod = self.parent.module(modname)
if( mod.mode == "install" and not mod.name in installed ):
print("+ " + self.name + " will launch installation of " + mod.name)
mod.previewinstall(installed)
print("+ "+ self.name + " using " + mod.name + " at [ " + mod.installPath + " ]")
print("\n+ Environment Settings used for building " + self.name + ":")
# print environment settings recursively
self.setEnv(self, [], True )
if( self.hasCMakeBuildSupport ):
#self.setCMakeVars(self, [])
print("\n+ Generated CMake command for building " + self.name + ":")
print(' $ ',self.genCMakeCmd())
print("\n+ " + self.name + " installation finished.")
print('\n' + 20*'-' + " Finished " + self.name + " Installation Test " + 20*'-' + '\n')
def showDependencies(self, installed=[]):
""" preview installation of this module """
if( self.mode == "install"):
# resolve circular dependencies
if( self.name in installed ):
return
else:
installed.append( self.name )
print(self.name + "[color=orange1, fontcolor=white, label=\"" + self.name + "\"shape=rectangle];")
# additional modules
mods = self.optmodules + self.reqmodules + self.reqmodules_external + self.reqmodules_buildonly
if( len(mods) > 0 ):
for modname in mods:
mod = self.parent.module(modname)
# if( mod.mode == "install" and not mod.name in installed ):
# print "+ " + self.name + " will launch installation of " + mod.name
# mod.previewinstall(installed)
print(self.name + " -> " + mod.name + ";")
# print "\n+ Environment Settings used for building " + self.name + ":"
# print environment settings recursively
# self.setEnv(self, [], True )
# if( self.hasCMakeBuildSupport ):
# #self.setCMakeVars(self, [])
# print "\n+ Generated CMake command for building " + self.name + ":"
# print ' $ ',self.genCMakeCmd()
#
# print "\n+ " + self.name + " installation finished."
# print '\n' + 20*'-' + " Finished " + self.name + " Installation Test " + 20*'-' + '\n'
def cmakeBoolOptionIsSet(self, opt):
""" checks if a cmake option is set """
if opt in self.envcmake:
val = str(self.envcmake.get(opt,""))
if val == "1" or val == "ON" or val == "YES":
return True
return False
def genCMakeCmd(self):
""" generates a CMake command out of envcmake """