xref: /petsc/config/BuildSystem/config/preTests.py (revision e366c154b69cf29c88be23f768f0f07dd2b3250c)
1'''
2This module tests features so broken, that he normal test apparatus is likely
3o fail. For example, there are several buggy implementations of Python, we can
4recognize and work around.
5'''
6import os, sys
7
8class Configure:
9  '''These test must run before almost any operations
10  - We maintain an internal self.log array of strings so that normal logging need not be initialized
11  '''
12  def __init__(self, options = {}, convertOptions = False):
13    self.options        = options
14    self.convertOptions = convertOptions
15    self.log            = []
16    return
17
18  def checkCygwin(self):
19    '''Check for versions of Cygwin below 1.5.11-1
20    These version have a known bug in the Python threads module
21    '''
22    if os.path.exists('/usr/bin/cygcheck.exe'):
23      buf = os.popen('/usr/bin/cygcheck.exe -c cygwin').read()
24      if buf.find('1.5.11-1') > -1:
25        return 1
26      else:
27        return 0
28    return 0
29
30  def checkCygwinPython(self):
31    '''Check for versions of Cygwin Python 2.4 and above
32    These version have a known bug in the Python threads module
33    '''
34    if os.path.exists('/usr/bin/cygcheck.exe'):
35      buf = os.popen('/usr/bin/cygcheck.exe -c python').read()
36      if buf.find('2.4') > -1:
37        return 1
38    return 0
39
40  def checkRedHat9(self):
41    '''Check for Redhat 9
42    This version have a known bug in the Python threads module
43    '''
44    try:
45      file = open('/etc/redhat-release','r')
46    except:
47      return 0
48    try:
49      buf = file.read()
50      file.close()
51    except:
52      # can't read file - assume dangerous RHL9
53      return 1
54    if buf.find('Shrike') > -1:
55      return 1
56    return 0
57
58  def checkThreads(self):
59    '''Check Python threading'''
60    if self.checkCygwin():
61      errorMsg = '''\
62      =================================================================================
63       *** cygwin-1.5.11-1 detected. configure.py fails with this version ***
64       *** Please upgrade to cygwin-1.5.12-1 or newer version. This can   ***
65       *** be done by running cygwin-setup, selecting "next" all the way. ***
66      ================================================================================='''
67      sys.exit(errorMsg)
68    if self.checkRedHat9():
69      sys.argv.append('--useThreads=0')
70      self.log.append('''\
71================================================================================
72   *** RHL9 detected. Threads do not work correctly with this distribution ***
73    ********* Disabling thread usage for this run of configure.py ***********
74================================================================================''')
75      if self.checkCygwinPython():
76        sys.argv.append('--useThreads=0')
77        self.log.append('''\
78================================================================================
79** Cygwin-python-2.4 detected. Threads do not work correctly with this version *
80 ********* Disabling thread usage for this run of configure.py ****************
81================================================================================''')
82    return
83
84  def checkOptions(self, options, convertOptions = False):
85    '''Check for some initial options, and optionally give them default values
86    - If convertOptions is true, process GNU options prefixes into our canonical form
87    '''
88    import nargs
89
90    if convertOptions:
91      nargs.Arg.processAlternatePrefixes(sys.argv)
92    for name, defaultArg in options.items():
93      if nargs.Arg.findArgument(name,sys.argv) is None:
94        if defaultArg:
95          sys.argv.append('%s=%s' % name, str(defaultArg))
96    return
97
98  def configure(self):
99    self.checkThreads()
100    self.checkOptions(self.options, self.convertOptions)
101    return
102