1import config.base 2import os 3import re 4 5def noCheck(command, status, output, error): 6 ''' Do no check result''' 7 return 8 9class Configure(config.base.Configure): 10 def __init__(self, framework): 11 config.base.Configure.__init__(self, framework) 12 return 13 14 def setupDependencies(self, framework): 15 self.sourceControl = framework.require('config.sourceControl',self) 16 self.petscdir = framework.require('PETSc.options.petscdir', self) 17 return 18 19 def configureInstallationMethod(self): 20 '''Determine if PETSc was obtained via git or a tarball''' 21 if os.path.exists(os.path.join(self.petscdir.dir,'lib','petsc','bin','maint')): 22 self.logPrint('lib/petsc/bin/maint exists. This appears to be a repository clone') 23 if os.path.exists(os.path.join(self.petscdir.dir, '.git')): 24 self.logPrint('.git directory exists') 25 if hasattr(self.sourceControl,'git'): 26 (o1, e1, s1) = self.executeShellCommand([self.sourceControl.git, 'describe', '--match=v*'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir) 27 (o2, e2, s2) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%H'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir) 28 (o3, e3, s3) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%ci'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir) 29 (o4, e4, s4) = self.executeShellCommand([self.sourceControl.git, 'rev-parse', '--abbrev-ref', 'HEAD'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir) 30 (o5, e5, s5) = self.executeShellCommand([self.sourceControl.git, 'status', '--short', '-uno'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir) 31 if s2 or s3 or s4: 32 self.logPrintWarning('Git branch check is giving errors! Check configure.log for output from "git status"') 33 self.logPrint(e5) 34 else: 35 if not o1: o1 = o2 36 self.addDefine('VERSION_GIT','"'+o1+'"') 37 self.addDefine('VERSION_DATE_GIT','"'+o3+'"') 38 self.addDefine('VERSION_BRANCH_GIT','"'+o4+'"') 39 else: 40 self.logPrintWarning('PETSC_DIR appears to be a Git clone - but git is not found in PATH') 41 else: 42 self.logPrint('This repository clone is obtained as a tarball as no .git dirs exist') 43 else: 44 if os.path.exists(os.path.join(self.petscdir.dir, '.git')): 45 raise RuntimeError('Your PETSc source tree is broken. Use "git status" to check, or remove the entire directory and start all over again') 46 else: 47 self.logPrint('This is a tarball installation') 48 return 49 50 def configure(self): 51 self.executeTest(self.configureInstallationMethod) 52 return 53