summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/perforce.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch2/perforce.py')
-rw-r--r--bitbake/lib/bb/fetch2/perforce.py198
1 files changed, 198 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py
new file mode 100644
index 0000000000..fc4074d5a3
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/perforce.py
@@ -0,0 +1,198 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' implementations
5
6Classes for obtaining upstream sources for the
7BitBake build tools.
8
9"""
10
11# Copyright (C) 2003, 2004 Chris Larson
12#
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.
16#
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.
21#
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.
25#
26# Based on functions from the base bb module, Copyright 2003 Holger Schurig
27
28from future_builtins import zip
29import os
30import subprocess
31import logging
32import bb
33from bb import data
34from bb.fetch2 import FetchMethod
35from bb.fetch2 import FetchError
36from bb.fetch2 import logger
37from bb.fetch2 import runfetchcmd
38
39class Perforce(FetchMethod):
40 def supports(self, url, ud, d):
41 return ud.type in ['p4']
42
43 def doparse(url, d):
44 parm = {}
45 path = url.split("://")[1]
46 delim = path.find("@");
47 if delim != -1:
48 (user, pswd, host, port) = path.split('@')[0].split(":")
49 path = path.split('@')[1]
50 else:
51 (host, port) = data.getVar('P4PORT', d).split(':')
52 user = ""
53 pswd = ""
54
55 if path.find(";") != -1:
56 keys=[]
57 values=[]
58 plist = path.split(';')
59 for item in plist:
60 if item.count('='):
61 (key, value) = item.split('=')
62 keys.append(key)
63 values.append(value)
64
65 parm = dict(zip(keys, values))
66 path = "//" + path.split(';')[0]
67 host += ":%s" % (port)
68 parm["cset"] = Perforce.getcset(d, path, host, user, pswd, parm)
69
70 return host, path, user, pswd, parm
71 doparse = staticmethod(doparse)
72
73 def getcset(d, depot, host, user, pswd, parm):
74 p4opt = ""
75 if "cset" in parm:
76 return parm["cset"];
77 if user:
78 p4opt += " -u %s" % (user)
79 if pswd:
80 p4opt += " -P %s" % (pswd)
81 if host:
82 p4opt += " -p %s" % (host)
83
84 p4date = data.getVar("P4DATE", d, True)
85 if "revision" in parm:
86 depot += "#%s" % (parm["revision"])
87 elif "label" in parm:
88 depot += "@%s" % (parm["label"])
89 elif p4date:
90 depot += "@%s" % (p4date)
91
92 p4cmd = data.getVar('FETCHCOMMAND_p4', d, True)
93 logger.debug(1, "Running %s%s changes -m 1 %s", p4cmd, p4opt, depot)
94 p4file, errors = bb.process.run("%s%s changes -m 1 %s" % (p4cmd, p4opt, depot))
95 cset = p4file.strip()
96 logger.debug(1, "READ %s", cset)
97 if not cset:
98 return -1
99
100 return cset.split(' ')[1]
101 getcset = staticmethod(getcset)
102
103 def urldata_init(self, ud, d):
104 (host, path, user, pswd, parm) = Perforce.doparse(ud.url, d)
105
106 # If a label is specified, we use that as our filename
107
108 if "label" in parm:
109 ud.localfile = "%s.tar.gz" % (parm["label"])
110 return
111
112 base = path
113 which = path.find('/...')
114 if which != -1:
115 base = path[:which]
116
117 base = self._strip_leading_slashes(base)
118
119 cset = Perforce.getcset(d, path, host, user, pswd, parm)
120
121 ud.localfile = data.expand('%s+%s+%s.tar.gz' % (host, base.replace('/', '.'), cset), d)
122
123 def download(self, loc, ud, d):
124 """
125 Fetch urls
126 """
127
128 (host, depot, user, pswd, parm) = Perforce.doparse(loc, d)
129
130 if depot.find('/...') != -1:
131 path = depot[:depot.find('/...')]
132 else:
133 path = depot
134
135 module = parm.get('module', os.path.basename(path))
136
137 localdata = data.createCopy(d)
138 data.setVar('OVERRIDES', "p4:%s" % data.getVar('OVERRIDES', localdata), localdata)
139 data.update_data(localdata)
140
141 # Get the p4 command
142 p4opt = ""
143 if user:
144 p4opt += " -u %s" % (user)
145
146 if pswd:
147 p4opt += " -P %s" % (pswd)
148
149 if host:
150 p4opt += " -p %s" % (host)
151
152 p4cmd = data.getVar('FETCHCOMMAND', localdata, True)
153
154 # create temp directory
155 logger.debug(2, "Fetch: creating temporary directory")
156 bb.utils.mkdirhier(data.expand('${WORKDIR}', localdata))
157 data.setVar('TMPBASE', data.expand('${WORKDIR}/oep4.XXXXXX', localdata), localdata)
158 tmpfile, errors = bb.process.run(data.getVar('MKTEMPDIRCMD', localdata, True) or "false")
159 tmpfile = tmpfile.strip()
160 if not tmpfile:
161 raise FetchError("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.", loc)
162
163 if "label" in parm:
164 depot = "%s@%s" % (depot, parm["label"])
165 else:
166 cset = Perforce.getcset(d, depot, host, user, pswd, parm)
167 depot = "%s@%s" % (depot, cset)
168
169 os.chdir(tmpfile)
170 logger.info("Fetch " + loc)
171 logger.info("%s%s files %s", p4cmd, p4opt, depot)
172 p4file, errors = bb.process.run("%s%s files %s" % (p4cmd, p4opt, depot))
173 p4file = [f.rstrip() for f in p4file.splitlines()]
174
175 if not p4file:
176 raise FetchError("Fetch: unable to get the P4 files from %s" % depot, loc)
177
178 count = 0
179
180 for file in p4file:
181 list = file.split()
182
183 if list[2] == "delete":
184 continue
185
186 dest = list[0][len(path)+1:]
187 where = dest.find("#")
188
189 subprocess.call("%s%s print -o %s/%s %s" % (p4cmd, p4opt, module, dest[:where], list[0]), shell=True)
190 count = count + 1
191
192 if count == 0:
193 logger.error()
194 raise FetchError("Fetch: No files gathered from the P4 fetch", loc)
195
196 runfetchcmd("tar -czf %s %s" % (ud.localpath, module), d, cleanup = [ud.localpath])
197 # cleanup
198 bb.utils.prunedir(tmpfile)