1import config.package 2import os 3 4class Configure(config.package.GNUPackage): 5 def __init__(self, framework): 6 config.package.GNUPackage.__init__(self, framework) 7 self.hghash = '611092f80ddb' 8 self.download = ['hg://https://bitbucket.org/pflotran/pflotran-dev'] 9 self.functions = [] 10 self.includes = [] 11 self.hastests = 1 12 self.fc = 1 # 1 means requires fortran 13 self.linkedbypetsc = 0 14 return 15 16 def setupDependencies(self, framework): 17 config.package.GNUPackage.setupDependencies(self, framework) 18 self.petscdir = framework.require('PETSc.options.petscdir', self.setCompilers) 19 self.mpi = framework.require('config.packages.MPI', self) 20 self.hdf5 = framework.require('config.packages.hdf5', self) 21 self.deps = [self.mpi, self.hdf5] 22 return 23 24 def Install(self): 25 return self.installDir 26 27 def configureLibrary(self): 28 ''' Just assume the downloaded library will work''' 29 if self.framework.clArgDB.has_key('with-pflotran'): 30 raise RuntimeError('Pflotran does not support --with-pflotran; only --download-pflotran') 31 if self.framework.clArgDB.has_key('with-pflotran-dir'): 32 raise RuntimeError('Pflotran does not support --with-pflotran-dir; only --download-pflotran') 33 if self.framework.clArgDB.has_key('with-pflotran-include'): 34 raise RuntimeError('Pflotran does not support --with-pflotran-include; only --download-pflotran') 35 if self.framework.clArgDB.has_key('with-pflotran-lib'): 36 raise RuntimeError('Pflotran does not support --with-pflotran-lib; only --download-pflotran') 37 if self.framework.clArgDB.has_key('with-pflotran-shared'): 38 raise RuntimeError('Pflotran does not support --with-pflotran-shared') 39 40 self.checkDownload() 41 self.include = [os.path.join(self.installDir,'include')] 42 self.lib = [os.path.join(self.installDir,'lib','libpflotranchem.a')] 43 self.found = 1 44 self.dlib = self.lib 45 if not hasattr(self.framework, 'packages'): 46 self.framework.packages = [] 47 self.framework.packages.append(self) 48 49 def compilePETSc(self): 50 try: 51 self.logPrintBox('Compiling PETSc; this may take several minutes') 52 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+self.petscdir.dir+' && '+self.make.make+' all PETSC_DIR='+self.petscdir.dir+' PETSC_ARCH='+self.arch,timeout=1000, log = self.log) 53 self.log.write(output+err) 54 except RuntimeError, e: 55 raise RuntimeError('Error running make all on PETSc: '+str(e)) 56 if self.framework.argDB['prefix']: 57 try: 58 self.logPrintBox('Installing PETSc; this may take several minutes') 59 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+self.petscdir.dir+' && '+self.installDirProvider.installSudo+self.make.make+' install PETSC_DIR='+self.petscdir.dir+' PETSC_ARCH='+self.arch,timeout=50, log = self.log) 60 self.log.write(output+err) 61 except RuntimeError, e: 62 raise RuntimeError('Error running make install on PETSc: '+str(e)) 63 elif not self.argDB['with-batch']: 64 try: 65 self.logPrintBox('Testing PETSc; this may take several minutes') 66 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+self.petscdir.dir+' && '+self.make.make+' test PETSC_DIR='+self.petscdir.dir+' PETSC_ARCH='+self.arch,timeout=50, log = self.log) 67 output = output+err 68 self.log.write(output) 69 if output.find('error') > -1 or output.find('Error') > -1: 70 raise RuntimeError('Error running make test on PETSc: '+output) 71 except RuntimeError, e: 72 raise RuntimeError('Error running make test on PETSc: '+str(e)) 73 74 def postProcess(self): 75 self.compilePETSc() 76 77 # Patch the PETSc paths so that older versions of PFlotran can find Fortran include files and configuration files 78 try: 79 if not os.path.isdir(os.path.join(self.petscdir.dir,'include','finclude')): 80 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+os.path.join(self.petscdir.dir,'include')+' && ln -s petsc/finclude finclude',timeout=10, log = self.log) 81 if not os.path.isdir(os.path.join(self.petscdir.dir,'conf')): 82 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+self.petscdir.dir+' && ln -s lib/petsc/conf conf',timeout=10, log = self.log) 83 except RuntimeError, e: 84 raise RuntimeError('Unable to make links required by older versions of PFlotran') 85 try: 86 self.logPrintBox('Compiling Pflotran; this may take several minutes') 87 # uses the regular PETSc library builder and then moves result 88 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+os.path.join(self.packageDir,'src','pflotran')+' && '+self.make.make+' have_hdf5=1 use_matseqaij_fix=1 PETSC_DIR='+self.petscdir.dir+' PETSC_ARCH='+self.arch+' libpflotranchem.a',timeout=1000, log = self.log) 89 self.log.write(output+err) 90 self.logPrintBox('Installing Pflotran; this may take several minutes') 91 self.installDirProvider.printSudoPasswordMessage(1) 92 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+self.packageDir+' && '+self.installDirProvider.installSudo+'cp -f '+os.path.join('src','pflotran','libpflotran*.a')+' '+os.path.join(self.installDir,'lib'),timeout=1000, log = self.log) 93 self.log.write(output+err) 94 output,err,ret = config.package.GNUPackage.executeShellCommand('cd '+self.packageDir+' && '+self.installDirProvider.installSudo+'cp -f '+os.path.join('src','pflotran','*.mod')+' '+self.include[0],timeout=100, log = self.log) 95 self.log.write(output+err) 96 except RuntimeError, e: 97 raise RuntimeError('Error running make on Pflotran: '+str(e)) 98 99 100