Skip to contentSkip to conversation

Add symlinks for git (shallow) tarballs when name differs due to mirror rewrite rules

PATCH Superseded Urs Fässler 2 participants 9 messages Oct 15, 2018 – Oct 16, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add symlinks for git (shallow) tarballs when name differs due to mirror rewrite rules

The git (shallow) tarballs are not found when certain mirror rewrite rules are in use. This is due to the fact that the tarball is named according to the url where it is downloaded from. The error occurs in the unpack step where BitBake looks for a tarball named after the url as specified in the recipe. By adding the symlinks BitBake finds the tarballs in the unpack step.

This is an alternative to the patches "Always use the url specified in the recipe as a base for the git shallow tarball naming" from the 23.07.2018. This solution is more aligned to the current implementation of BitBake.

Regards
Urs

Urs Fässler (7):
fetch2/git: add tests to capture existing behavior wrt. naming of
clone directories
fetch2/git: add tests to capture existing behavior wrt. naming of
mirror tarball
fetch2/git: add tests to capture existing behavior wrt. naming of git
shallow tarball
fetch2/git: use intention revealing names for premirror tests
fetch2: extract the function which ensures that a valid symlink exists
fetch2: add symlinks for mirror tarballs
fetch2: add symlink for shallow mirror tarballs

 lib/bb/fetch2/__init__.py |  31 +++--
 lib/bb/tests/fetch.py     | 235 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 246 insertions(+), 20 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/7 fetch2/git: add tests to capture existing behavior wrt. naming of clone directories

The mapping of the URLs to the local directory is not obvious. For easier understanding, we add this tests to explicitly showing the mapping.

---
 lib/bb/tests/fetch.py | 49 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
lib/bb/tests/fetch.py +49 -0
index ff66315a..53595312 100644
@@ -463,6 +463,55 @@ class MirrorUriTest(FetcherTest):
                                 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz',
                                 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz'])
 
+
+class GitDownloadDirectoryNamingTest(FetcherTest):
+    def setUp(self):
+        super(GitDownloadDirectoryNamingTest, self).setUp()
+        self.recipe_url = "git://git.openembedded.org/bitbake"
+        self.recipe_dir = "git.openembedded.org.bitbake"
+        self.mirror_url = "git://github.com/openembedded/bitbake.git"
+        self.mirror_dir = "github.com.openembedded.bitbake.git"
+
+        self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
+
+    def setup_mirror_rewrite(self):
+        self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
+
+    @skipIfNoNetwork()
+    def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self):
+        self.setup_mirror_rewrite()
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir + "/git2")
+        self.assertIn(self.recipe_dir, dir)
+
+    @skipIfNoNetwork()
+    def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self):
+        self.setup_mirror_rewrite()
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir + "/git2")
+        self.assertIn(self.mirror_dir, dir)
+        self.assertIn(self.recipe_dir, dir)
+
+    @skipIfNoNetwork()
+    def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self):
+        self.setup_mirror_rewrite()
+        fetcher = bb.fetch.Fetch([self.mirror_url], self.d)
+        fetcher.download()
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir + "/git2")
+        self.assertIn(self.mirror_dir, dir)
+        self.assertIn(self.recipe_dir, dir)
+
+
 class FetcherLocalTest(FetcherTest):
     def setUp(self):
         def touch(fn):
Signature · 1 line
2.19.1
#2 lore raw

PATCH 2/7 fetch2/git: add tests to capture existing behavior wrt. naming of mirror tarball

In reply to Urs Fässler

The mapping of the URLs to the local tarballs is not obvious. For easier understanding, we add this tests to explicitly showing the mapping.

---
 lib/bb/tests/fetch.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
lib/bb/tests/fetch.py +34 -0
index 53595312..dcc4d8ce 100644
@@ -512,6 +512,40 @@ class GitDownloadDirectoryNamingTest(FetcherTest):
         self.assertIn(self.recipe_dir, dir)
 
 
+class TarballNamingTest(FetcherTest):
+    def setUp(self):
+        super(TarballNamingTest, self).setUp()
+        self.recipe_url = "git://git.openembedded.org/bitbake"
+        self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz"
+        self.mirror_url = "git://github.com/openembedded/bitbake.git"
+        self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz"
+
+        self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1')
+        self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
+
+    def setup_mirror_rewrite(self):
+        self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
+
+    @skipIfNoNetwork()
+    def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self):
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir)
+        self.assertIn(self.recipe_tarball, dir)
+
+    @skipIfNoNetwork()
+    def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
+        self.setup_mirror_rewrite()
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir)
+        self.assertIn(self.mirror_tarball, dir)
+
+
 class FetcherLocalTest(FetcherTest):
     def setUp(self):
         def touch(fn):
Signature · 1 line
2.19.1
#3 lore raw

PATCH 3/7 fetch2/git: add tests to capture existing behavior wrt. naming of git shallow tarball

In reply to Urs Fässler

The mapping of the URLs to the local shallow tarballs is not obvious. For easier understanding, we add this tests to explicitly showing the mapping.

---
 lib/bb/tests/fetch.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/bb/tests/fetch.py +35 -0
index dcc4d8ce..79be1be0 100644
@@ -546,6 +546,41 @@ class TarballNamingTest(FetcherTest):
         self.assertIn(self.mirror_tarball, dir)
 
 
+class GitShallowTarballNamingTest(FetcherTest):
+    def setUp(self):
+        super(GitShallowTarballNamingTest, self).setUp()
+        self.recipe_url = "git://git.openembedded.org/bitbake"
+        self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz"
+        self.mirror_url = "git://github.com/openembedded/bitbake.git"
+        self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz"
+
+        self.d.setVar('BB_GIT_SHALLOW', '1')
+        self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1')
+        self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40')
+
+    def setup_mirror_rewrite(self):
+        self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url + " \n")
+
+    @skipIfNoNetwork()
+    def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self):
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir)
+        self.assertIn(self.recipe_tarball, dir)
+
+    @skipIfNoNetwork()
+    def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self):
+        self.setup_mirror_rewrite()
+        fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
+
+        fetcher.download()
+
+        dir = os.listdir(self.dldir)
+        self.assertIn(self.mirror_tarball, dir)
+
+
 class FetcherLocalTest(FetcherTest):
     def setUp(self):
         def touch(fn):
Signature · 1 line
2.19.1
#4 lore raw

PATCH 4/7 fetch2/git: use intention revealing names for premirror tests

In reply to Urs Fässler
---
 lib/bb/tests/fetch.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
lib/bb/tests/fetch.py +11 -11
index 79be1be0..9bed06ba 100644
@@ -869,27 +869,27 @@ class FetcherNetworkTest(FetcherTest):
         self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url)
 
     @skipIfNoNetwork()
-    def test_gitfetch_premirror(self):
-        url1 = "git://git.openembedded.org/bitbake"
-        url2 = "git://someserver.org/bitbake"
+    def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self):
+        recipeurl = "git://git.openembedded.org/bitbake"
+        mirrorurl = "git://someserver.org/bitbake"
         self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
-        self.gitfetcher(url1, url2)
+        self.gitfetcher(recipeurl, mirrorurl)
 
     @skipIfNoNetwork()
-    def test_gitfetch_premirror2(self):
-        url1 = url2 = "git://someserver.org/bitbake"
+    def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self):
+        recipeurl = "git://someserver.org/bitbake"
         self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake \n")
-        self.gitfetcher(url1, url2)
+        self.gitfetcher(recipeurl, recipeurl)
 
     @skipIfNoNetwork()
-    def test_gitfetch_premirror3(self):
+    def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self):
         realurl = "git://git.openembedded.org/bitbake"
-        dummyurl = "git://someserver.org/bitbake"
+        recipeurl = "git://someserver.org/bitbake"
         self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git")
         os.chdir(self.tempdir)
         bb.process.run("git clone %s %s 2> /dev/null" % (realurl, self.sourcedir), shell=True)
-        self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (dummyurl, self.sourcedir))
-        self.gitfetcher(dummyurl, dummyurl)
+        self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file \n" % (recipeurl, self.sourcedir))
+        self.gitfetcher(recipeurl, recipeurl)
 
     @skipIfNoNetwork()
     def test_git_submodule(self):
Signature · 1 line
2.19.1
#5 lore raw

PATCH 5/7 fetch2: extract the function which ensures that a valid symlink exists

In reply to Urs Fässler

For better readability and future use, we extract the function which ensures that a given symlink exists.

---
 lib/bb/fetch2/__init__.py | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
lib/bb/fetch2/__init__.py +17 -10
index a83526a5..458f3107 100644
@@ -1016,16 +1016,7 @@ def try_mirror_url(fetch, origud, ud, ld, check = False):
                     origud.method.build_mirror_data(origud, ld)
             return origud.localpath
         # Otherwise the result is a local file:// and we symlink to it
-        if not os.path.exists(origud.localpath):
-            if os.path.islink(origud.localpath):
-                # Broken symbolic link
-                os.unlink(origud.localpath)
-
-            # As per above, in case two tasks end up here simultaneously.
-            try:
-                os.symlink(ud.localpath, origud.localpath)
-            except FileExistsError:
-                pass
+        ensure_symlink(ud.localpath, origud.localpath)
         update_stamp(origud, ld)
         return ud.localpath
 
@@ -1059,6 +1050,22 @@ def try_mirror_url(fetch, origud, ud, ld, check = False):
             bb.utils.unlockfile(lf)
 
 
+def ensure_symlink(target, link_name):
+    if not os.path.exists(link_name):
+        if os.path.islink(link_name):
+            # Broken symbolic link
+            os.unlink(link_name)
+
+        # In case this is executing without any file locks held (as is
+        # the case for file:// URLs), two tasks may end up here at the
+        # same time, in which case we do not want the second task to
+        # fail when the link has already been created by the first task.
+        try:
+            os.symlink(target, link_name)
+        except FileExistsError:
+            pass
+
+
 def try_mirrors(fetch, d, origud, mirrors, check = False):
     """
     Try to use a mirrored version of the sources.
Signature · 1 line
2.19.1
#6 lore raw

PATCH 6/7 fetch2: add symlinks for mirror tarballs

In reply to Urs Fässler

In the unpack step the mirror tarball is not found when the mirrored tarball is named differently than the original tarball. This happens due to mirror rewrite rules. To solve the problem we add symlinks for the differently named tarballs.

---
 lib/bb/fetch2/__init__.py |  4 +++
 lib/bb/tests/fetch.py     | 53 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +4 -0
index 458f3107..a1b03a95 100644
@@ -1017,6 +1017,10 @@ def try_mirror_url(fetch, origud, ud, ld, check = False):
             return origud.localpath
         # Otherwise the result is a local file:// and we symlink to it
         ensure_symlink(ud.localpath, origud.localpath)
+
+        if os.path.exists(ud.fullmirror):
+            ensure_symlink(ud.fullmirror, origud.fullmirror)
+
         update_stamp(origud, ld)
         return ud.localpath
 
lib/bb/tests/fetch.py +52 -1

83 lines not on this page · raw message

Signature · 1 line
2.19.1
#7 lore raw

PATCH 7/7 fetch2: add symlink for shallow mirror tarballs

In reply to Urs Fässler

In the unpack step the shallow mirror tarball is not found when the mirrored tarball is named differently than the original tarball. This happens due to mirror rewrite rules. To solve the problem we add symlinks for the differently named tarballs.

---
 lib/bb/fetch2/__init__.py |  2 ++
 lib/bb/tests/fetch.py     | 44 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
lib/bb/fetch2/__init__.py +2 -0
index a1b03a95..6cbaf413 100644
@@ -1020,6 +1020,8 @@ def try_mirror_url(fetch, origud, ud, ld, check = False):
 
         if os.path.exists(ud.fullmirror):
             ensure_symlink(ud.fullmirror, origud.fullmirror)
+        if ud.shallow and os.path.exists(ud.fullshallow):
+            ensure_symlink(ud.fullshallow, origud.fullshallow)
 
         update_stamp(origud, ld)
         return ud.localpath
lib/bb/tests/fetch.py +44 -0

53 lines not on this page · raw message

Signature · 1 line
2.19.1
#8 lore raw
In reply to Urs Fässler
Quoted 9 lines · Urs Fässler

The git (shallow) tarballs are not found when certain mirror rewrite rules are in use. This is due to the fact that the tarball is named according to the url where it is downloaded from. The error occurs in the unpack step where BitBake looks for a tarball named after the url as specified in the recipe. By adding the symlinks BitBake finds the tarballs in the unpack step.

This is an alternative to the patches "Always use the url specified in the recipe as a base for the git shallow tarball naming" from the 23.07.2018. This solution is more aligned to the current implementation of BitBake.

This patch series does look much more in keeping with the way bitbake is written and is easier to review.

I tried it on the autobuilder and it resulted in:

https://autobuilder.yoctoproject.org/typhoon/#/builders/23/builds/120/steps/7/logs/step2b

I'm a bit nervous about accepting these in right now given we're so close to releasing 2.6 :/.

Cheers,

Richard