summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/contrib/vim/syntax/bitbake.vim120
-rw-r--r--bitbake/lib/bb/fetch/__init__.py175
-rw-r--r--bitbake/lib/bb/fetch/bk.py40
-rw-r--r--bitbake/lib/bb/fetch/cvs.py214
-rw-r--r--bitbake/lib/bb/fetch/git.py165
-rw-r--r--bitbake/lib/bb/fetch/local.py61
-rw-r--r--bitbake/lib/bb/fetch/svn.py189
-rw-r--r--bitbake/lib/bb/fetch/wget.py167
8 files changed, 1131 insertions, 0 deletions
diff --git a/bitbake/contrib/vim/syntax/bitbake.vim b/bitbake/contrib/vim/syntax/bitbake.vim
new file mode 100644
index 0000000000..5d2bc633e1
--- /dev/null
+++ b/bitbake/contrib/vim/syntax/bitbake.vim
@@ -0,0 +1,120 @@
1" Vim syntax file
2"
3" Copyright (C) 2004 Chris Larson <kergoth@handhelds.org>
4" This file is licensed under the MIT license, see COPYING.MIT in
5" this source distribution for the terms.
6"
7" Language: BitBake
8" Maintainer: Chris Larson <kergoth@handhelds.org>
9" Filenames: *.bb, *.bbclass
10
11if version < 600
12 syntax clear
13elseif exists("b:current_syntax")
14 finish
15endif
16
17syn case match
18
19
20" Catch incorrect syntax (only matches if nothing else does)
21"
22syn match bbUnmatched "."
23
24
25" Other
26
27syn match bbComment "^#.*$" display contains=bbTodo
28syn keyword bbTodo TODO FIXME XXX contained
29syn match bbDelimiter "[(){}=]" contained
30syn match bbQuote /['"]/ contained
31syn match bbArrayBrackets "[\[\]]" contained
32
33
34" BitBake strings
35
36syn match bbContinue "\\$"
37syn region bbString matchgroup=bbQuote start=/"/ skip=/\\$/ excludenl end=/"/ contained keepend contains=bbTodo,bbContinue,bbVarDeref
38syn region bbString matchgroup=bbQuote start=/'/ skip=/\\$/ excludenl end=/'/ contained keepend contains=bbTodo,bbContinue,bbVarDeref
39
40
41" BitBake variable metadata
42
43syn keyword bbExportFlag export contained nextgroup=bbIdentifier skipwhite
44syn match bbVarDeref "${[a-zA-Z0-9\-_\.]\+}" contained
45syn match bbVarDef "^\(export\s*\)\?\([a-zA-Z0-9\-_\.]\+\(_[${}a-zA-Z0-9\-_\.]\+\)\?\)\s*\(\(:=\)\|\(+=\)\|\(=+\)\|\(?=\)\|=\)\@=" contains=bbExportFlag,bbIdentifier,bbVarDeref nextgroup=bbVarEq
46
47syn match bbIdentifier "[a-zA-Z0-9\-_\.]\+" display contained
48"syn keyword bbVarEq = display contained nextgroup=bbVarValue
49syn match bbVarEq "\(:=\)\|\(+=\)\|\(=+\)\|\(?=\)\|=" contained nextgroup=bbVarValue
50syn match bbVarValue ".*$" contained contains=bbString,bbVarDeref
51
52
53" BitBake variable metadata flags
54syn match bbVarFlagDef "^\([a-zA-Z0-9\-_\.]\+\)\(\[[a-zA-Z0-9\-_\.]\+\]\)\@=" contains=bbIdentifier nextgroup=bbVarFlagFlag
55syn region bbVarFlagFlag matchgroup=bbArrayBrackets start="\[" end="\]\s*\(=\)\@=" keepend excludenl contained contains=bbIdentifier nextgroup=bbVarEq
56"syn match bbVarFlagFlag "\[\([a-zA-Z0-9\-_\.]\+\)\]\s*\(=\)\@=" contains=bbIdentifier nextgroup=bbVarEq
57
58
59" Functions!
60syn match bbFunction "\h\w*" display contained
61
62
63" BitBake python metadata
64syn include @python syntax/python.vim
65if exists("b:current_syntax")
66 unlet b:current_syntax
67endif
68
69syn keyword bbPythonFlag python contained nextgroup=bbFunction
70syn match bbPythonFuncDef "^\(python\s\+\)\(\w\+\)\?\(\s*()\s*\)\({\)\@=" contains=bbPythonFlag,bbFunction,bbDelimiter nextgroup=bbPythonFuncRegion skipwhite
71syn region bbPythonFuncRegion matchgroup=bbDelimiter start="{\s*$" end="^}\s*$" keepend contained contains=@python
72"hi def link bbPythonFuncRegion Comment
73
74
75" BitBake shell metadata
76syn include @shell syntax/sh.vim
77if exists("b:current_syntax")
78 unlet b:current_syntax
79endif
80
81syn keyword bbFakerootFlag fakeroot contained nextgroup=bbFunction
82syn match bbShellFuncDef "^\(fakeroot\s*\)\?\(\w\+\)\(python\)\@<!\(\s*()\s*\)\({\)\@=" contains=bbFakerootFlag,bbFunction,bbDelimiter nextgroup=bbShellFuncRegion skipwhite
83syn region bbShellFuncRegion matchgroup=bbDelimiter start="{\s*$" end="^}\s*$" keepend contained contains=@shell
84"hi def link bbShellFuncRegion Comment
85
86
87" BitBake 'def'd python functions
88syn keyword bbDef def contained
89syn region bbDefRegion start='^def\s\+\w\+\s*([^)]*)\s*:\s*$' end='^\(\s\|$\)\@!' contains=@python
90
91
92" BitBake statements
93syn keyword bbStatement include inherit addtask addhandler EXPORT_FUNCTIONS display contained
94syn match bbStatementLine "^\(include\|inherit\|addtask\|addhandler\|EXPORT_FUNCTIONS\)\s\+" contains=bbStatement nextgroup=bbStatementRest
95syn match bbStatementRest ".*$" contained contains=bbString,bbVarDeref
96
97" Highlight
98"
99hi def link bbArrayBrackets Statement
100hi def link bbUnmatched Error
101hi def link bbVarDeref String
102hi def link bbContinue Special
103hi def link bbDef Statement
104hi def link bbPythonFlag Type
105hi def link bbExportFlag Type
106hi def link bbFakerootFlag Type
107hi def link bbStatement Statement
108hi def link bbString String
109hi def link bbTodo Todo
110hi def link bbComment Comment
111hi def link bbOperator Operator
112hi def link bbError Error
113hi def link bbFunction Function
114hi def link bbDelimiter Delimiter
115hi def link bbIdentifier Identifier
116hi def link bbVarEq Operator
117hi def link bbQuote String
118hi def link bbVarValue String
119
120let b:current_syntax = "bb"
diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py
new file mode 100644
index 0000000000..da5b10c4b6
--- /dev/null
+++ b/bitbake/lib/bb/fetch/__init__.py
@@ -0,0 +1,175 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31
32class FetchError(Exception):
33 """Exception raised when a download fails"""
34
35class NoMethodError(Exception):
36 """Exception raised when there is no method to obtain a supplied url or set of urls"""
37
38class MissingParameterError(Exception):
39 """Exception raised when a fetch method is missing a critical parameter in the url"""
40
41class MD5SumError(Exception):
42 """Exception raised when a MD5SUM of a file does not match the expected one"""
43
44def uri_replace(uri, uri_find, uri_replace, d):
45# bb.note("uri_replace: operating on %s" % uri)
46 if not uri or not uri_find or not uri_replace:
47 bb.debug(1, "uri_replace: passed an undefined value, not replacing")
48 uri_decoded = list(bb.decodeurl(uri))
49 uri_find_decoded = list(bb.decodeurl(uri_find))
50 uri_replace_decoded = list(bb.decodeurl(uri_replace))
51 result_decoded = ['','','','','',{}]
52 for i in uri_find_decoded:
53 loc = uri_find_decoded.index(i)
54 result_decoded[loc] = uri_decoded[loc]
55 import types
56 if type(i) == types.StringType:
57 import re
58 if (re.match(i, uri_decoded[loc])):
59 result_decoded[loc] = re.sub(i, uri_replace_decoded[loc], uri_decoded[loc])
60 if uri_find_decoded.index(i) == 2:
61 if d:
62 localfn = bb.fetch.localpath(uri, d)
63 if localfn:
64 result_decoded[loc] = os.path.dirname(result_decoded[loc]) + "/" + os.path.basename(bb.fetch.localpath(uri, d))
65# bb.note("uri_replace: matching %s against %s and replacing with %s" % (i, uri_decoded[loc], uri_replace_decoded[loc]))
66 else:
67# bb.note("uri_replace: no match")
68 return uri
69# else:
70# for j in i.keys():
71# FIXME: apply replacements against options
72 return bb.encodeurl(result_decoded)
73
74methods = []
75
76def init(urls = [], d = None):
77 if d == None:
78 bb.debug(2,"BUG init called with None as data object!!!")
79 return
80
81 for m in methods:
82 m.urls = []
83
84 for u in urls:
85 for m in methods:
86 m.data = d
87 if m.supports(u, d):
88 m.urls.append(u)
89
90def go(d):
91 """Fetch all urls"""
92 for m in methods:
93 if m.urls:
94 m.go(d)
95
96def localpaths(d):
97 """Return a list of the local filenames, assuming successful fetch"""
98 local = []
99 for m in methods:
100 for u in m.urls:
101 local.append(m.localpath(u, d))
102 return local
103
104def localpath(url, d):
105 for m in methods:
106 if m.supports(url, d):
107 return m.localpath(url, d)
108 return url
109
110class Fetch(object):
111 """Base class for 'fetch'ing data"""
112
113 def __init__(self, urls = []):
114 self.urls = []
115 for url in urls:
116 if self.supports(bb.decodeurl(url), d) is 1:
117 self.urls.append(url)
118
119 def supports(url, d):
120 """Check to see if this fetch class supports a given url.
121 Expects supplied url in list form, as outputted by bb.decodeurl().
122 """
123 return 0
124 supports = staticmethod(supports)
125
126 def localpath(url, d):
127 """Return the local filename of a given url assuming a successful fetch.
128 """
129 return url
130 localpath = staticmethod(localpath)
131
132 def setUrls(self, urls):
133 self.__urls = urls
134
135 def getUrls(self):
136 return self.__urls
137
138 urls = property(getUrls, setUrls, None, "Urls property")
139
140 def setData(self, data):
141 self.__data = data
142
143 def getData(self):
144 return self.__data
145
146 data = property(getData, setData, None, "Data property")
147
148 def go(self, urls = []):
149 """Fetch urls"""
150 raise NoMethodError("Missing implementation for url")
151
152 def getSRCDate(d):
153 """
154 Return the SRC Date for the component
155
156 d the bb.data module
157 """
158 return data.getVar("SRCDATE", d, 1) or data.getVar("CVSDATE", d, 1) or data.getVar("DATE", d, 1 )
159 getSRCDate = staticmethod(getSRCDate)
160
161#if __name__ == "__main__":
162
163import bk
164import cvs
165import git
166import local
167import svn
168import wget
169
170methods.append(bk.Bk())
171methods.append(cvs.Cvs())
172methods.append(git.Git())
173methods.append(local.Local())
174methods.append(svn.Svn())
175methods.append(wget.Wget())
diff --git a/bitbake/lib/bb/fetch/bk.py b/bitbake/lib/bb/fetch/bk.py
new file mode 100644
index 0000000000..6bd6c018fb
--- /dev/null
+++ b/bitbake/lib/bb/fetch/bk.py
@@ -0,0 +1,40 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31from bb.fetch import Fetch
32
33class Bk(Fetch):
34 def supports(url, d):
35 """Check to see if a given url can be fetched via bitkeeper.
36 Expects supplied url in list form, as outputted by bb.decodeurl().
37 """
38 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
39 return type in ['bk']
40 supports = staticmethod(supports)
diff --git a/bitbake/lib/bb/fetch/cvs.py b/bitbake/lib/bb/fetch/cvs.py
new file mode 100644
index 0000000000..461a2f50f9
--- /dev/null
+++ b/bitbake/lib/bb/fetch/cvs.py
@@ -0,0 +1,214 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31from bb.fetch import Fetch
32from bb.fetch import FetchError
33from bb.fetch import MissingParameterError
34
35class Cvs(Fetch):
36 """Class to fetch a module or modules from cvs repositories"""
37 def supports(url, d):
38 """Check to see if a given url can be fetched with cvs.
39 Expects supplied url in list form, as outputted by bb.decodeurl().
40 """
41 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
42 return type in ['cvs', 'pserver']
43 supports = staticmethod(supports)
44
45 def localpath(url, d):
46 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
47 if "localpath" in parm:
48# if user overrides local path, use it.
49 return parm["localpath"]
50
51 if not "module" in parm:
52 raise MissingParameterError("cvs method needs a 'module' parameter")
53 else:
54 module = parm["module"]
55 if 'tag' in parm:
56 tag = parm['tag']
57 else:
58 tag = ""
59 if 'date' in parm:
60 date = parm['date']
61 else:
62 if not tag:
63 date = Fetch.getSRCDate(d)
64 else:
65 date = ""
66
67 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, tag, date), d))
68 localpath = staticmethod(localpath)
69
70 def go(self, d, urls = []):
71 """Fetch urls"""
72 if not urls:
73 urls = self.urls
74
75 localdata = data.createCopy(d)
76 data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
77 data.update_data(localdata)
78
79 for loc in urls:
80 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata))
81 if not "module" in parm:
82 raise MissingParameterError("cvs method needs a 'module' parameter")
83 else:
84 module = parm["module"]
85
86 dlfile = self.localpath(loc, localdata)
87 dldir = data.getVar('DL_DIR', localdata, 1)
88# if local path contains the cvs
89# module, consider the dir above it to be the
90# download directory
91# pos = dlfile.find(module)
92# if pos:
93# dldir = dlfile[:pos]
94# else:
95# dldir = os.path.dirname(dlfile)
96
97# setup cvs options
98 options = []
99 if 'tag' in parm:
100 tag = parm['tag']
101 else:
102 tag = ""
103
104 if 'date' in parm:
105 date = parm['date']
106 else:
107 if not tag:
108 date = Fetch.getSRCDate(d)
109 else:
110 date = ""
111
112 if "method" in parm:
113 method = parm["method"]
114 else:
115 method = "pserver"
116
117 if "localdir" in parm:
118 localdir = parm["localdir"]
119 else:
120 localdir = module
121
122 cvs_rsh = None
123 if method == "ext":
124 if "rsh" in parm:
125 cvs_rsh = parm["rsh"]
126
127 tarfn = data.expand('%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, tag, date), localdata)
128 data.setVar('TARFILES', dlfile, localdata)
129 data.setVar('TARFN', tarfn, localdata)
130
131 dl = os.path.join(dldir, tarfn)
132 if os.access(dl, os.R_OK):
133 bb.debug(1, "%s already exists, skipping cvs checkout." % tarfn)
134 continue
135
136 pn = data.getVar('PN', d, 1)
137 cvs_tarball_stash = None
138 if pn:
139 cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH_%s' % pn, d, 1)
140 if cvs_tarball_stash == None:
141 cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH', d, 1)
142 if cvs_tarball_stash:
143 fetchcmd = data.getVar("FETCHCOMMAND_wget", d, 1)
144 uri = cvs_tarball_stash + tarfn
145 bb.note("fetch " + uri)
146 fetchcmd = fetchcmd.replace("${URI}", uri)
147 ret = os.system(fetchcmd)
148 if ret == 0:
149 bb.note("Fetched %s from tarball stash, skipping checkout" % tarfn)
150 continue
151
152 if date:
153 options.append("-D %s" % date)
154 if tag:
155 options.append("-r %s" % tag)
156
157 olddir = os.path.abspath(os.getcwd())
158 os.chdir(data.expand(dldir, localdata))
159
160# setup cvsroot
161 if method == "dir":
162 cvsroot = path
163 else:
164 cvsroot = ":" + method + ":" + user
165 if pswd:
166 cvsroot += ":" + pswd
167 cvsroot += "@" + host + ":" + path
168
169 data.setVar('CVSROOT', cvsroot, localdata)
170 data.setVar('CVSCOOPTS', " ".join(options), localdata)
171 data.setVar('CVSMODULE', module, localdata)
172 cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
173 cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
174
175 if cvs_rsh:
176 cvscmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvscmd)
177 cvsupdatecmd = "CVS_RSH=\"%s\" %s" % (cvs_rsh, cvsupdatecmd)
178
179# create module directory
180 bb.debug(2, "Fetch: checking for module directory")
181 pkg=data.expand('${PN}', d)
182 pkgdir=os.path.join(data.expand('${CVSDIR}', localdata), pkg)
183 moddir=os.path.join(pkgdir,localdir)
184 if os.access(os.path.join(moddir,'CVS'), os.R_OK):
185 bb.note("Update " + loc)
186# update sources there
187 os.chdir(moddir)
188 myret = os.system(cvsupdatecmd)
189 else:
190 bb.note("Fetch " + loc)
191# check out sources there
192 bb.mkdirhier(pkgdir)
193 os.chdir(pkgdir)
194 bb.debug(1, "Running %s" % cvscmd)
195 myret = os.system(cvscmd)
196
197 if myret != 0:
198 try:
199 os.rmdir(moddir)
200 except OSError:
201 pass
202 raise FetchError(module)
203
204 os.chdir(moddir)
205 os.chdir('..')
206# tar them up to a defined filename
207 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(moddir)))
208 if myret != 0:
209 try:
210 os.unlink(tarfn)
211 except OSError:
212 pass
213 os.chdir(olddir)
214 del localdata
diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py
new file mode 100644
index 0000000000..296b926392
--- /dev/null
+++ b/bitbake/lib/bb/fetch/git.py
@@ -0,0 +1,165 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' git implementation
6
7Copyright (C) 2005 Richard Purdie
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place, Suite 330, Boston, MA 02111-1307 USA.
21"""
22
23import os, re
24import bb
25from bb import data
26from bb.fetch import Fetch
27from bb.fetch import FetchError
28
29def prunedir(topdir):
30 # Delete everything reachable from the directory named in 'topdir'.
31 # CAUTION: This is dangerous!
32 for root, dirs, files in os.walk(topdir, topdown=False):
33 for name in files:
34 os.remove(os.path.join(root, name))
35 for name in dirs:
36 os.rmdir(os.path.join(root, name))
37
38def rungitcmd(cmd,d):
39
40 bb.debug(1, "Running %s" % cmd)
41
42 # Need to export PATH as git is likely to be in metadata paths
43 # rather than host provided
44 pathcmd = 'export PATH=%s; %s' % (data.expand('${PATH}', d), cmd)
45
46 myret = os.system(pathcmd)
47
48 if myret != 0:
49 raise FetchError("Git: %s failed" % pathcmd)
50
51def gettag(parm):
52 if 'tag' in parm:
53 tag = parm['tag']
54 else:
55 tag = ""
56 if not tag:
57 tag = "master"
58
59 return tag
60
61class Git(Fetch):
62 """Class to fetch a module or modules from git repositories"""
63 def supports(url, d):
64 """Check to see if a given url can be fetched with cvs.
65 Expects supplied url in list form, as outputted by bb.decodeurl().
66 """
67 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
68 return type in ['git']
69 supports = staticmethod(supports)
70
71 def localpath(url, d):
72 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
73
74 #if user sets localpath for file, use it instead.
75 if "localpath" in parm:
76 return parm["localpath"]
77
78 tag = gettag(parm)
79
80 localname = data.expand('git_%s%s_%s.tar.gz' % (host, path.replace('/', '.'), tag), d)
81
82 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s' % (localname), d))
83
84 localpath = staticmethod(localpath)
85
86 def go(self, d, urls = []):
87 """Fetch urls"""
88 if not urls:
89 urls = self.urls
90
91 for loc in urls:
92 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, d))
93
94 tag = gettag(parm)
95
96 gitsrcname = '%s%s' % (host, path.replace('/', '.'))
97
98 repofile = os.path.join(data.getVar("DL_DIR", d, 1), 'git_%s.tar.gz' % (gitsrcname))
99 repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname)
100
101 coname = '%s' % (tag)
102 codir = os.path.join(repodir, coname)
103
104 cofile = self.localpath(loc, d)
105
106 # Always update to current if tag=="master"
107 #if os.access(cofile, os.R_OK) and (tag != "master"):
108 if os.access(cofile, os.R_OK):
109 bb.debug(1, "%s already exists, skipping git checkout." % cofile)
110 continue
111
112# Still Need to add GIT_TARBALL_STASH Support...
113# pn = data.getVar('PN', d, 1)
114# cvs_tarball_stash = None
115# if pn:
116# cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH_%s' % pn, d, 1)
117# if cvs_tarball_stash == None:
118# cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH', d, 1)
119# if cvs_tarball_stash:
120# fetchcmd = data.getVar("FETCHCOMMAND_wget", d, 1)
121# uri = cvs_tarball_stash + tarfn
122# bb.note("fetch " + uri)
123# fetchcmd = fetchcmd.replace("${URI}", uri)
124# ret = os.system(fetchcmd)
125# if ret == 0:
126# bb.note("Fetched %s from tarball stash, skipping checkout" % tarfn)
127# continue
128
129 #if os.path.exists(repodir):
130 #prunedir(repodir)
131
132 bb.mkdirhier(repodir)
133 os.chdir(repodir)
134
135 #print("Changing to %s" % repodir)
136
137 if os.access(repofile, os.R_OK):
138 rungitcmd("tar -xzf %s" % (repofile),d)
139 else:
140 rungitcmd("git clone rsync://%s%s %s" % (host, path, repodir),d)
141
142 rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (host, path, os.path.join(repodir, ".git", "")),d)
143
144 #print("Changing to %s" % repodir)
145 os.chdir(repodir)
146 rungitcmd("git pull rsync://%s%s" % (host, path),d)
147
148 #print("Changing to %s" % repodir)
149 os.chdir(repodir)
150 rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d)
151
152 if os.path.exists(codir):
153 prunedir(codir)
154
155 #print("Changing to %s" % repodir)
156 bb.mkdirhier(codir)
157 os.chdir(repodir)
158 rungitcmd("git read-tree %s" % (tag),d)
159
160 rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d)
161
162 #print("Changing to %s" % codir)
163 os.chdir(codir)
164 rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d)
165
diff --git a/bitbake/lib/bb/fetch/local.py b/bitbake/lib/bb/fetch/local.py
new file mode 100644
index 0000000000..51938f823e
--- /dev/null
+++ b/bitbake/lib/bb/fetch/local.py
@@ -0,0 +1,61 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31from bb.fetch import Fetch
32
33class Local(Fetch):
34 def supports(url, d):
35 """Check to see if a given url can be fetched in the local filesystem.
36 Expects supplied url in list form, as outputted by bb.decodeurl().
37 """
38 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
39 return type in ['file','patch']
40 supports = staticmethod(supports)
41
42 def localpath(url, d):
43 """Return the local filename of a given url assuming a successful fetch.
44 """
45 path = url.split("://")[1]
46 newpath = path
47 if path[0] != "/":
48 filespath = data.getVar('FILESPATH', d, 1)
49 if filespath:
50 newpath = bb.which(filespath, path)
51 if not newpath:
52 filesdir = data.getVar('FILESDIR', d, 1)
53 if filesdir:
54 newpath = os.path.join(filesdir, path)
55 return newpath
56 localpath = staticmethod(localpath)
57
58 def go(self, urls = []):
59 """Fetch urls (no-op for Local method)"""
60# no need to fetch local files, we'll deal with them in place.
61 return 1
diff --git a/bitbake/lib/bb/fetch/svn.py b/bitbake/lib/bb/fetch/svn.py
new file mode 100644
index 0000000000..ac5eebf5c0
--- /dev/null
+++ b/bitbake/lib/bb/fetch/svn.py
@@ -0,0 +1,189 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31from bb.fetch import Fetch
32from bb.fetch import FetchError
33from bb.fetch import MissingParameterError
34
35class Svn(Fetch):
36 """Class to fetch a module or modules from svn repositories"""
37 def supports(url, d):
38 """Check to see if a given url can be fetched with svn.
39 Expects supplied url in list form, as outputted by bb.decodeurl().
40 """
41 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
42 return type in ['svn']
43 supports = staticmethod(supports)
44
45 def localpath(url, d):
46 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
47 if "localpath" in parm:
48# if user overrides local path, use it.
49 return parm["localpath"]
50
51 if not "module" in parm:
52 raise MissingParameterError("svn method needs a 'module' parameter")
53 else:
54 module = parm["module"]
55 if 'rev' in parm:
56 revision = parm['rev']
57 else:
58 revision = ""
59
60 date = Fetch.getSRCDate(d)
61
62 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s_%s_%s_%s_%s.tar.gz' % ( module.replace('/', '.'), host, path.replace('/', '.'), revision, date), d))
63 localpath = staticmethod(localpath)
64
65 def go(self, d, urls = []):
66 """Fetch urls"""
67 if not urls:
68 urls = self.urls
69
70 localdata = data.createCopy(d)
71 data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
72 data.update_data(localdata)
73
74 for loc in urls:
75 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, localdata))
76 if not "module" in parm:
77 raise MissingParameterError("svn method needs a 'module' parameter")
78 else:
79 module = parm["module"]
80
81 dlfile = self.localpath(loc, localdata)
82 dldir = data.getVar('DL_DIR', localdata, 1)
83# if local path contains the svn
84# module, consider the dir above it to be the
85# download directory
86# pos = dlfile.find(module)
87# if pos:
88# dldir = dlfile[:pos]
89# else:
90# dldir = os.path.dirname(dlfile)
91
92# setup svn options
93 options = []
94 if 'rev' in parm:
95 revision = parm['rev']
96 else:
97 revision = ""
98
99 date = Fetch.getSRCDate(d)
100
101 if "method" in parm:
102 method = parm["method"]
103 else:
104 method = "pserver"
105
106 if "proto" in parm:
107 proto = parm["proto"]
108 else:
109 proto = "svn"
110
111 svn_rsh = None
112 if method == "ext":
113 if "rsh" in parm:
114 svn_rsh = parm["rsh"]
115
116 tarfn = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), host, path.replace('/', '.'), revision, date), localdata)
117 data.setVar('TARFILES', dlfile, localdata)
118 data.setVar('TARFN', tarfn, localdata)
119
120 dl = os.path.join(dldir, tarfn)
121 if os.access(dl, os.R_OK):
122 bb.debug(1, "%s already exists, skipping svn checkout." % tarfn)
123 continue
124
125 svn_tarball_stash = data.getVar('CVS_TARBALL_STASH', d, 1)
126 if svn_tarball_stash:
127 fetchcmd = data.getVar("FETCHCOMMAND_wget", d, 1)
128 uri = svn_tarball_stash + tarfn
129 bb.note("fetch " + uri)
130 fetchcmd = fetchcmd.replace("${URI}", uri)
131 ret = os.system(fetchcmd)
132 if ret == 0:
133 bb.note("Fetched %s from tarball stash, skipping checkout" % tarfn)
134 continue
135
136 olddir = os.path.abspath(os.getcwd())
137 os.chdir(data.expand(dldir, localdata))
138
139# setup svnroot
140# svnroot = ":" + method + ":" + user
141# if pswd:
142# svnroot += ":" + pswd
143 svnroot = host + path
144
145 data.setVar('SVNROOT', svnroot, localdata)
146 data.setVar('SVNCOOPTS', " ".join(options), localdata)
147 data.setVar('SVNMODULE', module, localdata)
148 svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
149 svncmd = "svn co -r {%s} %s://%s/%s" % (date, proto, svnroot, module)
150
151 if revision:
152 svncmd = "svn co -r %s %s://%s/%s" % (revision, proto, svnroot, module)
153 if svn_rsh:
154 svncmd = "svn_RSH=\"%s\" %s" % (svn_rsh, svncmd)
155
156# create temp directory
157 bb.debug(2, "Fetch: creating temporary directory")
158 bb.mkdirhier(data.expand('${WORKDIR}', localdata))
159 data.setVar('TMPBASE', data.expand('${WORKDIR}/oesvn.XXXXXX', localdata), localdata)
160 tmppipe = os.popen(data.getVar('MKTEMPDIRCMD', localdata, 1) or "false")
161 tmpfile = tmppipe.readline().strip()
162 if not tmpfile:
163 bb.error("Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
164 raise FetchError(module)
165
166# check out sources there
167 os.chdir(tmpfile)
168 bb.note("Fetch " + loc)
169 bb.debug(1, "Running %s" % svncmd)
170 myret = os.system(svncmd)
171 if myret != 0:
172 try:
173 os.rmdir(tmpfile)
174 except OSError:
175 pass
176 raise FetchError(module)
177
178 os.chdir(os.path.join(tmpfile, os.path.dirname(module)))
179# tar them up to a defined filename
180 myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))
181 if myret != 0:
182 try:
183 os.unlink(tarfn)
184 except OSError:
185 pass
186# cleanup
187 os.system('rm -rf %s' % tmpfile)
188 os.chdir(olddir)
189 del localdata
diff --git a/bitbake/lib/bb/fetch/wget.py b/bitbake/lib/bb/fetch/wget.py
new file mode 100644
index 0000000000..e47a8859be
--- /dev/null
+++ b/bitbake/lib/bb/fetch/wget.py
@@ -0,0 +1,167 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4"""
5BitBake 'Fetch' implementations
6
7Classes for obtaining upstream sources for the
8BitBake build tools.
9
10Copyright (C) 2003, 2004 Chris Larson
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; either version 2 of the License, or (at your option) any later
15version.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23Place, Suite 330, Boston, MA 02111-1307 USA.
24
25Based on functions from the base bb module, Copyright 2003 Holger Schurig
26"""
27
28import os, re
29import bb
30from bb import data
31from bb.fetch import Fetch
32from bb.fetch import FetchError
33from bb.fetch import MD5SumError
34from bb.fetch import uri_replace
35
36class Wget(Fetch):
37 """Class to fetch urls via 'wget'"""
38 def supports(url, d):
39 """Check to see if a given url can be fetched using wget.
40 Expects supplied url in list form, as outputted by bb.decodeurl().
41 """
42 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
43 return type in ['http','https','ftp']
44 supports = staticmethod(supports)
45
46 def localpath(url, d):
47# strip off parameters
48 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
49 if "localpath" in parm:
50# if user overrides local path, use it.
51 return parm["localpath"]
52 url = bb.encodeurl([type, host, path, user, pswd, {}])
53
54 return os.path.join(data.getVar("DL_DIR", d), os.path.basename(url))
55 localpath = staticmethod(localpath)
56
57 def go(self, d, urls = []):
58 """Fetch urls"""
59
60 def md5_sum(parm, d):
61 """
62 Return the MD5SUM associated with the to be downloaded
63 file.
64 It can return None if no md5sum is associated
65 """
66 try:
67 return parm['md5sum']
68 except:
69 return None
70
71 def verify_md5sum(wanted_sum, got_sum):
72 """
73 Verify the md5sum we wanted with the one we got
74 """
75 if not wanted_sum:
76 return True
77
78 return wanted_sum == got_sum
79
80 def fetch_uri(uri, basename, dl, md5, parm, d):
81 # the MD5 sum we want to verify
82 wanted_md5sum = md5_sum(parm, d)
83 if os.path.exists(dl):
84# file exists, but we didnt complete it.. trying again..
85 fetchcmd = data.getVar("RESUMECOMMAND", d, 1)
86 else:
87 fetchcmd = data.getVar("FETCHCOMMAND", d, 1)
88
89 bb.note("fetch " + uri)
90 fetchcmd = fetchcmd.replace("${URI}", uri)
91 fetchcmd = fetchcmd.replace("${FILE}", basename)
92 bb.debug(2, "executing " + fetchcmd)
93 ret = os.system(fetchcmd)
94 if ret != 0:
95 return False
96
97 # check if sourceforge did send us to the mirror page
98 dl_dir = data.getVar("DL_DIR", d, True)
99 if not os.path.exists(dl):
100 os.system("rm %s*" % dl) # FIXME shell quote it
101 bb.debug(2,"sourceforge.net send us to the mirror on %s" % basename)
102 return False
103
104# supposedly complete.. write out md5sum
105 if bb.which(data.getVar('PATH', d), 'md5sum'):
106 try:
107 md5pipe = os.popen('md5sum ' + dl)
108 md5data = (md5pipe.readline().split() or [ "" ])[0]
109 md5pipe.close()
110 except OSError:
111 md5data = ""
112
113 # verify the md5sum
114 if not verify_md5sum(wanted_md5sum, md5data):
115 raise MD5SumError(uri)
116
117 md5out = file(md5, 'w')
118 md5out.write(md5data)
119 md5out.close()
120 return True
121
122 if not urls:
123 urls = self.urls
124
125 localdata = data.createCopy(d)
126 data.setVar('OVERRIDES', "wget:" + data.getVar('OVERRIDES', localdata), localdata)
127 data.update_data(localdata)
128
129 for uri in urls:
130 completed = 0
131 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(uri, localdata))
132 basename = os.path.basename(path)
133 dl = self.localpath(uri, d)
134 dl = data.expand(dl, localdata)
135 md5 = dl + '.md5'
136
137 if os.path.exists(md5):
138# complete, nothing to see here..
139 continue
140
141 premirrors = [ i.split() for i in (data.getVar('PREMIRRORS', localdata, 1) or "").split('\n') if i ]
142 for (find, replace) in premirrors:
143 newuri = uri_replace(uri, find, replace, d)
144 if newuri != uri:
145 if fetch_uri(newuri, basename, dl, md5, parm, localdata):
146 completed = 1
147 break
148
149 if completed:
150 continue
151
152 if fetch_uri(uri, basename, dl, md5, parm, localdata):
153 continue
154
155# try mirrors
156 mirrors = [ i.split() for i in (data.getVar('MIRRORS', localdata, 1) or "").split('\n') if i ]
157 for (find, replace) in mirrors:
158 newuri = uri_replace(uri, find, replace, d)
159 if newuri != uri:
160 if fetch_uri(newuri, basename, dl, md5, parm, localdata):
161 completed = 1
162 break
163
164 if not completed:
165 raise FetchError(uri)
166
167 del localdata