Merge branch 'mysql'
[slapos.git] / component / kumo / kumo-hooks.py
1 import os
2 import sys
3 import traceback
4 from shutil import copy
5 from subprocess import Popen, PIPE
6
7 CONFIGURE_PATH = os.path.join('configure')
8 CONFIGURE_BACKUP_PATH = CONFIGURE_PATH + '_disabled'
9 # Fake configure, generating a fake Makefile which will create a marker file
10 # instead of actually installing anything.
11 # This is needed (?) to fetch --prefix from configure parameters, so we know
12 # where to tell Makefile to put the dummy file.
13 FAKE_CONFIGURE = '''#!%(python)s -S
14 import os
15 import sys
16 print 'Configuration is disabled on this host because %%s'
17 print 'Original configure file available at %(backup)s'
18 prefix = None
19 next = False
20 for arg in sys.argv:
21 if next:
22 prefix = arg
23 break
24 if arg.startswith('--prefix'):
25 if arg.startswith('--prefix='):
26 _, prefix = arg.split('=', 1)
27 break
28 next = True
29 if prefix is None:
30 raise '--prefix parameter not found'
31 # Generate Makefile with proper prefix
32 open('Makefile', 'w').write("""all:
33 \techo 'make disabled, see configure'
34
35 install:
36 \ttouch %%%%s""" %%%% (
37 os.path.join(prefix, 'BUILD_DISABLED_BY_BUILDOUT'),
38 ))
39 sys.exit(0)
40 ''' % {
41 'backup': CONFIGURE_BACKUP_PATH,
42 'python': sys.executable,
43 }
44
45 def pre_configure_hook(options, buildout):
46 gcc_executable = os.getenv('CC', 'gcc')
47 try:
48 gcc = Popen([gcc_executable, '-v'], stdout=PIPE, stderr=PIPE,
49 close_fds=True)
50 except OSError, (errno, _):
51 if errno == 2:
52 # No gcc installed, nothing to check
53 pass
54 else:
55 print 'Unexpected failure trying to detect gcc version'
56 traceback.print_exc()
57 else:
58 gcc.wait()
59 # Considered innocent until proven guilty.
60 error = None
61 for line in '\n'.join((gcc.stdout.read(), gcc.stderr.read())).splitlines():
62 if line.startswith('gcc version'):
63 if '4.1.1' in line and 'prerelease' in line:
64 # There is a bug in 4.1.1 prerelease (ie, as of mandriva
65 # 2007.0) g++ preventing kumo compilation from succeeding.
66 error = 'broken GCC version: %s' % (line, )
67 break
68 else:
69 print >>sys.stderr, 'GCC version could not be detected, ' \
70 'building anyway'
71 if error is not None:
72 print 'Disabling build, with reason:', error
73 # Copy to preserver permission
74 copy(CONFIGURE_PATH, CONFIGURE_BACKUP_PATH)
75 open(CONFIGURE_PATH, 'w').write(FAKE_CONFIGURE % (error, ))
76