xref: /petsc/config/PETSc/options/petscclone.py (revision bcab024551cbaaaa7f49e357634a3584f91cb6d5)
1import config.base
2import os
3import re
4
5class Configure(config.base.Configure):
6  def __init__(self, framework):
7    config.base.Configure.__init__(self, framework)
8    return
9
10  def setupDependencies(self, framework):
11    self.sourceControl = framework.require('config.sourceControl',self)
12    self.petscdir = framework.require('PETSc.options.petscdir', self)
13    return
14
15  def configureInstallationMethod(self):
16    if os.path.exists(os.path.join(self.petscdir.dir,'bin','maint')):
17      self.logPrint('bin/maint exists. This appears to be a repository clone')
18      self.isClone = 1
19      if os.path.exists(os.path.join(self.petscdir.dir, '.git')):
20        if hasattr(self.sourceControl,'git'):
21          self.addDefine('VERSION_GIT','"'+os.popen("cd "+self.petscdir.dir+" && "+self.sourceControl.git+" describe").read().strip()+'"')
22          self.addDefine('VERSION_DATE_GIT','"'+os.popen("cd "+self.petscdir.dir+" && "+self.sourceControl.git+" log -1 --pretty=format:%ci").read()+'"')
23          self.addDefine('VERSION_BRANCH_GIT','"'+re.compile('\* (.*)\n').search(os.popen('cd '+self.petscdir.dir+' && '+self.sourceControl.git+' branch').read()).group(1)+'"')
24        else:
25          self.logPrintBox('\n*****WARNING: PETSC_DIR appears to be a Git clone - but git is not found in PATH********\n')
26      elif os.path.exists(os.path.join(self.petscdir.dir, '.hg')):
27        if hasattr(self.sourceControl,'hg'):
28          self.addDefine('VERSION_HG','"'+os.popen(self.sourceControl.hg +" -R"+self.petscdir.dir+" tip --template '{node}'").read()+'"')
29          self.addDefine('VERSION_DATE_HG','"'+os.popen(self.sourceControl.hg +" -R"+self.petscdir.dir+" tip --template '{date|date}'").read()+'"')
30        else:
31          self.logPrintBox('\n*****WARNING: PETSC_DIR appears to be a mercurial clone - but hg is not found in PATH********\n')
32      else:
33        self.logPrint('This repository clone is obtained as a tarball as neither .hg nor .git dirs exist!')
34    else:
35      if os.path.exists(os.path.join(self.petscdir.dir, '.git')) or os.path.exists(os.path.join(self.petscdir.dir, '.hg')):
36        raise RuntimeError('Your petsc source tree is broken. Use "git status" to check, or remove the entire directory and start all over again')
37      else:
38        self.logPrint('This is a tarball installation')
39        self.isClone = 0
40    return
41
42  def configure(self):
43    self.executeTest(self.configureInstallationMethod)
44    return
45