@@ -5,18 +5,20 @@ from os.path import exists, abspath
5
5
from glob import glob
6
6
import yaml
7
7
from commands import getstatusoutput
8
+ import logging
9
+ from alibuild_helpers .log import debug , error , banner , info , success , warning
10
+ from alibuild_helpers .log import logger_handler , logger , LogFormatter , ProgressPrint
11
+ from alibuild_helpers .utilities import getPackageList , format , detectArch
8
12
import subprocess
9
13
10
- def execute (command , prefix ):
11
- print prefix + ":" + command .strip ("\n " )
14
+ def execute (command ):
12
15
popen = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
13
16
lines_iterator = iter (popen .stdout .readline , "" )
17
+ txt = ""
14
18
for line in lines_iterator :
15
- print prefix + ":" + line .strip ("\n " ) # yield line
16
- output = popen .communicate ()[0 ]
17
- for x in output .split ("\n " ):
18
- print prefix + ":" + output
19
- print prefix + ": exit code " + str (popen .returncode )
19
+ txt += line # yield line
20
+ txt += popen .communicate ()[0 ]
21
+ return (popen .returncode , txt )
20
22
21
23
def prunePaths (workDir ):
22
24
for x in ["PATH" , "LD_LIBRARY_PATH" , "DYLD_LIBRARY_PATH" ]:
@@ -25,10 +27,64 @@ def prunePaths(workDir):
25
27
workDirEscaped = re .escape ("%s" % workDir ) + "[^:]*:?"
26
28
os .environ [x ] = re .sub (workDirEscaped , "" , os .environ [x ])
27
29
30
+ def checkPreferSystem (spec , cmd , homebrew_replacement ):
31
+ if cmd == "false" :
32
+ debug ("Package %s can only be managed via alibuild." % spec ["package" ])
33
+ return (1 , "" )
34
+ cmd = homebrew_replacement + cmd
35
+ err , out = execute (cmd )
36
+ if not err :
37
+ success ("Package %s will be picked up from the system." % spec ["package" ])
38
+ for x in out .split ("\n " ):
39
+ debug (spec ["package" ] + ": " + x )
40
+ return (err , "" )
41
+
42
+ warning (format ("Package %(p)s cannot be picked up from the system and will be built by aliBuild.\n "
43
+ "This is due to the fact the following script fails:\n \n "
44
+ "%(cmd)s\n \n "
45
+ "with the following output:\n \n "
46
+ "%(error)s\n " ,
47
+ p = spec ["package" ],
48
+ cmd = cmd ,
49
+ error = "\n " .join (["%s: %s" % (spec ["package" ],x ) for x in out .split ("\n " )])))
50
+ return (err , "" )
51
+
52
+ def checkRequirements (spec , cmd , homebrew_replacement ):
53
+ if cmd == "false" :
54
+ debug ("Package %s is not a system requirement." % spec ["package" ])
55
+ return (0 , "" )
56
+ cmd = homebrew_replacement + cmd
57
+ err , out = execute (cmd )
58
+ if not err :
59
+ success ("Required package %s will be picked up from the system." % spec ["package" ])
60
+ debug (cmd )
61
+ for x in out .split ("\n " ):
62
+ debug (spec ["package" ] + ": " + x )
63
+ return (0 , "" )
64
+ error (format ("Package %(p)s is a system requirement and cannot be found.\n "
65
+ "This is due to the fact that the following script fails:\n \n "
66
+ "%(cmd)s\n "
67
+ "with the following output:\n \n "
68
+ "%(error)s\n "
69
+ "%(help)s\n " ,
70
+ p = spec ["package" ],
71
+ cmd = cmd ,
72
+ error = "\n " .join (["%s: %s" % (spec ["package" ],x ) for x in out .split ("\n " )]),
73
+ help = spec .get ("system_requirement_missing" )))
74
+ return (err , "" )
75
+
28
76
if __name__ == "__main__" :
29
77
parser = argparse .ArgumentParser ()
30
- parser .add_argument ("-c" , "--config" , help = "path to alidist" , dest = "config" , default = "alidist" )
31
- parser .add_argument ("-w" , "--work-dir" , help = "path to work dir" , dest = "workDir" , default = "workDir" )
78
+ parser .add_argument ("-a" , "--architecture" , help = "force architecture" ,
79
+ dest = "architecture" , default = detectArch ())
80
+ parser .add_argument ("-c" , "--config" , help = "path to alidist" ,
81
+ dest = "config" , default = "alidist" )
82
+ parser .add_argument ("-w" , "--work-dir" , help = "path to work dir" ,
83
+ dest = "workDir" , default = "workDir" )
84
+ parser .add_argument ("-d" , "--debug" , help = "Show also successful tests." ,
85
+ dest = "debug" , action = "store_true" , default = False )
86
+ parser .add_argument ("packages" , nargs = "+" , help = "Package to test" ,
87
+ default = [])
32
88
args = parser .parse_args ()
33
89
if not exists (args .config ):
34
90
parser .error ("Wrong path to alidist specified: %s" % args .config )
@@ -37,16 +93,49 @@ if __name__ == "__main__":
37
93
38
94
# Decide if we can use homebrew. If not, we replace it with "true" so
39
95
# that we do not get spurious messages on linux
40
- homebrew_replacement = "brew "
96
+ homebrew_replacement = ""
41
97
err , output = getstatusoutput ("which brew" )
42
98
if err :
43
- homebrew_replacement = "true"
44
-
45
- for x in glob ("%s/*.sh" % args .config ):
46
- print "Reading" , x
47
- txt = file (x ).read ()
48
- header , body = txt .split ("---" , 1 )
49
- spec = yaml .safe_load (header )
50
- if "prefer_system_check" in spec :
51
- execute (spec ["prefer_system_check" ].replace ("brew" , homebrew_replacement ),
52
- spec ["package" ])
99
+ homebrew_replacement = "brew() { true; }; "
100
+
101
+ logger .setLevel (logging .BANNER )
102
+ if args .debug :
103
+ logger .setLevel (logging .DEBUG )
104
+
105
+ specs = {}
106
+ packages = []
107
+ for p in args .packages :
108
+ path = "%s/%s.sh" % (args .config , p .lower ())
109
+ if not exists (path ):
110
+ error ("Cannot find recipe %s for package %s." % (path , p ))
111
+ continue
112
+ packages .append (p )
113
+
114
+ specs = {}
115
+ def unreachable ():
116
+ assert (False )
117
+ (fromSystem , own , failed ) = getPackageList (packages = packages ,
118
+ specs = specs ,
119
+ configDir = args .config ,
120
+ preferSystem = False ,
121
+ noSystem = False ,
122
+ architecture = args .architecture ,
123
+ disable = [],
124
+ defaults = "release" ,
125
+ dieOnError = lambda x , y : unreachable ,
126
+ performPreferCheck = lambda pkg , cmd : checkPreferSystem (pkg , cmd , homebrew_replacement ),
127
+ performRequirementCheck = lambda pkg , cmd : checkRequirements (pkg , cmd , homebrew_replacement ))
128
+
129
+ if fromSystem :
130
+ banner ("The following packages will be picked up from the system:\n \n - " +
131
+ "\n - " .join (fromSystem ) +
132
+ "\n \n If this is not you want, you have to uninstall / unload them." )
133
+ if own :
134
+ banner ("The following packages will be build by aliBuild because they couldn't be picked up from the system:\n \n - " +
135
+ "\n - " .join (own ) +
136
+ "\n \n This is not a real issue, but it might take longer the first time you invoke aliBuild." )
137
+ if failed :
138
+ banner ("The following packages are system dependencies and could not be found:\n \n - " +
139
+ "\n - " .join (failed )
140
+ )
141
+ exit (1 )
0 commit comments