1import config.base 2import os 3import re 4 5class Configure(config.base.Configure): 6 def __init__(self, framework): 7 config.base.Configure.__init__(self, framework) 8 self.headerPrefix = 'PETSC' 9 self.substPrefix = 'PETSC' 10 return 11 12 def __str1__(self): 13 if not hasattr(self, 'arch'): 14 return '' 15 desc = ['PETSc:'] 16 desc.append(' PETSC_ARCH: '+str(self.arch)) 17 return '\n'.join(desc)+'\n' 18 19 def setupHelp(self, help): 20 import nargs 21 help.addArgument('PETSc', '-PETSC_ARCH=<string>', nargs.Arg(None, None, 'The configuration name')) 22 help.addArgument('PETSc', '-with-petsc-arch=<string>',nargs.Arg(None, None, 'The configuration name')) 23 return 24 25 def setNativeArchitecture(self): 26 import sys 27 arch = 'arch-' + sys.platform.replace('cygwin','mswin') 28 # use opt/debug, c/c++ tags.s 29 arch+= '-'+self.framework.argDB['with-clanguage'].lower().replace('+','x') 30 if self.framework.argDB['with-debugging']: 31 arch += '-debug' 32 else: 33 arch += '-opt' 34 self.nativeArch = arch 35 return 36 37 def configureArchitecture(self): 38 '''Checks PETSC_ARCH and sets if not set''' 39 # Warn if PETSC_ARCH doesnt match env variable 40 if 'PETSC_ARCH' in self.framework.argDB and 'PETSC_ARCH' in os.environ and self.framework.argDB['PETSC_ARCH'] != os.environ['PETSC_ARCH']: 41 self.logPrintBox('''\ 42Warning: PETSC_ARCH from environment does not match command-line or name of script. 43Warning: Using from command-line or name of script: %s, ignoring environment: %s''' % (str(self.framework.argDB['PETSC_ARCH']), str(os.environ['PETSC_ARCH']))) 44 os.environ['PETSC_ARCH'] = self.framework.argDB['PETSC_ARCH'] 45 if 'with-petsc-arch' in self.framework.argDB: 46 self.arch = self.framework.argDB['with-petsc-arch'] 47 msg = 'option -with-petsc-arch='+str(self.arch) 48 elif 'PETSC_ARCH' in self.framework.argDB: 49 self.arch = self.framework.argDB['PETSC_ARCH'] 50 msg = 'option PETSC_ARCH='+str(self.arch) 51 elif 'PETSC_ARCH' in os.environ: 52 self.arch = os.environ['PETSC_ARCH'] 53 msg = 'environment variable PETSC_ARCH='+str(self.arch) 54 else: 55 self.arch = self.nativeArch 56 if self.arch.find('/') >= 0 or self.arch.find('\\') >= 0: 57 raise RuntimeError('PETSC_ARCH should not contain path characters, but you have specified with '+msg) 58 if self.arch.startswith('-'): 59 raise RuntimeError('PETSC_ARCH should not start with "-", but you have specified with '+msg) 60 if self.arch.startswith('.'): 61 raise RuntimeError('PETSC_ARCH should not start with ".", but you have specified with '+msg) 62 if not len(self.arch): 63 raise RuntimeError('PETSC_ARCH cannot be empty string. Use a valid string or do not set one. Currently set with '+msg) 64 self.archBase = re.sub(r'^(\w+)[-_]?.*$', r'\1', self.arch) 65 return 66 67 def configure(self): 68 self.executeTest(self.setNativeArchitecture) 69 self.executeTest(self.configureArchitecture) 70 # required by top-level configure.py 71 self.framework.arch = self.arch 72 return 73