xref: /petsc/config/PETSc/options/petscclone.py (revision d1b3ee289116af54fe925b17aa1669dfbeedfe1b)
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'):
2750f8d48fSJed Brown          (o1, e1, s1) = self.executeShellCommand([self.sourceControl.git, 'describe', '--match=v*'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
2850f8d48fSJed Brown          (o2, e2, s2) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%H'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
2950f8d48fSJed Brown          (o3, e3, s3) = self.executeShellCommand([self.sourceControl.git, 'log', '-1', '--pretty=format:%ci'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3083f83e59SBarry Smith          (o4, e4, s4) = self.executeShellCommand([self.sourceControl.git, 'rev-parse', '--abbrev-ref', 'HEAD'],checkCommand = noCheck, log = self.log, cwd=self.petscdir.dir)
3120a743a3SSatish Balay          if s2 or s3 or s4:
32*d1b3ee28SJacob Faibussowitsch            self.logPrintWarning('Git branch check is giving errors! Checking the repo with "git status"')
3350f8d48fSJed 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+'"')
3983f83e59SBarry Smith            self.addDefine('VERSION_BRANCH_GIT','"'+o4+'"')
409d310bb7SBarry Smith        else:
41*d1b3ee28SJacob Faibussowitsch          self.logPrintWarning('PETSC_DIR appears to be a Git clone - but git is not found in PATH')
429d310bb7SBarry Smith      else:
436e709e5aSBarry Smith        self.logPrint('This repository clone is obtained as a tarball as no .git dirs exist')
449d310bb7SBarry Smith    else:
456e709e5aSBarry Smith      if os.path.exists(os.path.join(self.petscdir.dir, '.git')):
469d310bb7SBarry Smith        raise RuntimeError('Your petsc source tree is broken. Use "git status" to check, or remove the entire directory and start all over again')
479d310bb7SBarry Smith      else:
489d310bb7SBarry Smith        self.logPrint('This is a tarball installation')
499d310bb7SBarry Smith    return
509d310bb7SBarry Smith
519d310bb7SBarry Smith  def configure(self):
529d310bb7SBarry Smith    self.executeTest(self.configureInstallationMethod)
539d310bb7SBarry Smith    return
54