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! Checking the repo with "git status"') 35 (o5, e5, s5) = self.executeShellCommand([self.sourceControl.git, 'status'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir) 36 self.logPrint(e5) 37 else: 38 if not o1: o1 = o2 39 self.addDefine('VERSION_GIT','"'+o1+'"') 40 self.addDefine('VERSION_DATE_GIT','"'+o3+'"') 41 self.addDefine('VERSION_BRANCH_GIT','"'+o4+'"') 42 else: 43 self.logPrintWarning('PETSC_DIR appears to be a Git clone - but git is not found in PATH') 44 else: 45 self.logPrint('This repository clone is obtained as a tarball as no .git dirs exist') 46 else: 47 if os.path.exists(os.path.join(self.petscdir.dir, '.git')): 48 raise RuntimeError('Your petsc source tree is broken. Use "git status" to check, or remove the entire directory and start all over again') 49 else: 50 self.logPrint('This is a tarball installation') 51 return 52 53 def configure(self): 54 self.executeTest(self.configureInstallationMethod) 55 return 56