summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/hg.py
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
committerTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
commitc527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch)
treebb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /bitbake/lib/bb/fetch2/hg.py
downloadpoky-daisy-140929.tar.gz
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'bitbake/lib/bb/fetch2/hg.py')
-rw-r--r--bitbake/lib/bb/fetch2/hg.py187
1 files changed, 187 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/hg.py b/bitbake/lib/bb/fetch2/hg.py
new file mode 100644
index 0000000000..6927f6111e
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/hg.py
@@ -0,0 +1,187 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' implementation for mercurial DRCS (hg).
5
6"""
7
8# Copyright (C) 2003, 2004 Chris Larson
9# Copyright (C) 2004 Marcin Juszkiewicz
10# Copyright (C) 2007 Robert Schuster
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License version 2 as
14# published by the Free Software Foundation.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License along
22# with this program; if not, write to the Free Software Foundation, Inc.,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24#
25# Based on functions from the base bb module, Copyright 2003 Holger Schurig
26
27import os
28import sys
29import logging
30import bb
31from bb import data
32from bb.fetch2 import FetchMethod
33from bb.fetch2 import FetchError
34from bb.fetch2 import MissingParameterError
35from bb.fetch2 import runfetchcmd
36from bb.fetch2 import logger
37
38class Hg(FetchMethod):
39 """Class to fetch from mercurial repositories"""
40 def supports(self, ud, d):
41 """
42 Check to see if a given url can be fetched with mercurial.
43 """
44 return ud.type in ['hg']
45
46 def urldata_init(self, ud, d):
47 """
48 init hg specific variable within url data
49 """
50 if not "module" in ud.parm:
51 raise MissingParameterError('module', ud.url)
52
53 ud.module = ud.parm["module"]
54
55 # Create paths to mercurial checkouts
56 relpath = self._strip_leading_slashes(ud.path)
57 ud.pkgdir = os.path.join(data.expand('${HGDIR}', d), ud.host, relpath)
58 ud.moddir = os.path.join(ud.pkgdir, ud.module)
59
60 ud.setup_revisons(d)
61
62 if 'rev' in ud.parm:
63 ud.revision = ud.parm['rev']
64 elif not ud.revision:
65 ud.revision = self.latest_revision(ud, d)
66
67 ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d)
68
69 def need_update(self, ud, d):
70 revTag = ud.parm.get('rev', 'tip')
71 if revTag == "tip":
72 return True
73 if not os.path.exists(ud.localpath):
74 return True
75 return False
76
77 def _buildhgcommand(self, ud, d, command):
78 """
79 Build up an hg commandline based on ud
80 command is "fetch", "update", "info"
81 """
82
83 basecmd = data.expand('${FETCHCMD_hg}', d)
84
85 proto = ud.parm.get('protocol', 'http')
86
87 host = ud.host
88 if proto == "file":
89 host = "/"
90 ud.host = "localhost"
91
92 if not ud.user:
93 hgroot = host + ud.path
94 else:
95 if ud.pswd:
96 hgroot = ud.user + ":" + ud.pswd + "@" + host + ud.path
97 else:
98 hgroot = ud.user + "@" + host + ud.path
99
100 if command == "info":
101 return "%s identify -i %s://%s/%s" % (basecmd, proto, hgroot, ud.module)
102
103 options = [];
104
105 # Don't specify revision for the fetch; clone the entire repo.
106 # This avoids an issue if the specified revision is a tag, because
107 # the tag actually exists in the specified revision + 1, so it won't
108 # be available when used in any successive commands.
109 if ud.revision and command != "fetch":
110 options.append("-r %s" % ud.revision)
111
112 if command == "fetch":
113 cmd = "%s clone %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, hgroot, ud.module, ud.module)
114 elif command == "pull":
115 # do not pass options list; limiting pull to rev causes the local
116 # repo not to contain it and immediately following "update" command
117 # will crash
118 if ud.user and ud.pswd:
119 cmd = "%s --config auth.default.prefix=* --config auth.default.username=%s --config auth.default.password=%s --config \"auth.default.schemes=%s\" pull" % (basecmd, ud.user, ud.pswd, proto)
120 else:
121 cmd = "%s pull" % (basecmd)
122 elif command == "update":
123 cmd = "%s update -C %s" % (basecmd, " ".join(options))
124 else:
125 raise FetchError("Invalid hg command %s" % command, ud.url)
126
127 return cmd
128
129 def download(self, ud, d):
130 """Fetch url"""
131
132 logger.debug(2, "Fetch: checking for module directory '" + ud.moddir + "'")
133
134 if os.access(os.path.join(ud.moddir, '.hg'), os.R_OK):
135 updatecmd = self._buildhgcommand(ud, d, "pull")
136 logger.info("Update " + ud.url)
137 # update sources there
138 os.chdir(ud.moddir)
139 logger.debug(1, "Running %s", updatecmd)
140 bb.fetch2.check_network_access(d, updatecmd, ud.url)
141 runfetchcmd(updatecmd, d)
142
143 else:
144 fetchcmd = self._buildhgcommand(ud, d, "fetch")
145 logger.info("Fetch " + ud.url)
146 # check out sources there
147 bb.utils.mkdirhier(ud.pkgdir)
148 os.chdir(ud.pkgdir)
149 logger.debug(1, "Running %s", fetchcmd)
150 bb.fetch2.check_network_access(d, fetchcmd, ud.url)
151 runfetchcmd(fetchcmd, d)
152
153 # Even when we clone (fetch), we still need to update as hg's clone
154 # won't checkout the specified revision if its on a branch
155 updatecmd = self._buildhgcommand(ud, d, "update")
156 os.chdir(ud.moddir)
157 logger.debug(1, "Running %s", updatecmd)
158 runfetchcmd(updatecmd, d)
159
160 scmdata = ud.parm.get("scmdata", "")
161 if scmdata == "keep":
162 tar_flags = ""
163 else:
164 tar_flags = "--exclude '.hg' --exclude '.hgrags'"
165
166 os.chdir(ud.pkgdir)
167 runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, ud.module), d, cleanup = [ud.localpath])
168
169 def supports_srcrev(self):
170 return True
171
172 def _latest_revision(self, ud, d, name):
173 """
174 Compute tip revision for the url
175 """
176 bb.fetch2.check_network_access(d, self._buildhgcommand(ud, d, "info"))
177 output = runfetchcmd(self._buildhgcommand(ud, d, "info"), d)
178 return output.strip()
179
180 def _build_revision(self, ud, d, name):
181 return ud.revision
182
183 def _revision_key(self, ud, d, name):
184 """
185 Return a unique key for the url
186 """
187 return "hg:" + ud.moddir