19d310bb7SBarry Smithfrom __future__ import generators 29d310bb7SBarry Smithimport config.base 39d310bb7SBarry Smithimport os 49d310bb7SBarry Smith 59d310bb7SBarry Smithclass Configure(config.base.Configure): 69d310bb7SBarry Smith def __init__(self, framework): 79d310bb7SBarry Smith config.base.Configure.__init__(self, framework) 89d310bb7SBarry Smith self.headerPrefix = '' 99d310bb7SBarry Smith self.substPrefix = '' 104d9e5d0eSSatish Balay self.isprefix = False 115188cb68SSatish Balay self.dir = '' 129d310bb7SBarry Smith return 139d310bb7SBarry Smith 144d9e5d0eSSatish Balay def __str1__(self): 154d9e5d0eSSatish Balay if self.isprefix: 164d9e5d0eSSatish Balay return ' Prefix: ' + self.dir + '\n' 174d9e5d0eSSatish Balay else: 184d9e5d0eSSatish Balay return ' Prefix: <inplace installation>\n' 199d310bb7SBarry Smith 209d310bb7SBarry Smith def setupHelp(self, help): 219d310bb7SBarry Smith import nargs 229d310bb7SBarry Smith help.addArgument('PETSc', '-with-clean=<bool>', nargs.ArgBool(None, 0, 'Delete prior build files including externalpackages')) 239d310bb7SBarry Smith return 249d310bb7SBarry Smith 259d310bb7SBarry Smith def setupDependencies(self, framework): 269d310bb7SBarry Smith config.base.Configure.setupDependencies(self, framework) 275bb5b263SMatthew G. Knepley self.petscdir = framework.require('PETSc.options.petscdir', self) 289d310bb7SBarry Smith self.arch = framework.require('PETSc.options.arch', self) 299d310bb7SBarry Smith return 309d310bb7SBarry Smith 319d310bb7SBarry Smith def setInstallDir(self): 327b65ca21SBarry Smith '''Set installDir to either prefix or if that is not set to PETSC_DIR/PETSC_ARCH''' 339d310bb7SBarry Smith self.installSudo = '' 349d310bb7SBarry Smith if self.framework.argDB['prefix']: 354d9e5d0eSSatish Balay self.isprefix = True 364a08bad0SBarry Smith self.dir = os.path.abspath(os.path.expanduser(self.framework.argDB['prefix'])) 375188cb68SSatish Balay self.petscDir = self.dir 385188cb68SSatish Balay self.petscArch = '' 399d310bb7SBarry Smith try: 409d310bb7SBarry Smith os.makedirs(os.path.join(self.dir,'PETScTestDirectory')) 419d310bb7SBarry Smith os.rmdir(os.path.join(self.dir,'PETScTestDirectory')) 42be5c6b33SBarry Smith except Exception as e: 43*15229ffcSPierre Jolivet self.logPrint('Error trying to test write permissions on directory '+str(e)) 449d310bb7SBarry Smith self.installSudo = 'sudo ' 459d310bb7SBarry Smith else: 465bb5b263SMatthew G. Knepley self.dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 475188cb68SSatish Balay self.petscDir = self.petscdir.dir 485188cb68SSatish Balay self.petscArch = self.arch.arch 498ca03633SSatish Balay self.addMakeMacro('PREFIXDIR',self.dir) 505bb5b263SMatthew G. Knepley self.confDir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 519d310bb7SBarry Smith 529d310bb7SBarry Smith def configureInstallDir(self): 539d310bb7SBarry Smith '''Makes installDir subdirectories if it does not exist for both prefix install location and PETSc work install location''' 545bb5b263SMatthew G. Knepley dir = os.path.abspath(os.path.join(self.petscdir.dir, self.arch.arch)) 559d310bb7SBarry Smith if not os.path.exists(dir): 569d310bb7SBarry Smith os.makedirs(dir) 57af0996ceSBarry Smith for i in ['include','lib','bin',os.path.join('lib','petsc','conf')]: 589d310bb7SBarry Smith newdir = os.path.join(dir,i) 599d310bb7SBarry Smith if not os.path.exists(newdir): 609d310bb7SBarry Smith os.makedirs(newdir) 619d310bb7SBarry Smith if os.path.isfile(self.framework.argDB.saveFilename): 629d310bb7SBarry Smith os.remove(self.framework.argDB.saveFilename) 63af0996ceSBarry Smith confdir = os.path.join(dir,'lib','petsc','conf') 649d310bb7SBarry Smith self.framework.argDB.saveFilename = os.path.abspath(os.path.join(confdir, 'RDict.db')) 657ad10985SMatthew G. Knepley self.logPrint('Changed persistence directory to '+confdir) 669d310bb7SBarry Smith return 679d310bb7SBarry Smith 685004c6edSSatish Balay def cleanConfDir(self): 697b65ca21SBarry Smith '''Remove all the files from configuration directory for this PETSC_ARCH, from --with-clean option''' 709d310bb7SBarry Smith import shutil 715004c6edSSatish Balay if self.framework.argDB['with-clean'] and os.path.isdir(self.confDir): 72d1b3ee28SJacob Faibussowitsch self.logPrintWarning('"with-clean" is specified. Removing all build files from '+ self.confDir) 735004c6edSSatish Balay shutil.rmtree(self.confDir) 749d310bb7SBarry Smith return 759d310bb7SBarry Smith 769d310bb7SBarry Smith def saveReconfigure(self): 777b65ca21SBarry Smith '''Save the configure options in a script in PETSC_ARCH/lib/petsc/conf so the same configure may be easily re-run''' 78af0996ceSBarry Smith self.reconfigure_file = os.path.join(self.dir,'lib','petsc','conf','reconfigure-'+self.arch.arch+'.py') 799d310bb7SBarry Smith self.save_reconfigure_file = None 809d310bb7SBarry Smith if self.framework.argDB['with-clean'] and os.path.exists(self.reconfigure_file): 819d310bb7SBarry Smith self.save_reconfigure_file = '.save.reconfigure-'+self.arch.arch+'.py' 829d310bb7SBarry Smith try: 839d310bb7SBarry Smith if os.path.exists(self.save_reconfigure_file): os.unlink(self.save_reconfigure_file) 849d310bb7SBarry Smith os.rename(self.reconfigure_file,self.save_reconfigure_file) 855b6bfdb9SJed Brown except Exception as e: 869d310bb7SBarry Smith self.save_reconfigure_file = None 877ad10985SMatthew G. Knepley self.logPrint('error in saveReconfigure(): '+ str(e)) 889d310bb7SBarry Smith return 899d310bb7SBarry Smith 909d310bb7SBarry Smith def restoreReconfigure(self): 917b65ca21SBarry Smith '''If --with-clean was requested but restoring the reconfigure file was requested then restore it''' 929d310bb7SBarry Smith if self.framework.argDB['with-clean'] and self.save_reconfigure_file: 939d310bb7SBarry Smith try: 949d310bb7SBarry Smith os.rename(self.save_reconfigure_file,self.reconfigure_file) 955b6bfdb9SJed Brown except Exception as e: 967ad10985SMatthew G. Knepley self.logPrint('error in restoreReconfigure(): '+ str(e)) 979d310bb7SBarry Smith return 989d310bb7SBarry Smith 999d310bb7SBarry Smith def configure(self): 1009d310bb7SBarry Smith self.executeTest(self.setInstallDir) 1019d310bb7SBarry Smith self.executeTest(self.saveReconfigure) 1025004c6edSSatish Balay self.executeTest(self.cleanConfDir) 1039d310bb7SBarry Smith self.executeTest(self.configureInstallDir) 1049d310bb7SBarry Smith self.executeTest(self.restoreReconfigure) 1059d310bb7SBarry Smith return 106