diff options
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 73 |
1 files changed, 27 insertions, 46 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 5cccdf6ef4..b1ff2c005f 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -393,6 +393,15 @@ class FetcherTest(unittest.TestCase): | |||
393 | bb.process.run('chmod u+rw -R %s' % self.tempdir) | 393 | bb.process.run('chmod u+rw -R %s' % self.tempdir) |
394 | bb.utils.prunedir(self.tempdir) | 394 | bb.utils.prunedir(self.tempdir) |
395 | 395 | ||
396 | def git(self, cmd, cwd=None): | ||
397 | if isinstance(cmd, str): | ||
398 | cmd = 'git ' + cmd | ||
399 | else: | ||
400 | cmd = ['git'] + cmd | ||
401 | if cwd is None: | ||
402 | cwd = self.gitdir | ||
403 | return bb.process.run(cmd, cwd=cwd)[0] | ||
404 | |||
396 | class MirrorUriTest(FetcherTest): | 405 | class MirrorUriTest(FetcherTest): |
397 | 406 | ||
398 | replaceuris = { | 407 | replaceuris = { |
@@ -699,28 +708,24 @@ class FetcherLocalTest(FetcherTest): | |||
699 | # Create dummy local Git repo | 708 | # Create dummy local Git repo |
700 | src_dir = tempfile.mkdtemp(dir=self.tempdir, | 709 | src_dir = tempfile.mkdtemp(dir=self.tempdir, |
701 | prefix='gitfetch_localusehead_') | 710 | prefix='gitfetch_localusehead_') |
702 | src_dir = os.path.abspath(src_dir) | 711 | self.gitdir = os.path.abspath(src_dir) |
703 | bb.process.run("git init", cwd=src_dir) | 712 | self.git('init') |
704 | bb.process.run("git config user.email 'you@example.com'", cwd=src_dir) | 713 | self.git('config user.email "you@example.com"') |
705 | bb.process.run("git config user.name 'Your Name'", cwd=src_dir) | 714 | self.git('config user.name "Your Name"') |
706 | bb.process.run("git commit --allow-empty -m'Dummy commit'", | 715 | self.git(['commit', '--allow-empty', '-m', 'Dummy commit']) |
707 | cwd=src_dir) | ||
708 | # Use other branch than master | 716 | # Use other branch than master |
709 | bb.process.run("git checkout -b my-devel", cwd=src_dir) | 717 | self.git(['checkout', '-b', 'my-devel']) |
710 | bb.process.run("git commit --allow-empty -m'Dummy commit 2'", | 718 | self.git(['commit', '--allow-empty', '-m', 'Dummy commit 2']) |
711 | cwd=src_dir) | 719 | orig_rev = self.git(['rev-parse', 'HEAD']).strip() |
712 | stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir) | ||
713 | orig_rev = stdout[0].strip() | ||
714 | 720 | ||
715 | # Fetch and check revision | 721 | # Fetch and check revision |
716 | self.d.setVar("SRCREV", "AUTOINC") | 722 | self.d.setVar("SRCREV", "AUTOINC") |
717 | url = "git://" + src_dir + ";protocol=file;" + suffix | 723 | url = "git://" + self.gitdir + ";protocol=file;" + suffix |
718 | fetcher = bb.fetch.Fetch([url], self.d) | 724 | fetcher = bb.fetch.Fetch([url], self.d) |
719 | fetcher.download() | 725 | fetcher.download() |
720 | fetcher.unpack(self.unpackdir) | 726 | fetcher.unpack(self.unpackdir) |
721 | stdout = bb.process.run("git rev-parse HEAD", | 727 | unpack_rev = self.git(['rev-parse', 'HEAD'], |
722 | cwd=os.path.join(self.unpackdir, 'git')) | 728 | cwd=os.path.join(self.unpackdir, 'git')).strip() |
723 | unpack_rev = stdout[0].strip() | ||
724 | self.assertEqual(orig_rev, unpack_rev) | 729 | self.assertEqual(orig_rev, unpack_rev) |
725 | 730 | ||
726 | def test_local_gitfetch_usehead(self): | 731 | def test_local_gitfetch_usehead(self): |
@@ -920,7 +925,8 @@ class FetcherNetworkTest(FetcherTest): | |||
920 | def gitfetcher(self, url1, url2): | 925 | def gitfetcher(self, url1, url2): |
921 | def checkrevision(self, fetcher): | 926 | def checkrevision(self, fetcher): |
922 | fetcher.unpack(self.unpackdir) | 927 | fetcher.unpack(self.unpackdir) |
923 | revision = bb.process.run("git rev-parse HEAD", shell=True, cwd=self.unpackdir + "/git")[0].strip() | 928 | revision = self.git(['rev-parse', 'HEAD'], |
929 | cwd=os.path.join(self.unpackdir, 'git')).strip() | ||
924 | self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5") | 930 | self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5") |
925 | 931 | ||
926 | self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1") | 932 | self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1") |
@@ -996,7 +1002,7 @@ class FetcherNetworkTest(FetcherTest): | |||
996 | recipeurl = "git://someserver.org/bitbake" | 1002 | recipeurl = "git://someserver.org/bitbake" |
997 | self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") | 1003 | self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") |
998 | os.chdir(self.tempdir) | 1004 | os.chdir(self.tempdir) |
999 | bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True) | 1005 | self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir) |
1000 | self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file" % (recipeurl, self.sourcedir)) | 1006 | self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file" % (recipeurl, self.sourcedir)) |
1001 | self.gitfetcher(recipeurl, recipeurl) | 1007 | self.gitfetcher(recipeurl, recipeurl) |
1002 | 1008 | ||
@@ -1437,9 +1443,9 @@ class GitMakeShallowTest(FetcherTest): | |||
1437 | FetcherTest.setUp(self) | 1443 | FetcherTest.setUp(self) |
1438 | self.gitdir = os.path.join(self.tempdir, 'gitshallow') | 1444 | self.gitdir = os.path.join(self.tempdir, 'gitshallow') |
1439 | bb.utils.mkdirhier(self.gitdir) | 1445 | bb.utils.mkdirhier(self.gitdir) |
1440 | bb.process.run('git init', cwd=self.gitdir) | 1446 | self.git('init') |
1441 | bb.process.run('git config user.email "you@example.com"', cwd=self.gitdir) | 1447 | self.git('config user.email "you@example.com"') |
1442 | bb.process.run('git config user.name "Your Name"', cwd=self.gitdir) | 1448 | self.git('config user.name "Your Name"') |
1443 | 1449 | ||
1444 | def assertRefs(self, expected_refs): | 1450 | def assertRefs(self, expected_refs): |
1445 | actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines() | 1451 | actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines() |
@@ -1453,13 +1459,6 @@ class GitMakeShallowTest(FetcherTest): | |||
1453 | actual_count = len(revs.splitlines()) | 1459 | actual_count = len(revs.splitlines()) |
1454 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) | 1460 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) |
1455 | 1461 | ||
1456 | def git(self, cmd): | ||
1457 | if isinstance(cmd, str): | ||
1458 | cmd = 'git ' + cmd | ||
1459 | else: | ||
1460 | cmd = ['git'] + cmd | ||
1461 | return bb.process.run(cmd, cwd=self.gitdir)[0] | ||
1462 | |||
1463 | def make_shallow(self, args=None): | 1462 | def make_shallow(self, args=None): |
1464 | if args is None: | 1463 | if args is None: |
1465 | args = ['HEAD'] | 1464 | args = ['HEAD'] |
@@ -1595,15 +1594,6 @@ class GitShallowTest(FetcherTest): | |||
1595 | actual_count = len(revs.splitlines()) | 1594 | actual_count = len(revs.splitlines()) |
1596 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) | 1595 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) |
1597 | 1596 | ||
1598 | def git(self, cmd, cwd=None): | ||
1599 | if isinstance(cmd, str): | ||
1600 | cmd = 'git ' + cmd | ||
1601 | else: | ||
1602 | cmd = ['git'] + cmd | ||
1603 | if cwd is None: | ||
1604 | cwd = self.gitdir | ||
1605 | return bb.process.run(cmd, cwd=cwd)[0] | ||
1606 | |||
1607 | def add_empty_file(self, path, cwd=None, msg=None): | 1597 | def add_empty_file(self, path, cwd=None, msg=None): |
1608 | if msg is None: | 1598 | if msg is None: |
1609 | msg = path | 1599 | msg = path |
@@ -2140,7 +2130,7 @@ class GitLfsTest(FetcherTest): | |||
2140 | 2130 | ||
2141 | self.gitdir = os.path.join(self.tempdir, 'git') | 2131 | self.gitdir = os.path.join(self.tempdir, 'git') |
2142 | self.srcdir = os.path.join(self.tempdir, 'gitsource') | 2132 | self.srcdir = os.path.join(self.tempdir, 'gitsource') |
2143 | 2133 | ||
2144 | self.d.setVar('WORKDIR', self.tempdir) | 2134 | self.d.setVar('WORKDIR', self.tempdir) |
2145 | self.d.setVar('S', self.gitdir) | 2135 | self.d.setVar('S', self.gitdir) |
2146 | self.d.delVar('PREMIRRORS') | 2136 | self.d.delVar('PREMIRRORS') |
@@ -2158,15 +2148,6 @@ class GitLfsTest(FetcherTest): | |||
2158 | self.git(['add', '.gitattributes'], cwd=self.srcdir) | 2148 | self.git(['add', '.gitattributes'], cwd=self.srcdir) |
2159 | self.git(['commit', '-m', "attributes", '.gitattributes'], cwd=self.srcdir) | 2149 | self.git(['commit', '-m', "attributes", '.gitattributes'], cwd=self.srcdir) |
2160 | 2150 | ||
2161 | def git(self, cmd, cwd=None): | ||
2162 | if isinstance(cmd, str): | ||
2163 | cmd = 'git ' + cmd | ||
2164 | else: | ||
2165 | cmd = ['git'] + cmd | ||
2166 | if cwd is None: | ||
2167 | cwd = self.gitdir | ||
2168 | return bb.process.run(cmd, cwd=cwd)[0] | ||
2169 | |||
2170 | def fetch(self, uri=None, download=True): | 2151 | def fetch(self, uri=None, download=True): |
2171 | uris = self.d.getVar('SRC_URI').split() | 2152 | uris = self.d.getVar('SRC_URI').split() |
2172 | uri = uris[0] | 2153 | uri = uris[0] |