Skip to contentSkip to conversation

gitsm.py: use download cache for git submodules too

PATCH In review Mikko Rapeli 3 participants 9 messages Sep 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 gitsm.py: use download cache for git submodules too

Currently download caches for recipes using gitsm are filled also with the submodule repositories but when the git submodule tree is reused from cache, only the base repository is cloned. After a source URL rewrite, 'git submodule update --init --recursive' is called in the tree which downloads the needed submodules from upstream URL's. This wastes bandwidth since download cache already had the needed commits for the submodule repositories.

With this change, also the submodule repositories are copied to the work space from download cache and the download from upstream can be avoided. Using plain 'cp -a' since git cloning doesn't work for the submodule directories.

Note that using BB_NO_NETWORK does not stop the submodule downloads from 'git submodule update --init --recursive'. Thus tested by breaking access to remote repository via /etc/hosts line like:

127.0.0.1 localhost github.com

---
 bitbake/lib/bb/fetch2/gitsm.py | 8 ++++++++
 1 file changed, 8 insertions(+)

v2: send to bitbake-devel

v1: was sent to oe-core

bitbake/lib/bb/fetch2/gitsm.py +8 -0
index 0aff100..20a9c40 100644
@@ -131,5 +131,13 @@ class GitSM(Git):
         Git.unpack(self, ud, destdir, d)
 
         if self.uses_submodules(ud, d, ud.destdir):
+            # Copy also submodule trees from download cache instead of
+            # downloading again from the upstream repository.
+            # For some reason git does not clone them.
+            clone_modules = os.path.join(ud.clonedir, "modules")
+            if os.path.exists(clone_modules):
+                dest_modules = os.path.join(ud.destdir, ".git")
+                runfetchcmd("cp -a " + clone_modules + " " + dest_modules, 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
1.9.1
#1 lore raw

PATCH v2 2/2 gitsm.py: support BB_NO_NETWORK during do_unpack

'git submodule update --init -recursive' will clone remote repositories if local tree does not have the referenced commits. Add --no-fetch to git submodule update if BB_NO_NETWORK is defined and only local download caches should be used.

---
 bitbake/lib/bb/fetch2/gitsm.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

v2: send to bitbake-devel

v1: was sent to oe-core

bitbake/lib/bb/fetch2/gitsm.py +4 -1
index 20a9c40..007d06e 100644
@@ -140,4 +140,7 @@ class GitSM(Git):
                 runfetchcmd("cp -a " + clone_modules + " " + dest_modules, 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)
+            if d.getVar("BB_NO_NETWORK", True) == "1":
+                runfetchcmd(ud.basecmd + " submodule update --no-fetch --init --recursive", d, workdir=ud.destdir)
+            else:
+                runfetchcmd(ud.basecmd + " submodule update --init --recursive", d, workdir=ud.destdir)
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v2 2/2] gitsm.py: support BB_NO_NETWORK during do_unpack

Quoted 7 lines · Mikko Rapeli

'git submodule update --init -recursive' will clone remote repositories if local tree does not have the referenced commits. Add --no-fetch to git submodule update if BB_NO_NETWORK is defined and only local download caches should be used.

If we’re unpacking, there’s no reason to be contacting anything remote regardless of the value of BB_NO_NETWORK. We should be passing —no-fetch all the time. We also need to be running a submodule sync to update any changes urls in the submodule remotes, but there are other issues to be resolved beyond that.

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

Re: [PATCH v2 2/2] gitsm.py: support BB_NO_NETWORK during do_unpack

Quoted 7 lines · Christopher Larson
Quoted 5 lines · Mikko Rapeli

'git submodule update --init -recursive' will clone remote repositories if local tree does not have the referenced commits. Add --no-fetch to git submodule update if BB_NO_NETWORK is defined and only local download caches should be used.

Quoted 8 lines
Quoted 2 lines

If we’re unpacking, there’s no reason to be contacting anything remote regardless of the value of BB_NO_NETWORK. We should be passing —no-fetch all the time. We also need to be running a submodule sync to update any changes urls in the submodule remotes, but there are other issues to be resolved beyond that.

Yes, I thought about this but decided not to change current behavior. Should have mentioned that in the commit message.

I can send a new version where --no-fetch is the default but it might break in some setups, especially when the DL_DIR cache is not used for submodules...

-Mikko

#4 lore raw

Re: [PATCH v2 2/2] gitsm.py: support BB_NO_NETWORK during do_unpack

Quoted 17 lines · On 9/6/17 10:47 AM, [email protected] wrote:
Quoted 7 lines · Christopher Larson
Quoted 5 lines · Mikko Rapeli

'git submodule update --init -recursive' will clone remote repositories if local tree does not have the referenced commits. Add --no-fetch to git submodule update if BB_NO_NETWORK is defined and only local download caches should be used.

Quoted 8 lines
Quoted 2 lines

If we’re unpacking, there’s no reason to be contacting anything remote regardless of the value of BB_NO_NETWORK. We should be passing —no-fetch all the time. We also need to be running a submodule sync to update any changes urls in the submodule remotes, but there are other issues to be resolved beyond that.

Quoted 5 lines

Yes, I thought about this but decided not to change current behavior. Should have mentioned that in the commit message.

I can send a new version where --no-fetch is the default but it might break in some setups, especially when the DL_DIR cache is not used for submodules...

(without truely understanding the ramifications), I would prefer the system to fail with an error then attempt to contact a network resources if BB_NO_NETWORK is set.

An error (with a resolution of somehow getting the item local either in the DL_DIR or a file:// mirror seems like the best alternative for a user who needs to prevent network access.

So if --no-fetch will help ensure that, I'm all for it.

--Mark

Quoted 2 lines

-Mikko

#5 lore raw

Re: [PATCH v2 2/2] gitsm.py: support BB_NO_NETWORK during do_unpack

Quoted 21 lines · Mark Hatle
Quoted 20 lines · On 9/6/17 10:47 AM, [email protected] wrote:
Quoted 7 lines · Christopher Larson
Quoted 5 lines · Mikko Rapeli

'git submodule update --init -recursive' will clone remote repositories if local tree does not have the referenced commits. Add --no-fetch to git submodule update if BB_NO_NETWORK is defined and only local download caches should be used.

Quoted 8 lines
Quoted 2 lines

If we’re unpacking, there’s no reason to be contacting anything remote regardless of the value of BB_NO_NETWORK. We should be passing —no-fetch all the time. We also need to be running a submodule sync to update any changes urls in the submodule remotes, but there are other issues to be resolved beyond that.

Yes, I thought about this but decided not to change current behavior. Should have mentioned that in the commit message.

Quoted 6 lines
Quoted 2 lines

I can send a new version where --no-fetch is the default but it might break in some setups, especially when the DL_DIR cache is not used for submodules...

(without truely understanding the ramifications), I would prefer the system to fail with an error then attempt to contact a network resources if BB_NO_NETWORK is set.

Yes, that is clear. The comment from Christopher was about using --no-fetch by default in do_unpack also for builds with network connectivity.

This could work for fresh clones of the source tree which call download -> update_submodules -> "git submodule update --init --recursive". Then the tree would be copied to DL_DIR cache.

A subsequent update to the recipe would extract the repo from DL_DIR and call unpack which would call only "git submodule update --no-fetch --init --recursive".

This would work if any recipe changes which update the commit has also call fetch on the base repo (bitbake/lib/bb/fetch2/git.py ?) and download from gitsm.py which would call update_submodules ->
"git submodule update --init --recursive".

Did I miss something? Are there some tests for gitsm.py already?

Quoted 3 lines

An error (with a resolution of somehow getting the item local either in the DL_DIR or a file:// mirror seems like the best alternative for a user who needs to prevent network access.

And this is where the dependency to using DL_DIR cache for git submodules and first patch in the series becomes into play...

-Mikko

#6 lore raw
In reply to Mikko Rapeli
Quoted 8 lines · Mikko Rapeli

Currently download caches for recipes using gitsm are filled also with the submodule repositories but when the git submodule tree is reused from cache, only the base repository is cloned. After a source URL rewrite, 'git submodule update --init --recursive' is called in the tree which downloads the needed submodules from upstream URL's. This wastes bandwidth since download cache already had the needed commits for the submodule repositories.

Quoted 5 lines

With this change, also the submodule repositories are copied to the work space from download cache and the download from upstream can be avoided. Using plain 'cp -a' since git cloning doesn't work for the submodule directories.

This behavior is both already tracked by a yocto bug, and blindly copying will result in breakage when the branch changes in such a way that the submodules change. I already submitted an equivalent patch a week or two ago and then decided against its inclusion, as it just runs into other failures, specifically there was an oe-selftest that fails if you had previously fetched a different branch of the sources in question, as the upstream url of one of the submodules changes between branches, and we don’t re-fetch existing submodules when their urls change. We definitely need to fix this, but this fixes one problem and introduces others.

See https://bugzilla.yoctoproject.org/show_bug.cgi?id=11830 and
https://bugzilla.yoctoproject.org/show_bug.cgi?id=11831 for reference.

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

Hi,

Quoted 16 lines · Christopher Larson
Quoted 8 lines · Mikko Rapeli

Currently download caches for recipes using gitsm are filled also with the submodule repositories but when the git submodule tree is reused from cache, only the base repository is cloned. After a source URL rewrite, 'git submodule update --init --recursive' is called in the tree which downloads the needed submodules from upstream URL's. This wastes bandwidth since download cache already had the needed commits for the submodule repositories.

Quoted 5 lines

With this change, also the submodule repositories are copied to the work space from download cache and the download from upstream can be avoided. Using plain 'cp -a' since git cloning doesn't work for the submodule directories.

Quoted 9 lines

This behavior is both already tracked by a yocto bug, and blindly copying will result in breakage when the branch changes in such a way that the submodules change. I already submitted an equivalent patch a week or two ago and then decided against its inclusion, as it just runs into other failures, specifically there was an oe-selftest that fails if you had previously fetched a different branch of the sources in question, as the upstream url of one of the submodules changes between branches, and we don’t re-fetch existing submodules when their urls change. We definitely need to fix this, but this fixes one problem and introduces others.

In short: git submodules suck.

git exposes all this yuckyness to users who are confused too if their local submodule repositories stop working between commits.

Quoted 2 lines

See https://bugzilla.yoctoproject.org/show_bug.cgi?id=11830 and
https://bugzilla.yoctoproject.org/show_bug.cgi?id=11831 for reference.

Ok. I'll use my patch for now until something better comes along which avoids cloning tens of repositories on every build.

As for testing, it's possible to setup fake http_proxy environment variable and break e.g. http connections to github.com, or in containers to break DNS resolution using /etc/hosts or all network connectivity.

Thanks for pushing to fix this issue.

-Mikko

#8 lore raw
Quoted 31 lines · On Wed, Sep 6, 2017 at 8:45 AM, <[email protected]> wrote:

Hi,

Quoted 1 line · Christopher Larson

On Wed, Sep 6, 2017 at 5:33 AM, Mikko Rapeli <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines

Currently download caches for recipes using gitsm are filled also with the submodule repositories but when the git submodule tree is reused

from

Quoted 12 lines
Quoted 11 lines

cache, only the base repository is cloned. After a source URL rewrite, 'git submodule update --init --recursive' is called in the tree which downloads the needed submodules from upstream URL's. This wastes bandwidth since download cache already had the needed commits for the submodule repositories.

With this change, also the submodule repositories are copied to the work space from download cache and the download from upstream can be avoided. Using plain 'cp -a' since git cloning doesn't work for the submodule directories.

Quoted 9 lines

This behavior is both already tracked by a yocto bug, and blindly copying will result in breakage when the branch changes in such a way that the submodules change. I already submitted an equivalent patch a week or two ago and then decided against its inclusion, as it just runs into other failures, specifically there was an oe-selftest that fails if you had previously fetched a different branch of the sources in question, as the upstream url of one of the submodules changes between branches, and we don’t re-fetch existing submodules when their urls change. We definitely need to fix this, but this fixes one problem and introduces others.

Quoted 5 lines

In short: git submodules suck.

git exposes all this yuckyness to users who are confused too if their local submodule repositories stop working between commits.

Yeah, submodules are a mess all around, for a number of reasons, but most of the alternatives have their own idiosyncrasies :)

Quoted 12 lines
Quoted 2 lines

See https://bugzilla.yoctoproject.org/show_bug.cgi?id=11830 and
https://bugzilla.yoctoproject.org/show_bug.cgi?id=11831 for reference.

Ok. I'll use my patch for now until something better comes along which avoids cloning tens of repositories on every build.

As for testing, it's possible to setup fake http_proxy environment variable and break e.g. http connections to github.com, or in containers to break DNS resolution using /etc/hosts or all network connectivity.

Thanks for pushing to fix this issue.

No problem. Thinking about it again, I’d support merging your patches as a workaround for now. It introduces other issues, but those other issues are likely more minor than re-fetching everything in do_unpack. So we can merge this and use it until the rewritten fetcher gets merged.

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