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