xref: /petsc/config/PETSc/options/petscclone.py (revision 7b65ca21b2b9b366f4246f381bb20ef06298501e)
19d310bb7SBarry Smithimport config.base
29d310bb7SBarry Smithimport os
39d310bb7SBarry Smithimport re
49d310bb7SBarry Smith
520a743a3SSatish Balaydef noCheck(command, status, output, error):
620a743a3SSatish Balay  ''' Do no check result'''
720a743a3SSatish Balay  return
820a743a3SSatish Balay
99d310bb7SBarry Smithclass Configure(config.base.Configure):
109d310bb7SBarry Smith  def __init__(self, framework):
119d310bb7SBarry Smith    config.base.Configure.__init__(self, framework)
1220a743a3SSatish Balay    self.isClone = 0
139d310bb7SBarry Smith    return
149d310bb7SBarry Smith
159d310bb7SBarry Smith  def setupDependencies(self, framework):
169d310bb7SBarry Smith    self.sourceControl = framework.require('config.sourceControl',self)
179d310bb7SBarry Smith    self.petscdir = framework.require('PETSc.options.petscdir', self)
189d310bb7SBarry Smith    return
199d310bb7SBarry Smith
209d310bb7SBarry Smith  def configureInstallationMethod(self):
21*7b65ca21SBarry Smith    '''Determine if PETSc was obtained via git or a tarball'''
22c3a89c15SBarry Smith    if os.path.exists(os.path.join(self.petscdir.dir,'lib','petsc','bin','maint')):
23c3a89c15SBarry Smith      self.logPrint('lib/petsc/bin/maint exists. This appears to be a repository clone')
249d310bb7SBarry Smith      self.isClone = 1
259d310bb7SBarry Smith      if os.path.exists(os.path.join(self.petscdir.dir, '.git')):
266e709e5aSBarry Smith        self.logPrint('.git directory exists')
279d310bb7SBarry Smith        if hasattr(self.sourceControl,'git'):
2850f8d48fSJed Brown          (o1, e1, s1) = self.executeShellCommand([self.sourceControl.git, 'describe', '--match=v*'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
2950f8d48fSJed Brown          (o2, e2, s2) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%H'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3050f8d48fSJed Brown          (o3, e3, s3) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%ci'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3183f83e59SBarry Smith          (o4, e4, s4) = self.executeShellCommand([self.sourceControl.git, 'rev-parse', '--abbrev-ref', 'HEAD'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3220a743a3SSatish Balay          if s2 or s3 or s4:
33d1b3ee28SJacob Faibussowitsch            self.logPrintWarning('Git branch check is giving errors! Checking the repo with "git status"')
3450f8d48fSJed Brown            (o5, e5, s5) = self.executeShellCommand([self.sourceControl.git, 'status'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3520a743a3SSatish Balay            self.logPrint(e5)
3620a743a3SSatish Balay          else:
3720a743a3SSatish Balay            if not o1: o1 = o2
3820a743a3SSatish Balay            self.addDefine('VERSION_GIT','"'+o1+'"')
3920a743a3SSatish Balay            self.addDefine('VERSION_DATE_GIT','"'+o3+'"')
4083f83e59SBarry Smith            self.addDefine('VERSION_BRANCH_GIT','"'+o4+'"')
419d310bb7SBarry Smith        else:
42d1b3ee28SJacob Faibussowitsch          self.logPrintWarning('PETSC_DIR appears to be a Git clone - but git is not found in PATH')
439d310bb7SBarry Smith      else:
446e709e5aSBarry Smith        self.logPrint('This repository clone is obtained as a tarball as no .git dirs exist')
459d310bb7SBarry Smith    else:
466e709e5aSBarry Smith      if os.path.exists(os.path.join(self.petscdir.dir, '.git')):
479d310bb7SBarry Smith        raise RuntimeError('Your petsc source tree is broken. Use "git status" to check, or remove the entire directory and start all over again')
489d310bb7SBarry Smith      else:
499d310bb7SBarry Smith        self.logPrint('This is a tarball installation')
509d310bb7SBarry Smith    return
519d310bb7SBarry Smith
529d310bb7SBarry Smith  def configure(self):
539d310bb7SBarry Smith    self.executeTest(self.configureInstallationMethod)
549d310bb7SBarry Smith    return
55