diff options
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r-- | bitbake/lib/bb/fetch/__init__.py | 2 | ||||
-rw-r--r-- | bitbake/lib/bb/fetch/hg.py | 150 |
2 files changed, 152 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py index da911e242c..eed7095819 100644 --- a/bitbake/lib/bb/fetch/__init__.py +++ b/bitbake/lib/bb/fetch/__init__.py | |||
@@ -461,6 +461,7 @@ import svk | |||
461 | import ssh | 461 | import ssh |
462 | import perforce | 462 | import perforce |
463 | import bzr | 463 | import bzr |
464 | import hg | ||
464 | 465 | ||
465 | methods.append(local.Local()) | 466 | methods.append(local.Local()) |
466 | methods.append(wget.Wget()) | 467 | methods.append(wget.Wget()) |
@@ -471,3 +472,4 @@ methods.append(svk.Svk()) | |||
471 | methods.append(ssh.SSH()) | 472 | methods.append(ssh.SSH()) |
472 | methods.append(perforce.Perforce()) | 473 | methods.append(perforce.Perforce()) |
473 | methods.append(bzr.Bzr()) | 474 | methods.append(bzr.Bzr()) |
475 | methods.append(hg.Hg()) | ||
diff --git a/bitbake/lib/bb/fetch/hg.py b/bitbake/lib/bb/fetch/hg.py new file mode 100644 index 0000000000..8e8073e56d --- /dev/null +++ b/bitbake/lib/bb/fetch/hg.py | |||
@@ -0,0 +1,150 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | """ | ||
4 | BitBake '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 | |||
27 | import os, re | ||
28 | import sys | ||
29 | import bb | ||
30 | from bb import data | ||
31 | from bb.fetch import Fetch | ||
32 | from bb.fetch import FetchError | ||
33 | from bb.fetch import MissingParameterError | ||
34 | from bb.fetch import runfetchcmd | ||
35 | |||
36 | class Hg(Fetch): | ||
37 | """Class to fetch a from mercurial repositories""" | ||
38 | def supports(self, url, ud, d): | ||
39 | """ | ||
40 | Check to see if a given url can be fetched with mercurial. | ||
41 | """ | ||
42 | return ud.type in ['hg'] | ||
43 | |||
44 | def localpath(self, url, ud, d): | ||
45 | if not "module" in ud.parm: | ||
46 | raise MissingParameterError("hg method needs a 'module' parameter") | ||
47 | |||
48 | ud.module = ud.parm["module"] | ||
49 | |||
50 | # Create paths to mercurial checkouts | ||
51 | relpath = ud.path | ||
52 | if relpath.startswith('/'): | ||
53 | # Remove leading slash as os.path.join can't cope | ||
54 | relpath = relpath[1:] | ||
55 | ud.pkgdir = os.path.join(data.expand('${HGDIR}', d), ud.host, relpath) | ||
56 | ud.moddir = os.path.join(ud.pkgdir, ud.module) | ||
57 | |||
58 | if 'rev' in ud.parm: | ||
59 | ud.revision = ud.parm['rev'] | ||
60 | else: | ||
61 | # | ||
62 | rev = data.getVar("SRCREV", d, 0) | ||
63 | if rev and "get_srcrev" in rev: | ||
64 | ud.revision = self.latest_revision(url, ud, d) | ||
65 | elif rev: | ||
66 | ud.revision = rev | ||
67 | else: | ||
68 | ud.revision = "" | ||
69 | |||
70 | ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision), d) | ||
71 | |||
72 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
73 | |||
74 | def _buildhgcommand(self, ud, d, command): | ||
75 | """ | ||
76 | Build up an hg commandline based on ud | ||
77 | command is "fetch", "update", "info" | ||
78 | """ | ||
79 | |||
80 | basecmd = data.expand('${FETCHCMD_hg}', d) | ||
81 | |||
82 | proto = "http" | ||
83 | if "proto" in ud.parm: | ||
84 | proto = ud.parm["proto"] | ||
85 | |||
86 | host = ud.host | ||
87 | if proto == "file": | ||
88 | host = "/" | ||
89 | ud.host = "localhost" | ||
90 | |||
91 | hgroot = host + ud.path | ||
92 | |||
93 | if command is "info": | ||
94 | return "%s identify -i %s://%s/%s" % (basecmd, proto, hgroot, ud.module) | ||
95 | |||
96 | options = []; | ||
97 | if ud.revision: | ||
98 | options.append("-r %s" % ud.revision) | ||
99 | |||
100 | if command is "fetch": | ||
101 | cmd = "%s clone %s %s://%s/%s %s" % (basecmd, " ".join(options), proto, hgroot, ud.module, ud.module) | ||
102 | elif command is "pull": | ||
103 | cmd = "%s pull %s" % (basecmd, " ".join(options)) | ||
104 | elif command is "update": | ||
105 | cmd = "%s update -C %s" % (basecmd, " ".join(options)) | ||
106 | else: | ||
107 | raise FetchError("Invalid hg command %s" % command) | ||
108 | |||
109 | return cmd | ||
110 | |||
111 | def go(self, loc, ud, d): | ||
112 | """Fetch url""" | ||
113 | |||
114 | # try to use the tarball stash | ||
115 | if Fetch.try_mirror(d, ud.localfile): | ||
116 | bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping hg checkout." % ud.localpath) | ||
117 | return | ||
118 | |||
119 | bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + ud.moddir + "'") | ||
120 | |||
121 | if os.access(os.path.join(ud.moddir, '.hg'), os.R_OK): | ||
122 | updatecmd = self._buildhgcommand(ud, d, "pull") | ||
123 | bb.msg.note(1, bb.msg.domain.Fetcher, "Update " + loc) | ||
124 | # update sources there | ||
125 | os.chdir(ud.moddir) | ||
126 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % updatecmd) | ||
127 | runfetchcmd(updatecmd, d) | ||
128 | |||
129 | updatecmd = self._buildhgcommand(ud, d, "update") | ||
130 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % updatecmd) | ||
131 | runfetchcmd(updatecmd, d) | ||
132 | else: | ||
133 | fetchcmd = self._buildhgcommand(ud, d, "fetch") | ||
134 | bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc) | ||
135 | # check out sources there | ||
136 | bb.mkdirhier(ud.pkgdir) | ||
137 | os.chdir(ud.pkgdir) | ||
138 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % fetchcmd) | ||
139 | runfetchcmd(fetchcmd, d) | ||
140 | |||
141 | os.chdir(ud.pkgdir) | ||
142 | try: | ||
143 | runfetchcmd("tar -czf %s %s" % (ud.localpath, ud.module), d) | ||
144 | except: | ||
145 | t, v, tb = sys.exc_info() | ||
146 | try: | ||
147 | os.unlink(ud.localpath) | ||
148 | except OSError: | ||
149 | pass | ||
150 | raise t, v, tb | ||