xref: /petsc/config/PETSc/options/petscclone.py (revision c3a89c15c66be42c1ea3c2eab6faebba95f76ffa)
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*c3a89c15SBarry Smith    if os.path.exists(os.path.join(self.petscdir.dir,'lib','petsc','bin','maint')):
22*c3a89c15SBarry 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'):
272c3da995SSatish Balay          (o1, e1, s1) = self.executeShellCommand('cd '+self.petscdir.dir+' && '+self.sourceControl.git+' describe --match "v*"',checkCommand = noCheck, log = self.log)
287908f030SMatthew G. Knepley          (o2, e2, s2) = self.executeShellCommand("cd "+self.petscdir.dir+" && "+self.sourceControl.git+" log -1 --pretty=format:%H",checkCommand = noCheck, log = self.log)
297908f030SMatthew G. Knepley          (o3, e3, s3) = self.executeShellCommand("cd "+self.petscdir.dir+" && "+self.sourceControl.git+" log -1 --pretty=format:%ci",checkCommand = noCheck, log = self.log)
307908f030SMatthew G. Knepley          (o4, e4, s4) = self.executeShellCommand('cd '+self.petscdir.dir+' && '+self.sourceControl.git+' branch',checkCommand = noCheck, log = self.log)
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"')
337908f030SMatthew G. Knepley            (o5, e5, s5) = self.executeShellCommand('cd '+self.petscdir.dir+' && '+self.sourceControl.git+' status',checkCommand = noCheck, log = self.log)
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