summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorJoey Degges <jdegges@gmail.com>2022-07-03 14:17:31 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-07-15 12:41:59 +0100
commit9c5b33ccbabfa112da30423e8dad88e235a2b16f (patch)
tree04513098b0a0218e289cb91d998584229343b066 /bitbake
parenteb12590623f97455ade79b63d42335a688da92c5 (diff)
downloadpoky-9c5b33ccbabfa112da30423e8dad88e235a2b16f.tar.gz
bitbake: fetch/git: Fix usehead for non-default names
The usehead url parameter for git repositories causes bitbake to use whatever commit the repository HEAD is pointing to if the repository happens to have the name 'default'. This is the default name so in many cases it works just fine, but if a different name is specified with the url parameter 'name=newName' then it will fail to parse the recipe with an error along the lines of: ERROR: ExpansionError during parsing /path/to/my/recipe.bb Traceback (most recent call last): File "/path/to/poky/bitbake/lib/bb/fetch2/git.py", line 235, in Git.urldata_init: > ud.setup_revisions(d) File "/path/to/poky/bitbake/lib/bb/fetch2/__init__.py", line 1302, in FetchData.setup_revisions: for name in self.names: > self.revisions[name] = srcrev_internal_helper(self, d, name) File "/path/to/poky/bitbake/lib/bb/fetch2/__init__.py", line 1167, in srcrev_internal_helper(name='newName'): if srcrev == "AUTOINC": > srcrev = ud.method.latest_revision(ud, d, name) File "/path/to/poky/bitbake/lib/bb/fetch2/__init__.py", line 1562, in Git.latest_revision(name='newName'): except KeyError: > revs[key] = rev = self._latest_revision(ud, d, name) return rev File "/path/to/poky/bitbake/lib/bb/fetch2/git.py", line 650, in Git._latest_revision(name='newName'): raise bb.fetch2.FetchError("Unable to resolve '%s' in upstream git repository in git ls-remote output for %s" % \ > (ud.unresolvedrev[name], ud.host+ud.path)) bb.data_smart.ExpansionError: Failure expanding variable SRCPV, expression was ${@bb.fetch2.get_srcrev(d)} which triggered exception FetchError: Fetcher failure: Unable to resolve 'master' in upstream git repository in git ls-remote output for /path/to/local/git/repo Let's fix this by setting the unresolved rev of _all_ repository names to 'HEAD' when the usehead url parameter is specified. Update the currently failing test, test_local_gitfetch_usehead_withname, to now expect success. This change preserves existing behavior that allows usehead to be overridden by a valid looking revision if one happens to be specified instead of AUTOREV. (Bitbake rev: a247f56df680382d62910bb9a174e0fdd29e4ca8) Signed-off-by: Joey Degges <jdegges@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 01e901c44ab0f496606b1d45c8953dc54970204c) Signed-off-by: Paulo Neves <ptsneves@gmail.com> Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/fetch2/git.py7
-rw-r--r--bitbake/lib/bb/tests/fetch.py52
2 files changed, 58 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index f6f6b63a74..63a9f92b0a 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -224,7 +224,12 @@ class Git(FetchMethod):
224 ud.shallow = False 224 ud.shallow = False
225 225
226 if ud.usehead: 226 if ud.usehead:
227 ud.unresolvedrev['default'] = 'HEAD' 227 # When usehead is set let's associate 'HEAD' with the unresolved
228 # rev of this repository. This will get resolved into a revision
229 # later. If an actual revision happens to have also been provided
230 # then this setting will be overridden.
231 for name in ud.names:
232 ud.unresolvedrev[name] = 'HEAD'
228 233
229 ud.basecmd = d.getVar("FETCHCMD_git") or "git -c core.fsyncobjectfiles=0" 234 ud.basecmd = d.getVar("FETCHCMD_git") or "git -c core.fsyncobjectfiles=0"
230 235
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 301c468399..484fa58295 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -650,6 +650,58 @@ class FetcherLocalTest(FetcherTest):
650 with self.assertRaises(bb.fetch2.UnpackError): 650 with self.assertRaises(bb.fetch2.UnpackError):
651 self.fetchUnpack(['file://a;subdir=/bin/sh']) 651 self.fetchUnpack(['file://a;subdir=/bin/sh'])
652 652
653 def test_local_gitfetch_usehead(self):
654 # Create dummy local Git repo
655 src_dir = tempfile.mkdtemp(dir=self.tempdir,
656 prefix='gitfetch_localusehead_')
657 src_dir = os.path.abspath(src_dir)
658 bb.process.run("git init", cwd=src_dir)
659 bb.process.run("git commit --allow-empty -m'Dummy commit'",
660 cwd=src_dir)
661 # Use other branch than master
662 bb.process.run("git checkout -b my-devel", cwd=src_dir)
663 bb.process.run("git commit --allow-empty -m'Dummy commit 2'",
664 cwd=src_dir)
665 stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir)
666 orig_rev = stdout[0].strip()
667
668 # Fetch and check revision
669 self.d.setVar("SRCREV", "AUTOINC")
670 url = "git://" + src_dir + ";protocol=file;usehead=1"
671 fetcher = bb.fetch.Fetch([url], self.d)
672 fetcher.download()
673 fetcher.unpack(self.unpackdir)
674 stdout = bb.process.run("git rev-parse HEAD",
675 cwd=os.path.join(self.unpackdir, 'git'))
676 unpack_rev = stdout[0].strip()
677 self.assertEqual(orig_rev, unpack_rev)
678
679 def test_local_gitfetch_usehead_withname(self):
680 # Create dummy local Git repo
681 src_dir = tempfile.mkdtemp(dir=self.tempdir,
682 prefix='gitfetch_localusehead_')
683 src_dir = os.path.abspath(src_dir)
684 bb.process.run("git init", cwd=src_dir)
685 bb.process.run("git commit --allow-empty -m'Dummy commit'",
686 cwd=src_dir)
687 # Use other branch than master
688 bb.process.run("git checkout -b my-devel", cwd=src_dir)
689 bb.process.run("git commit --allow-empty -m'Dummy commit 2'",
690 cwd=src_dir)
691 stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir)
692 orig_rev = stdout[0].strip()
693
694 # Fetch and check revision
695 self.d.setVar("SRCREV", "AUTOINC")
696 url = "git://" + src_dir + ";protocol=file;usehead=1;name=newName"
697 fetcher = bb.fetch.Fetch([url], self.d)
698 fetcher.download()
699 fetcher.unpack(self.unpackdir)
700 stdout = bb.process.run("git rev-parse HEAD",
701 cwd=os.path.join(self.unpackdir, 'git'))
702 unpack_rev = stdout[0].strip()
703 self.assertEqual(orig_rev, unpack_rev)
704
653class FetcherNoNetworkTest(FetcherTest): 705class FetcherNoNetworkTest(FetcherTest):
654 def setUp(self): 706 def setUp(self):
655 super().setUp() 707 super().setUp()