summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-22 14:18:18 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-25 15:58:31 (GMT)
commita6c6a8ddb6bd6138e13434d0a44dc427e75546df (patch)
tree087ba3568fcf2cab03a875264330ae0a27059b3d
parent8054716544c2f4f817fb4ca0d57dd5ae243aed4e (diff)
downloadpoky-a6c6a8ddb6bd6138e13434d0a44dc427e75546df.tar.gz
bitbake: bitbake/fetch: Add git submodules fetcher
This adds very basic git submodule support to the fetcher. It can be used by replacing a git:// url prefix with a gitsm:// prefix, otherwise behaviour is the same as the git fetcher. Whilst this code should be functional, its not as efficient as the usual git fetcher due to the need to checkout the tree to fetch/update the submodule information. git doesn't support submodule operations on the bare clones the standard git fetcher uses which is also problematic. This code does however give a starting point to people wanting to use submodules. (Bitbake rev: 25e0b0bc50114f1fbf955de23cc0c96f5f7a41e3) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py2
-rw-r--r--bitbake/lib/bb/fetch2/git.py2
-rw-r--r--bitbake/lib/bb/fetch2/gitsm.py78
3 files changed, 81 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 4cfe089..1bf67dd 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -1497,6 +1497,7 @@ class Fetch(object):
1497 1497
1498from . import cvs 1498from . import cvs
1499from . import git 1499from . import git
1500from . import gitsm
1500from . import local 1501from . import local
1501from . import svn 1502from . import svn
1502from . import wget 1503from . import wget
@@ -1513,6 +1514,7 @@ methods.append(local.Local())
1513methods.append(wget.Wget()) 1514methods.append(wget.Wget())
1514methods.append(svn.Svn()) 1515methods.append(svn.Svn())
1515methods.append(git.Git()) 1516methods.append(git.Git())
1517methods.append(gitsm.GitSM())
1516methods.append(cvs.Cvs()) 1518methods.append(cvs.Cvs())
1517methods.append(svk.Svk()) 1519methods.append(svk.Svk())
1518methods.append(ssh.SSH()) 1520methods.append(ssh.SSH())
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 63ff00b..052802e 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -234,7 +234,7 @@ class Git(FetchMethod):
234 def_destsuffix = "git/" 234 def_destsuffix = "git/"
235 235
236 destsuffix = ud.parm.get("destsuffix", def_destsuffix) 236 destsuffix = ud.parm.get("destsuffix", def_destsuffix)
237 destdir = os.path.join(destdir, destsuffix) 237 destdir = ud.destdir = os.path.join(destdir, destsuffix)
238 if os.path.exists(destdir): 238 if os.path.exists(destdir):
239 bb.utils.prunedir(destdir) 239 bb.utils.prunedir(destdir)
240 240
diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py
new file mode 100644
index 0000000..572b637
--- /dev/null
+++ b/bitbake/lib/bb/fetch2/gitsm.py
@@ -0,0 +1,78 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' git submodules implementation
5"""
6
7# Copyright (C) 2013 Richard Purdie
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22import os
23import bb
24from bb import data
25from bb.fetch2.git import Git
26from bb.fetch2 import runfetchcmd
27from bb.fetch2 import logger
28
29class GitSM(Git):
30 def supports(self, url, ud, d):
31 """
32 Check to see if a given url can be fetched with git.
33 """
34 return ud.type in ['gitsm']
35
36 def uses_submodules(self, ud, d):
37 for name in ud.names:
38 try:
39 runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True)
40 return True
41 except bb.fetch.FetchError:
42 pass
43 return False
44
45 def update_submodules(self, u, ud, d):
46 # We have to convert bare -> full repo, do the submodule bit, then convert back
47 tmpclonedir = ud.clonedir + ".tmp"
48 gitdir = tmpclonedir + os.sep + ".git"
49 bb.utils.remove(tmpclonedir, True)
50 os.mkdir(tmpclonedir)
51 os.rename(ud.clonedir, gitdir)
52 runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*true/bare = false/'", d)
53 os.chdir(tmpclonedir)
54 runfetchcmd("git reset --hard", d)
55 runfetchcmd("git submodule init", d)
56 runfetchcmd("git submodule update", d)
57 runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare = true/'", d)
58 os.rename(gitdir, ud.clonedir,)
59 bb.utils.remove(tmpclonedir, True)
60
61 def download(self, loc, ud, d):
62 Git.download(self, loc, ud, d)
63
64 os.chdir(ud.clonedir)
65 submodules = self.uses_submodules(ud, d)
66 if submodules:
67 self.update_submodules(loc, ud, d)
68
69 def unpack(self, ud, destdir, d):
70 Git.unpack(self, ud, destdir, d)
71
72 os.chdir(ud.destdir)
73 submodules = self.uses_submodules(ud, d)
74 if submodules:
75 runfetchcmd("cp -r " + ud.clonedir + "/modules " + ud.destdir + "/.git/", d)
76 runfetchcmd("git submodule init", d)
77 runfetchcmd("git submodule update", d)
78