1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4 BitBake 'Fetch' implementations
6 Classes for obtaining upstream sources for the
11 # Copyright (C) 2003, 2004 Chris Larson
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License version 2 as
15 # published by the Free Software Foundation.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with this program; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 # Based on functions from the base bb module, Copyright 2003 Holger Schurig
31 from bb.fetch import Fetch
32 from bb.fetch import FetchError
33 from bb.fetch import MissingParameterError
35 class Perforce(Fetch):
36 def supports(self, url, ud, d):
37 return ud.type in ['p4']
41 path = url.split("://")[1]
42 delim = path.find("@");
44 (user,pswd,host,port) = path.split('@')[0].split(":")
45 path = path.split('@')[1]
47 (host,port) = data.getVar('P4PORT', d).split(':')
51 if path.find(";") != -1:
54 plist = path.split(';')
57 (key,value) = item.split('=')
61 parm = dict(zip(keys,values))
62 path = "//" + path.split(';')[0]
63 host += ":%s" % (port)
64 parm["cset"] = Perforce.getcset(d, path, host, user, pswd, parm)
66 return host,path,user,pswd,parm
67 doparse = staticmethod(doparse)
69 def getcset(d, depot,host,user,pswd,parm):
74 p4opt += " -u %s" % (user)
76 p4opt += " -P %s" % (pswd)
78 p4opt += " -p %s" % (host)
80 p4date = data.getVar("P4DATE", d, 1)
81 if "revision" in parm:
82 depot += "#%s" % (parm["revision"])
84 depot += "@%s" % (parm["label"])
86 depot += "@%s" % (p4date)
88 p4cmd = data.getVar('FETCHCOMMAND_p4', d, 1)
89 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s%s changes -m 1 %s" % (p4cmd, p4opt, depot))
90 p4file = os.popen("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot))
91 cset = p4file.readline().strip()
92 bb.msg.debug(1, bb.msg.domain.Fetcher, "READ %s" % (cset))
96 return cset.split(' ')[1]
97 getcset = staticmethod(getcset)
99 def localpath(self, url, ud, d):
101 (host,path,user,pswd,parm) = Perforce.doparse(url,d)
103 # If a label is specified, we use that as our filename
106 ud.localfile = "%s.tar.gz" % (parm["label"])
107 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
110 which = path.find('/...')
117 cset = Perforce.getcset(d, path, host, user, pswd, parm)
119 ud.localfile = data.expand('%s+%s+%s.tar.gz' % (host,base.replace('/', '.'), cset), d)
121 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
123 def go(self, loc, ud, d):
128 # try to use the tarball stash
129 if Fetch.try_mirror(d, ud.localfile):
130 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping perforce checkout." % ud.localpath)
133 (host,depot,user,pswd,parm) = Perforce.doparse(loc, d)
135 if depot.find('/...') != -1:
136 path = depot[:depot.find('/...')]
141 module = parm["module"]
143 module = os.path.basename(path)
145 localdata = data.createCopy(d)
146 data.setVar('OVERRIDES', "p4:%s" % data.getVar('OVERRIDES', localdata), localdata)
147 data.update_data(localdata)
152 p4opt += " -u %s" % (user)
155 p4opt += " -P %s" % (pswd)
158 p4opt += " -p %s" % (host)
160 p4cmd = data.getVar('FETCHCOMMAND', localdata, 1)
162 # create temp directory
163 bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: creating temporary directory")
164 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
165 data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata)
166 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
167 tmpfile = tmppipe.readline().strip()
169 bb.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
170 raise FetchError(module)
173 depot = "%s@%s" % (depot,parm["label"])
175 cset = Perforce.getcset(d, depot, host, user, pswd, parm)
176 depot = "%s@%s" % (depot,cset)
179 bb.msg.note(1, bb.msg.domain.Fetcher, "Fetch " + loc)
180 bb.msg.note(1, bb.msg.domain.Fetcher, "%s%s files %s" % (p4cmd, p4opt, depot))
181 p4file = os.popen("%s%s files %s" % (p4cmd, p4opt, depot))
184 bb.error("Fetch: unable to get the P4 files from %s" % (depot))
185 raise FetchError(module)
192 if list[2] == "delete":
195 dest = list[0][len(path)+1:]
196 where = dest.find("#")
198 os.system("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module,dest[:where],list[0]))
202 bb.error("Fetch: No files gathered from the P4 fetch")
203 raise FetchError(module)
205 myret = os.system("tar -czf %s %s" % (ud.localpath, module))
208 os.unlink(ud.localpath)
211 raise FetchError(module)
213 os.system('rm -rf %s' % tmpfile)