xref: /petsc/config/configure.py (revision f6614063d88ec540034d811f8fe170b2ea42cd96)
15d5a5a7bSMatthew Knepley#!/usr/bin/env python
25d5a5a7bSMatthew Knepleyimport os
35d5a5a7bSMatthew Knepleyimport sys
44f8a5b45SBarry Smithimport commands
55d5a5a7bSMatthew Knepley
64b8aa89bSBarry Smith
7b26a8723SBarry Smithif not hasattr(sys, 'version_info') or not sys.version_info[1] >= 2:
832077d6dSBarry Smith  print '********* You must have Python version 2.2 or higher to run configure ***********'
932077d6dSBarry Smith  print '* Python is easy to install for end users or sys-admin. We urge you to upgrade  *'
1032077d6dSBarry Smith  print '*                   http://www.python.org/download/                             *'
1132077d6dSBarry Smith  print '*                                                                               *'
1232077d6dSBarry Smith  print '* You can configure PETSc manually BUT please, please consider upgrading python *'
1332077d6dSBarry Smith  print '* http://www.mcs.anl.gov/petsc/petsc-2/documentation/installation.html#Manual   *'
1432077d6dSBarry Smith  print '*********************************************************************************'
15b26a8723SBarry Smith  sys.exit(4)
162fb34ac0SMatthew Knepley
17*f6614063SBarry Smithclass RestartException:
18*f6614063SBarry Smith  def __init__(self,args):
19*f6614063SBarry Smith    self.args = args
20*f6614063SBarry Smith    return
21*f6614063SBarry Smith
224b8aa89bSBarry Smithdef getarch():
2364382af2SBarry Smith  if os.path.basename(sys.argv[0]).startswith('configure'): return ''
24b88bae4cSBarry Smith  else: return os.path.basename(sys.argv[0])[:-3]
254b8aa89bSBarry Smith
265d5a5a7bSMatthew Knepleydef petsc_configure(configure_options):
275fb2c094SBarry Smith  # use the name of the config/configure_arch.py to determine the arch
285fb2c094SBarry Smith  if getarch(): configure_options.append('-PETSC_ARCH='+getarch())
295fb2c094SBarry Smith
3087282423SMatthew Knepley  # Should be run from the toplevel
315d5a5a7bSMatthew Knepley  pythonDir = os.path.abspath(os.path.join('python'))
3287282423SMatthew Knepley  bsDir     = os.path.join(pythonDir, 'BuildSystem')
3387282423SMatthew Knepley  if not os.path.isdir(pythonDir):
345d5a5a7bSMatthew Knepley    raise RuntimeError('Run configure from $PETSC_DIR, not '+os.path.abspath('.'))
3587282423SMatthew Knepley  if not os.path.isdir(bsDir):
36d688700cSSatish Balay    print '''++ Could not locate BuildSystem in $PETSC_DIR/python.'''
37d688700cSSatish Balay    print '''++ Downloading it using "bk clone bk://sidl.bkbits.net/BuildSystem $PETSC_DIR/python/BuildSystem"'''
384f8a5b45SBarry Smith    (status,output) = commands.getstatusoutput('bk clone bk://sidl.bkbits.net/BuildSystem python/BuildSystem')
397d7624c9SBarry Smith    if status:
407d7624c9SBarry Smith      if output.find('ommand not found') >= 0:
41d688700cSSatish Balay        print '''** Unable to locate bk (Bitkeeper) to download BuildSystem; make sure bk is in your path'''
42d688700cSSatish Balay        print '''** or manually copy BuildSystem to $PETSC_DIR/python/BuildSystem from a machine where'''
43d688700cSSatish Balay        print '''** you do have bk installed and can clone BuildSystem. '''
447d7624c9SBarry Smith      elif output.find('Cannot resolve host') >= 0:
45d688700cSSatish Balay        print '''** Unable to download BuildSystem. You must be off the network.'''
46d688700cSSatish Balay        print '''** Connect to the internet and run config/configure.py again.'''
477d7624c9SBarry Smith      else:
48d688700cSSatish Balay        print '''** Unable to download BuildSystem. Please send this message to petsc-maint@mcs.anl.gov'''
497d7624c9SBarry Smith      print output
5087282423SMatthew Knepley      sys.exit(3)
514f8a5b45SBarry Smith
5287282423SMatthew Knepley  sys.path.insert(0, bsDir)
535d5a5a7bSMatthew Knepley  sys.path.insert(0, pythonDir)
545d5a5a7bSMatthew Knepley  import config.framework
55f56be888SMatthew Knepley  import cPickle
564f8a5b45SBarry Smith
57*f6614063SBarry Smith  framework = []
5870ae1cd5SMatthew Knepley  try:
59*f6614063SBarry Smith    framework = while_petsc_configure(sys.argv[1:]+['-configModules=PETSc.Configure']+configure_options)
60358ebc22SMatthew Knepley    framework.storeSubstitutions(framework.argDB)
61f56be888SMatthew Knepley    framework.argDB['configureCache'] = cPickle.dumps(framework)
62dd50d019SBarry Smith    return 0
63e9f3bb17SBarry Smith  except RuntimeError, e:
6466b9a547SSatish Balay    msg = '***** Unable to configure with given options ***** (see configure.log for full details):\n' \
65d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
66e9f3bb17SBarry Smith    se = ''
671a02243aSBarry Smith  except TypeError, e:
6866b9a547SSatish Balay    msg = '***** Error in command line argument to configure.py *****\n' \
69d688700cSSatish Balay    +str(e)+'\n******************************************************\n'
701a02243aSBarry Smith    se = ''
71d7d3c4beSMatthew Knepley  except SystemExit, e:
72d7d3c4beSMatthew Knepley    if e.code is None or e.code == 0:
73d7d3c4beSMatthew Knepley      return
74d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
75d7d3c4beSMatthew Knepley    se  = str(e)
76e9f3bb17SBarry Smith  except Exception, e:
77d688700cSSatish Balay    msg = '*** CONFIGURATION CRASH **** Please send configure.log to petsc-maint@mcs.anl.gov\n'
78e9f3bb17SBarry Smith    se  = str(e)
79e9f3bb17SBarry Smith
80e9f3bb17SBarry Smith  print msg
81e9f3bb17SBarry Smith  if hasattr(framework, 'log'):
82e9f3bb17SBarry Smith    framework.log.write(msg+se)
83*f6614063SBarry Smith    file = framework.log
84*f6614063SBarry Smith  else:
85*f6614063SBarry Smith    print se
86*f6614063SBarry Smith    file = sys.stdout
87*f6614063SBarry Smith  import traceback
88*f6614063SBarry Smith  traceback.print_tb(sys.exc_info()[2], file = file)
89e9f3bb17SBarry Smith  sys.exit(1)
905d5a5a7bSMatthew Knepley
91*f6614063SBarry Smith
92*f6614063SBarry Smithdef while_petsc_configure(args):
93*f6614063SBarry Smith  import config.framework
94*f6614063SBarry Smith  while 1:
95*f6614063SBarry Smith    framework = config.framework.Framework(args, loadArgDB = 0)
96*f6614063SBarry Smith    try:
97*f6614063SBarry Smith      framework.configure(out = sys.stdout)
98*f6614063SBarry Smith      break
99*f6614063SBarry Smith    except RestartException, e:
100*f6614063SBarry Smith      # ugly crap; merge additional args
101*f6614063SBarry Smith      for j in e.args:
102*f6614063SBarry Smith        found = 0
103*f6614063SBarry Smith        for i in len(args):
104*f6614063SBarry Smith          if args[i].startswith(j):
105*f6614063SBarry Smith            args[i] += ' '+e.args[j]
106*f6614063SBarry Smith            found = 1
107*f6614063SBarry Smith            break
108*f6614063SBarry Smith        if not found:
109*f6614063SBarry Smith          args.append(j+'='+e.args[j])
110*f6614063SBarry Smith      args.append('-logAppend=1')
111*f6614063SBarry Smith  return framework
112*f6614063SBarry Smith
1135d5a5a7bSMatthew Knepleyif __name__ == '__main__':
114a030c540SBarry Smith  petsc_configure([])
115759acf64SBarry Smith
116