From 0fa1c5b0a54c2b64dfc431449b1ba4491b9981c0 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 27 Sep 2014 00:04:50 -0700 Subject: Add Mercurial fetch strategy and lwm2. --- lib/spack/spack/fetch_strategy.py | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index 411c8cc276..ad9af43c96 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -421,6 +421,76 @@ class SvnFetchStrategy(VCSFetchStrategy): self.svn('revert', '.', '-R') +class HgFetchStrategy(VCSFetchStrategy): + """Fetch strategy that gets source code from a Mercurial repository. + Use like this in a package: + + version('name', hg='https://jay.grs.rwth-aachen.de/hg/lwm2') + + Optionally, you can provide a branch, or revision to check out, e.g.: + + version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus') + + You can use these three optional attributes in addition to ``hg``: + + * ``branch``: Particular branch to build from (default is 'default') + * ``tag``: Particular tag to check out + * ``revision``: Particular revision hash in the repo + """ + enabled = True + required_attributes = ['hg'] + + def __init__(self, **kwargs): + super(HgFetchStrategy, self).__init__( + 'hg', 'tag', 'branch', 'revision', **kwargs) + self._hg = None + + # For git fetch branches and tags the same way. + if not self.revision: + self.revision = self.branch + if not self.revision: + self.revision = self.tag + + + @property + def hg(self): + if not self._hg: + self._hg = which('hg', required=True) + return self._hg + + + def fetch(self): + assert(self.stage) + self.stage.chdir() + + if self.stage.source_path: + tty.msg("Already fetched %s." % self.stage.source_path) + return + + tty.msg("Trying to clone Mercurial repository: %s" % self.url) + + args = ['clone', self.url] + if self.revision: + args += ['-r', self.revision] + + self.hg(*args) + + + def reset(self): + assert(self.stage) + self.stage.chdir() + + scrubbed = "scrubbed-source-tmp" + args = ['clone'] + if self.revision: + args += ['-r', self.revision] + args += [self.stage.source_path, scrubbed] + + self.hg(*args) + shutil.rmtree(self.stage.source_path, ignore_errors=True) + shutil.move(scrubbed, self.stage.source_path) + + def from_url(url): """Given a URL, find an appropriate fetch strategy for it. Currently just gives you a URLFetchStrategy that uses curl. -- cgit v1.2.3-70-g09d2