Skip to contentSkip to conversation

tests/fetch: add test_git_submodule_branch_new_module

PATCH In review Christopher Larson 3 participants 8 messages Aug 21, 2017 – Aug 23, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tests/fetch: add test_git_submodule_branch_new_module

From: Christopher Larson <[email protected]>

This local test validates that we can switch branches for a gitsm URI and the submodules are correct for that branch when unpacked.

[YOCTO #11830]

---
 lib/bb/tests/fetch.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 3 deletions(-)
lib/bb/tests/fetch.py +57 -3
index faa5c74a..f91621c0 100644
@@ -19,11 +19,12 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 
-import unittest
-import tempfile
-import subprocess
 import collections
 import os
+import shutil
+import subprocess
+import tempfile
+import unittest
 from bb.fetch2 import URI
 from bb.fetch2 import FetchMethod
 import bb
@@ -517,6 +518,59 @@ class FetcherLocalTest(FetcherTest):
         with self.assertRaises(bb.fetch2.UnpackError):
             self.fetchUnpack(['file://a;subdir=/bin/sh'])
 
+    def test_git_submodule_branch_new_module(self):
+        def git(gitdir, *cmd):
+            if len(cmd) == 1 and isinstance(cmd[0], list, str):
+                cmd = cmd[0]
+
+            if isinstance(cmd, str):
+                cmd = 'git ' + cmd
+            else:
+                cmd = ['git'] + list(cmd)
+            return bb.process.run(cmd, cwd=gitdir)[0]
+
+        def newrepo(name):
+            gitdir = os.path.join(self.tempdir, name)
+            bb.process.run(['git', 'init', gitdir])
+            open(os.path.join(gitdir, 'a'), 'w').close()
+            git(gitdir, 'add', 'a')
+            git(gitdir, 'commit', '-m', 'add a')
+            return gitdir
+
+        sub1 = newrepo('upstream-submodule1')
+        upstream = newrepo('upstream')
+        git(upstream, 'submodule', 'add', sub1, 'sub1')
+        git(upstream, 'add', '.gitmodules')
+        git(upstream, 'commit', '-m', 'add submodule1')
+
+        git(upstream, 'checkout', '-b', 'with-sub2')
+        sub2 = newrepo('upstream-submodule2')
+        git(upstream, 'submodule', 'add', sub2, 'sub2')
+        git(upstream, 'add', '.gitmodules')
+        git(upstream, 'commit', '-m', 'add submodule2')
+
+        git(upstream, 'checkout', 'master')
+
+        self.d.setVar('SRCREV', '${@bb.fetch2.get_autorev(d)}')
+
+        bb.utils.mkdirhier(self.unpackdir)
+        tree = self.fetchUnpack(["gitsm://%s;protocol=file;branch=master" % upstream])
+        tree = filter(lambda f: not f.startswith('git/.git/'), tree)
+        self.assertEqual(list(tree), ['git/.gitmodules', 'git/a', 'git/sub1/.git', 'git/sub1/a'])
+
+        shutil.rmtree(self.unpackdir)
+        bb.utils.mkdirhier(self.unpackdir)
+        tree = self.fetchUnpack(["gitsm://%s;protocol=file;branch=with-sub2" % upstream])
+        tree = filter(lambda f: not f.startswith('git/.git/'), tree)
+        self.assertEqual(list(tree), ['git/.gitmodules', 'git/a', 'git/sub1/.git', 'git/sub1/a', 'git/sub2/.git', 'git/sub2/a'])
+
+        shutil.rmtree(self.unpackdir)
+        bb.utils.mkdirhier(self.unpackdir)
+        tree = self.fetchUnpack(["gitsm://%s;protocol=file;branch=master" % upstream])
+        tree = filter(lambda f: not f.startswith('git/.git/'), tree)
+        self.assertEqual(list(tree), ['git/.gitmodules', 'git/a', 'git/sub1/.git', 'git/sub1/a'])
+
+
 class FetcherNetworkTest(FetcherTest):
 
     if os.environ.get("BB_SKIP_NETTESTS") == "yes":
Signature · 1 line
2.11.1
#1 lore raw

PATCH 2/2 Revert "fetch2/gitsm: Fix when repository change submodules"

From: Christopher Larson <[email protected]>

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

This commit caused the gitsm fetcher to download submodules from upstream in do_unpack, rather than using the previously fetched submodules from DL_DIR.

[YOCTO #11830]

---
 lib/bb/fetch2/gitsm.py | 1 +
 1 file changed, 1 insertion(+)
lib/bb/fetch2/gitsm.py +1 -0
index 0aff1008..167b77a1 100644
@@ -131,5 +131,6 @@ class GitSM(Git):
         Git.unpack(self, ud, destdir, d)
 
         if self.uses_submodules(ud, d, ud.destdir):
+            runfetchcmd('cp -fpPRH "%s/modules" "%s/"' % (ud.clonedir, os.path.join(ud.destdir, '.git')), d)
             runfetchcmd(ud.basecmd + " checkout " + ud.revisions[ud.names[0]], d, workdir=ud.destdir)
             runfetchcmd(ud.basecmd + " submodule update --init --recursive", d, workdir=ud.destdir)
Signature · 1 line
2.11.1
#2 lore raw

Re: [PATCH 2/2] Revert "fetch2/gitsm: Fix when repository change submodules"

Quoted 11 lines · Christopher Larson

From: Christopher Larson <[email protected]>

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

This commit caused the gitsm fetcher to download submodules from upstream in
do_unpack, rather than using the previously fetched submodules from DL_DIR.

[YOCTO #11830]

Hold off on this for the moment, looks like it broke use of gitshallow. Fixing now.

Signature · 4 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Senior Software Engineer, Mentor Graphics
#3 lore raw

PATCH v2 1/1 fetch2/gitsm: copy submodules from DL_DIR in unpack

In reply to Christopher Larson

From: Christopher Larson <[email protected]>

Revert "fetch2/gitsm: Fix when repository change submodules"

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

This commit caused the gitsm fetcher to download submodules from upstream in do_unpack, rather than using the previously fetched submodules from DL_DIR. Also drop the pointless checkout, as Git.unpack() already handles this correctly.

[YOCTO #11830]

---
 lib/bb/fetch2/gitsm.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/bb/fetch2/gitsm.py +2 -1
index 0aff1008..ed94c3d7 100644
@@ -131,5 +131,6 @@ class GitSM(Git):
         Git.unpack(self, ud, destdir, d)
 
         if self.uses_submodules(ud, d, ud.destdir):
-            runfetchcmd(ud.basecmd + " checkout " + ud.revisions[ud.names[0]], d, workdir=ud.destdir)
+            if not ud.shallow or ud.localpath != ud.fullshallow:
+                runfetchcmd('cp -fpPRH "%s/modules" "%s/"' % (ud.clonedir, os.path.join(ud.destdir, '.git')), d)
             runfetchcmd(ud.basecmd + " submodule update --init --recursive", d, workdir=ud.destdir)
Signature · 1 line
2.11.1
#4 lore raw

Re: [PATCHv2] fetch2/gitsm: copy submodules from DL_DIR in unpack

Supercedes "[PATCH 2/2] Revert "fetch2/gitsm: Fix when repository change submodules””.

Quoted 38 lines · Christopher Larson

From: Christopher Larson <[email protected]>

Revert "fetch2/gitsm: Fix when repository change submodules"

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

This commit caused the gitsm fetcher to download submodules from upstream in
do_unpack, rather than using the previously fetched submodules from DL_DIR. Also drop the pointless checkout, as Git.unpack() already handles this correctly.

[YOCTO #11830]

---
 lib/bb/fetch2/gitsm.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/bb/fetch2/gitsm.py +2 -1
index 0aff1008..ed94c3d7 100644
@@ -131,5 +131,6 @@ class GitSM(Git):
         Git.unpack(self, ud, destdir, d)
 
         if self.uses_submodules(ud, d, ud.destdir):
-            runfetchcmd(ud.basecmd + " checkout " +
 ud.revisions[ud.names[0]], d, workdir=ud.destdir)
+            if not ud.shallow or ud.localpath != ud.fullshallow:
+                runfetchcmd('cp -fpPRH "%s/modules" "%s/"' %

(ud.clonedir, os.path.join(ud.destdir, '.git')), d)

             runfetchcmd(ud.basecmd + " submodule update --init

--recursive", d, workdir=ud.destdir)
--
2.11.1

Signature · 4 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Senior Software Engineer, Mentor Graphics
#5 lore raw

Re: [PATCHv2] fetch2/gitsm: copy submodules from DL_DIR in unpack

In reply to Christopher Larson
Quoted 28 lines · Christopher Larson

From: Christopher Larson <[email protected]>

Revert "fetch2/gitsm: Fix when repository change submodules"

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

This commit caused the gitsm fetcher to download submodules from upstream in
do_unpack, rather than using the previously fetched submodules from DL_DIR.
Also drop the pointless checkout, as Git.unpack() already handles this
correctly.

[YOCTO #11830]

---
 lib/bb/fetch2/gitsm.py | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
lib/bb/fetch2/gitsm.py +0 -0
index 0aff1008..ed94c3d7 100644
@@ -131,5 +131,6 @@ class GitSM(Git):
          Git.unpack(self, ud, destdir, d)

Quoted 8 lines

         if self.uses_submodules(ud, d, ud.destdir):
-            runfetchcmd(ud.basecmd + " checkout " + ud.revisions[ud.names[0]], d, workdir=ud.destdir)
+            if not ud.shallow or ud.localpath != ud.fullshallow:
+                runfetchcmd('cp -fpPRH "%s/modules" "%s/"' % (ud.clonedir, os.path.join(ud.destdir, '.git')), d) runfetchcmd(ud.basecmd + " submodule update --init -- recursive", d, workdir=ud.destdir)

With these two patches applied (as in master-next), I'm seeing:

$ oe-selftest -r devtool.DevtoolTests.test_devtool_add_fetch_git
2017-08-23 11:19:39,203 - oe-selftest - INFO - Adding layer libraries:
2017-08-23 11:19:39,204 - oe-selftest - INFO - 	/media/build1/poky/meta/lib
2017-08-23 11:19:39,204 - oe-selftest - INFO - 	/media/build1/poky/meta-yocto-bsp/lib
2017-08-23 11:19:39,204 - oe-selftest - INFO - 	/media/build1/poky/meta-selftest/lib
2017-08-23 11:19:39,204 - oe-selftest - INFO - Running bitbake -p
2017-08-23 11:19:41,433 - oe-selftest - INFO - Running tests...----------------------------------------------------------------------
2017-08-23 11:19:41,433 - oe-selftest - INFO - Adding: "include selftest.inc" in /media/build1/poky/build/conf/local.conf
2017-08-23 11:19:42,989 - oe-selftest - INFO -   test_devtool_add_fetch_git (devtool.DevtoolTests)
2017-08-23 11:20:14,813 - oe-selftest - WARNING - tearDown commands have failed: bitbake -c cleansstate mraa
2017-08-23 11:20:14,815 - oe-selftest - INFO -  ... FAIL (31.826s)
2017-08-23 11:20:14,819 - oe-selftest - INFO - ======================================================================
2017-08-23 11:20:14,819 - oe-selftest - INFO - FAIL [31.826s]: test_devtool_add_fetch_git (devtool.DevtoolTests)
2017-08-23 11:20:14,819 - oe-selftest - INFO - ----------------------------------------------------------------------
2017-08-23 11:20:14,819 - oe-selftest - INFO - Traceback (most recent call last):
  File "/media/build1/poky/meta/lib/oeqa/core/decorator/__init__.py", line 32, in wrapped_f
    return func(*args, **kwargs)
  File "/media/build1/poky/meta/lib/oeqa/selftest/cases/devtool.py", line 392, in test_devtool_add_fetch_git
    result = runCmd('devtool add %s %s -f "%s" -V 1.5' % (testrecipe, srcdir, url_rev))
  File "/media/build1/poky/meta/lib/oeqa/utils/commands.py", line 191, in runCmd
    raise AssertionError("Command '%s' returned non-zero exit status %d:\n%s" % (command, result.status, exc_output))
AssertionError: Command 'devtool add mraa /tmp/devtoolqa9peegimn/mraa -f "gitsm://git.yoctoproject.org/mraa;rev=ae127b19a50aa54255e4330ccfdd9a5d058e581d" -V 1.5' returned non-zero exit status 1:
NOTE: Starting bitbake server...
WARNING: -f/--fetch option is deprecated - you can now simply specify the URL to fetch as a positional argument instead
NOTE: Starting bitbake server...
NOTE: Fetching gitsm://git.yoctoproject.org/mraa;rev=ae127b19a50aa54255e4330ccfdd9a5d058e581d;nobranch=1...
NOTE: Starting bitbake server...
Loading cache...done.
Loaded 1292 entries from dependency cache.
Parsing recipes...done.
Parsing of 835 .bb files complete (834 cached, 1 parsed). 1290 targets, 74 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION        = "1.35.0"
BUILD_SYS         = "x86_64-linux"
NATIVELSBSTRING   = "universal"
TARGET_SYS        = "mips-poky-linux"
MACHINE           = "qemumips"
DISTRO            = "poky"
DISTRO_VERSION    = "2.3"
TUNE_FEATURES     = "o32 bigendian fpu-hard mips32r2" TARGET_FPU        = ""
meta
meta-poky
meta-yocto-bsp    = "wip:fb706fa5934fab53c0858d7e9a36c07e3fb7bb65" meta-mingw        = "master:0679d2a91575bd7f3efd0973aa99d7ee681e9395" meta-selftest
workspace         = "wip:fb706fa5934fab53c0858d7e9a36c07e3fb7bb65"

Initialising tasks...done.
NOTE: Executing RunQueue Tasks
ERROR: Fetcher failure: Fetch command export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"; export PATH="/media/build1/poky/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/media/build1/poky/scripts:/media/build1/poky/build/tmp/work/recipetool-1fxlbrau/work/recipe-sysroot-native/usr/bin/mips-poky-linux:/media/build1/poky/build/tmp/work/recipetool-1fxlbrau/work/recipe-sysroot/usr/bin/crossscripts:/media/build1/poky/build/tmp/work/recipetool-1fxlbrau/work/recipe-sysroot-native/usr/sbin:/media/build1/poky/build/tmp/work/recipetool-1fxlbrau/work/recipe-sysroot-native/usr/bin:/media/build1/poky/build/tmp/work/recipetool-1fxlbrau/work/recipe-sysroot-native/sbin:/media/build1/poky/build/tmp/work/recipetool-1fxlbrau/work/recipe-sysroot-native/bin:/media/build1/poky/bitbake/bin:/media/build1/poky/build/tmp/hosttools"; export HOME="/home/richard"; git -c core.fsyncobjectfiles=0 submodule update --init --recursive failed with exit code 1, output:
Submodule 'doxygen2jsdoc' (https://github.com/arfoll/doxygen2jsdoc.git) registered for path 'doxygen2jsdoc'
error: no such remote ref 9cc90b7976252b2d14b7956230c5870097e1f008
Fetched in submodule path 'doxygen2jsdoc', but it did not contain 9cc90b7976252b2d14b7956230c5870097e1f008. Direct fetching of that commit failed.

ERROR: Function failed: base_do_unpack
NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be rerun and 1 failed.
ERROR: Failed to fetch URL gitsm://git.yoctoproject.org/mraa;rev=ae127b19a50aa54255e4330ccfdd9a5d058e581d;nobranch=1
ERROR: Command 'recipetool --color=auto create --devtool -o /tmp/devtoolqzsczjvq 'gitsm://git.yoctoproject.org/mraa;rev=ae127b19a50aa54255e4330ccfdd9a5d058e581d'  -x /tmp/devtoolqa9peegimn/mraa -N mraa -V 1.5' failed
----------------------------------------------------------------------

2017-08-23 11:20:14,819 - oe-selftest - INFO - Ran 1 test in 33.385s
2017-08-23 11:20:14,819 - oe-selftest - INFO - FAILED
2017-08-23 11:20:14,819 - oe-selftest - INFO -  (failures=1)
2017-08-23 11:20:14,824 - oe-selftest - INFO - RESULTS:
2017-08-23 11:20:14,824 - oe-selftest - INFO - RESULTS - devtool.DevtoolTests.test_devtool_add_fetch_git - Testcase 1161: FAILED
2017-08-23 11:20:14,824 - oe-selftest - INFO - SUMMARY:
2017-08-23 11:20:14,824 - oe-selftest - INFO - oe-selftest () - Ran 1 test in 33.391s
2017-08-23 11:20:14,824 - oe-selftest - INFO - oe-selftest - FAIL - Required tests failed

Could you take a look at that test case and see what the issue is please?

Cheers,

Richard

#6 lore raw

Re: [PATCHv2] fetch2/gitsm: copy submodules from DL_DIR in unpack

Quoted 7 lines · Richard Purdie
Quoted 5 lines · Christopher Larson

From: Christopher Larson <[email protected]>

Revert "fetch2/gitsm: Fix when repository change submodules"

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

[…]

Quoted 10 lines
2017-08-23 11:20:14,819 - oe-selftest - INFO - Ran 1 test in 33.385s
2017-08-23 11:20:14,819 - oe-selftest - INFO - FAILED
2017-08-23 11:20:14,819 - oe-selftest - INFO -  (failures=1)
2017-08-23 11:20:14,824 - oe-selftest - INFO - RESULTS:
2017-08-23 11:20:14,824 - oe-selftest - INFO - RESULTS -
devtool.DevtoolTests.test_devtool_add_fetch_git - Testcase 1161: FAILED
2017-08-23 11:20:14,824 - oe-selftest - INFO - SUMMARY:
2017-08-23 11:20:14,824 - oe-selftest - INFO - oe-selftest () - Ran 1 test
in 33.391s
2017-08-23 11:20:14,824 - oe-selftest - INFO - oe-selftest - FAIL -
Quoted 4 lines

Required tests failed

Could you take a look at that test case and see what the issue is please?

Will do, thanks, sorry about that. I ran the bitbake selftests, but didn’t think to re-run the oe selftests. *eyeroll*

Signature · 4 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Senior Software Engineer, Mentor Graphics
#7 lore raw

Re: [PATCHv2] fetch2/gitsm: copy submodules from DL_DIR in unpack

Quoted 24 lines · Christopher Larson
Quoted 7 lines · Richard Purdie
Quoted 5 lines · Christopher Larson

From: Christopher Larson <[email protected]>

Revert "fetch2/gitsm: Fix when repository change submodules"

This reverts commit 12f6c0651af8bd5d6efb751690571cf2fcd3eeb0.

[…]

Quoted 12 lines
2017-08-23 11:20:14,819 - oe-selftest - INFO - Ran 1 test in 33.385s
2017-08-23 11:20:14,819 - oe-selftest - INFO - FAILED
2017-08-23 11:20:14,819 - oe-selftest - INFO -  (failures=1)
2017-08-23 11:20:14,824 - oe-selftest - INFO - RESULTS:
2017-08-23 11:20:14,824 - oe-selftest - INFO - RESULTS -
devtool.DevtoolTests.test_devtool_add_fetch_git - Testcase 1161: FAILED
2017-08-23 11:20:14,824 - oe-selftest - INFO - SUMMARY:
2017-08-23 11:20:14,824 - oe-selftest - INFO - oe-selftest () - Ran 1
test in 33.391s
2017-08-23 11:20:14,824 - oe-selftest - INFO - oe-selftest - FAIL -

Required tests failed

Quoted 6 lines
Quoted 2 lines

Could you take a look at that test case and see what the issue is please?

Will do, thanks, sorry about that. I ran the bitbake selftests, but didn’t think to re-run the oe selftests. *eyeroll*

This is uglier than I had been thinking. If the upstream url for an existing module changes between srcrevs or branches, we’re in trouble, since the modules/ dir in clonedir won’t line up with .gitmodules. I was thinking about adding a needs_update() to GitSM to check for the case where it doesn’t match up, but then if multiple recipes need different sets of modules for the same clonedir at the same time, they’d both run download() and first one would switch to one configuration, then the other would switch back..

The perils of using a single directory in a single clone for multiple possible sets of modules and revs.. I don’t think it’s worth trying to handle this with a stopgap measure, best to just punt on this for this release and pursue the rewrite of gitsm after the release. Feel free to drop these patches. Thanks.

Signature · 4 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Senior Software Engineer, Mentor Graphics