xref: /petsc/config/PETSc/options/petscclone.py (revision 50f8d48f56e349a7ed87939c177100f77f552dab)
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):
21c3a89c15SBarry Smith    if os.path.exists(os.path.join(self.petscdir.dir,'lib','petsc','bin','maint')):
22c3a89c15SBarry Smith      self.logPrint('lib/petsc/bin/maint exists. This appears to be a repository clone')
239d310bb7SBarry Smith      self.isClone = 1
249d310bb7SBarry Smith      if os.path.exists(os.path.join(self.petscdir.dir, '.git')):
256e709e5aSBarry Smith        self.logPrint('.git directory exists')
269d310bb7SBarry Smith        if hasattr(self.sourceControl,'git'):
27*50f8d48fSJed Brown          (o1, e1, s1) = self.executeShellCommand([self.sourceControl.git, 'describe', '--match=v*'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
28*50f8d48fSJed Brown          (o2, e2, s2) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%H'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
29*50f8d48fSJed Brown          (o3, e3, s3) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%ci'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
30*50f8d48fSJed Brown          (o4, e4, s4) = self.executeShellCommand([self.sourceControl.git, 'branch'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3120a743a3SSatish Balay          if s2 or s3 or s4:
3220a743a3SSatish Balay            self.logPrintBox('***** WARNING: Git branch check is giving errors! Checking the repo with "git status"')
33*50f8d48fSJed Brown            (o5, e5, s5) = self.executeShellCommand([self.sourceControl.git, 'status'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3420a743a3SSatish Balay            self.logPrint(e5)
3520a743a3SSatish Balay          else:
3620a743a3SSatish Balay            if not o1: o1 = o2
3720a743a3SSatish Balay            self.addDefine('VERSION_GIT','"'+o1+'"')
3820a743a3SSatish Balay            self.addDefine('VERSION_DATE_GIT','"'+o3+'"')
3920a743a3SSatish Balay            try:
4020a743a3SSatish Balay              self.addDefine('VERSION_BRANCH_GIT','"'+re.compile('\* (.*)').search(o4).group(1)+'"')
4120a743a3SSatish Balay            except:
4220a743a3SSatish Balay              self.addDefine('VERSION_BRANCH_GIT','undetermined')
439d310bb7SBarry Smith        else:
449d310bb7SBarry Smith          self.logPrintBox('\n*****WARNING: PETSC_DIR appears to be a Git clone - but git is not found in PATH********\n')
459d310bb7SBarry Smith      else:
466e709e5aSBarry Smith        self.logPrint('This repository clone is obtained as a tarball as no .git dirs exist')
479d310bb7SBarry Smith    else:
486e709e5aSBarry Smith      if os.path.exists(os.path.join(self.petscdir.dir, '.git')):
499d310bb7SBarry Smith        raise RuntimeError('Your petsc source tree is broken. Use "git status" to check, or remove the entire directory and start all over again')
509d310bb7SBarry Smith      else:
519d310bb7SBarry Smith        self.logPrint('This is a tarball installation')
529d310bb7SBarry Smith    return
539d310bb7SBarry Smith
549d310bb7SBarry Smith  def configure(self):
559d310bb7SBarry Smith    self.executeTest(self.configureInstallationMethod)
569d310bb7SBarry Smith    return
57