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