Skip to content

Commit

Permalink
fetch2/cooker: Fix source revision handling with floating upstreams
Browse files Browse the repository at this point in the history
Where a git url uses a tag instead of a full source revision, breakage
can currently occur in builds. Issues include:

* the revision being looked up in multiple tasks (fetch and unpack)
* the risk a different revision may be obtained in those tasks
* that some tasks may not be allowed to access the network
* that a revision may not be consistent throughout a given build
* rerunning a specific task may given inconsistent results

To fix this, stop the workers from cleaning out the source revision store. This
should only be done in the cooker itself (based on current policy).

Also, where the code "sees" an upstream access, mark the recipe as not to be
cached. The reparse re-triggers the upstream lookup by the server.

Add a test to ensure that if get_srcrev isn't called, the user is told they're
using a configuration that is known to break.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
  • Loading branch information
rpurdie committed Feb 17, 2022
1 parent e514488 commit 4b5eed1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/bitbake-worker
Expand Up @@ -440,7 +440,7 @@ class BitbakeWorker(object):
def handle_cookercfg(self, data):
self.cookercfg = pickle.loads(data)
self.databuilder = bb.cookerdata.CookerDataBuilder(self.cookercfg, worker=True)
self.databuilder.parseBaseConfiguration()
self.databuilder.parseBaseConfiguration(worker=True)
self.data = self.databuilder.data

def handle_extraconfigdata(self, data):
Expand Down
4 changes: 2 additions & 2 deletions lib/bb/cookerdata.py
Expand Up @@ -258,12 +258,12 @@ def __init__(self, cookercfg, worker = False):
self.data = self.basedata
self.mcdata = {}

def parseBaseConfiguration(self):
def parseBaseConfiguration(self, worker=False):
data_hash = hashlib.sha256()
try:
self.data = self.parseConfigurationFiles(self.prefiles, self.postfiles)

if self.data.getVar("BB_WORKERCONTEXT", False) is None:
if self.data.getVar("BB_WORKERCONTEXT", False) is None and not worker:
bb.fetch.fetcher_init(self.data)
bb.parse.init_parser(self.data)
bb.codeparser.parser_cache_init(self.data)
Expand Down
1 change: 1 addition & 0 deletions lib/bb/fetch2/__init__.py
Expand Up @@ -765,6 +765,7 @@ def get_srcrev(d, method_name='sortable_revision'):
that fetcher provides a method with the given name and the same signature as sortable_revision.
"""

d.setVar("__BBSEENSRCREV", "1")
recursion = d.getVar("__BBINSRCREV")
if recursion:
raise FetchError("There are recursive references in fetcher variables, likely through SRC_URI")
Expand Down
6 changes: 6 additions & 0 deletions lib/bb/fetch2/git.py
Expand Up @@ -727,6 +727,12 @@ def _latest_revision(self, ud, d, name):
"""
Compute the HEAD revision for the url
"""
if not d.getVar("__BBSEENSRCREV"):
raise bb.fetch2.FetchError("Recipe uses a floating tag/branch without a fixed SRCREV yet doesn't call bb.fetch2.get_srcrev() (use SRCPV in PV for OE).")

# Ensure we mark as not cached
bb.fetch2.get_autorev(d)

output = self._lsremote(ud, d, "")
# Tags of the form ^{} may not work, need to fallback to other form
if ud.unresolvedrev[name][:5] == "refs/" or ud.usehead:
Expand Down
4 changes: 4 additions & 0 deletions lib/bb/tests/fetch.py
Expand Up @@ -728,6 +728,7 @@ def dummyGitTest(self, suffix):

# Fetch and check revision
self.d.setVar("SRCREV", "AUTOINC")
self.d.setVar("__BBSEENSRCREV", "1")
url = "git://" + self.gitdir + ";branch=master;protocol=file;" + suffix
fetcher = bb.fetch.Fetch([url], self.d)
fetcher.download()
Expand Down Expand Up @@ -1581,6 +1582,7 @@ def setUp(self):
self.d.setVar('BB_GIT_SHALLOW', '1')
self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0')
self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
self.d.setVar("__BBSEENSRCREV", "1")

def assertRefs(self, expected_refs, cwd=None):
if cwd is None:
Expand Down Expand Up @@ -2138,6 +2140,7 @@ def setUp(self):

self.d.setVar('SRCREV', '${AUTOREV}')
self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}')
self.d.setVar("__BBSEENSRCREV", "1")

bb.utils.mkdirhier(self.srcdir)
self.git_init(cwd=self.srcdir)
Expand Down Expand Up @@ -2746,6 +2749,7 @@ def setUp(self):
super(GitSharedTest, self).setUp()
self.recipe_url = "git://git.openembedded.org/bitbake;branch=master"
self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
self.d.setVar("__BBSEENSRCREV", "1")

@skipIfNoNetwork()
def test_shared_unpack(self):
Expand Down

0 comments on commit 4b5eed1

Please sign in to comment.