Commit Graph

30 Commits

Author SHA1 Message Date
Mark Hatle
2030e815bb bitbake: gitsm: Add need_update method to determine when we are going to a new SRCREV
If the system had previously fetched a source repository for use by gitsm,
and then the SRCREV was updated and the new commit already existed, the system
would not re-evaluate the submodules and update them accordingly.

The cause of this issue was that need_update was being used, unmodified, from
the base git fetcher.  It did not have any knowledge, nor did it care if we
were moving commits and needed to re-evaluate what was happening due to this
switch.

To fix the issue, during the download process we add all processed (by
gitsm) srcrevs to the git config file, as bitbake.srcrev.  This allows us to
use a new need_update function that not only checks if the git commit is
present, but if we have previously processed this commit to ensure all of the
submodule components are also present.

This approach is used, instead of iterating over the submodules in need_update
to avoid a potential race condition that has affected us in the past.  The
need_update is called only with the parent locking.  Any time we need to dive
into the submodules, we need to lock, and unlock them, at each stage.  This
opens the possibility of errors in either the code, or unintended race
conditions with rm_work.

This issue was discovered by William A. Kennington III <wak@google.com>.  The
included test case was also written by him, and included unmodified.

(Bitbake rev: 30fe86d22c239afa75168cc5eb262b880886ef8a)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-04-01 14:48:44 +01:00
Mark Hatle
a7774aced0 bitbake: gitsm: The fetcher did not process some recursive submodules properly.
Move the submodule processing outside of the if statement to avoid any
optimizations that may happen.

Update the test cases to include the additional case, and split the other
test cases into individual tests to make it easier to figure out what
the failure may be.

(Bitbake rev: 0ec98c01ae50f95c9c74acf53013ac59e0e72b08)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-28 23:14:27 +00:00
Mark Hatle
1979d9162a bitbake: gitsmy.py: Fix unpack of submodules of submodules
If the submodule is in a subdirectory, it needs to have that structure
preserved.  This means the unpack path needs to be in the 'dirname' of the
final path -- since the unpack directory name is specified in the URI.

Additional specific test cases were added to ensure this is working properly
based on two recent error reports.

(Bitbake rev: 8c8ecec2a722bc2885e2648d41ac8df07bdf660d)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-24 17:45:49 +00:00
Mark Hatle
9238a72589 bitbake: gitsm.py: Fix relative URLs
Prior code happened to work with relative URLs, when the code was recently
restructured it caused all relative urls to no longer work.  Restore the prior
code flow for relative support and better comment why that code is there.

(Bitbake rev: 14bb383af0ca98e0e04ec217e537b6a899f3658e)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-24 17:45:49 +00:00
Mark Hatle
7d715ae071 bitbake: gitsm.py: Refactor the functions and simplify the class
The update_submodules and unpack_submodules functions were nearly indentical,
so we made a common function where the different behavior could be passed
in by the download and unpack users.  The new function is process_submodules.

Moved the parse_gitmodules function under the new process_submodules, since
there are no external callers.

Refactor the file relative path processing to the URL translation code.
We also add a warning to the translation if a relative ssh URL has been
detected.  Since this can cause a problem.

In the case of a relative URL that does not work after being translated,
it should be possible to use the MIRROR functions to manual translate the
generated relative URL into one that works properly.

Remove 'git config' processing on download contents.  It turns out this is not
necessary since all of the later components work using the git fetcher.

Limit the 'git submodule update' call to only when unpacking a non-bare
repository.  Submodules are always loaded as bare, so this prevents
intermediate unpacks from being attempted.

Finally, the test cases were updated and the new commit ids in the test
repository were updates as well.

(Bitbake rev: 610dbee5634677f5055e2b36a3043cd197fb8c51)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-16 15:35:08 +00:00
Mark Hatle
a9cf611e7a bitbake: gitsm.py: Rework the shallow fetcher and test case
A custom shallow submodule is no longer necessary, as the regular git
fetcher is used and shallow handling works with the same code.

The only general difference between the regular change is simply declaring a
clone as shallow, when appropriate.

This also removes a potential race condition in copying repositories
vs cloning them.

The gitsm shallow fetcher test was revised to verify that the submodule
is shallow cloned along with the primary repository.

The first step of this change was to be sure to clean the gitsubmodule download
directory, as was previously done with the may gitsource directory.

Additional test components were added to verify commit counts, and an
obsolete (and likely incorrect) test for the .git/modules directory to be
empty was also removed.

(Bitbake rev: f9cc4684dcf4281acc557cda8cb35602354ac3d6)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-16 15:35:08 +00:00
Mark Hatle
cd1430e379 bitbake: gitsm.py: revise unpack
Greatly simply the unpack rule by copying the general functionality of
update_submodules as unpack_submodules.  This will recursively construct
a set of urls and unpack them using the standard system behaviors.

The overall code may be slightly bigger, but this ensures that all of the
standard locks are inplace, ensuring the code doesn't change out from
under the unpack function.  (This could have happened before due to using
'cp' instead of further unpacks on submodules.  This may still happen in
shallow clones.)

(Bitbake rev: 7d7ee630f1c65e7dd234f945edf5e3b3bcb0fc30)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-16 15:35:08 +00:00
Mark Hatle
80f41edbf7 bitbake: gitsm.py: Optimize code and attempt to resolve locking issue
It was reported that a race condition on a shared download directory could
occur with the gitsm fetcher, the result happened with a call to

  git config

that occured within the update_submodules.  Since the fetch is locked by the
upper level, it was probably the prior need_update(...) function causing this
because of some old code.

The gitsm class inherits the git class.  The need_update was overridding the
version in gitsm, so that it forceably checked the submodules.

It's clear we can optimize the code by only updating if the primary repository
needs updating.  Since we don't care if the submodule repository has changed
because if the primary hasn't, references to the submodule won't change.

(Bitbake rev: 346338667edca1f58ace769ad417548da2b8d981)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-16 15:35:08 +00:00
Mark Hatle
3974e5054f bitbake: gitsm.py: Add support for alternative URL formats from submodule files
The following appear to be the git supported formats:

  proto://user:pass@host/path  (URI format)
  user@host:path (SSH format)
  /path or ./path or ../path (local file format)

We adjust the parsing to find out if we have a URI format or not.
When we are NOT in URI format, we do our best to determine SSH or
file format by looking for a ':' in the overall string.  If we find
a ':' we assume SSH format and adjust accordingly.

Note, in SSH format we simply replace the ':' with a '/' when constructing
the URL.  However, if the original path was ":/...", we don't want '//' so
we deal with this corner case as well.

(Bitbake rev: dcac05e7dc6b0c5f8e63d36ad105b7eab41f0016)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-16 15:35:07 +00:00
Mark Hatle
566d31960c bitbake: gitsm.py: Fix when a submodule is defined, but not initialized
It is possible for a submodule to be defined in the .gitmodules file, but
never initialized in the repository itself.  This shows itself when searching
for the defined module hash you will get back a empty value.

Similarly we need to identify and skip defined but not initialized submodules
during the unpack stages as well.

Thanks to raphael.lisicki@siemens.com for their help is figuring out how
to resolve this issue.

Additionally a problem was found where, while unlikely, it may be possible
for the wrong revision to have been searched using ls-tree.  This has been
resolved in the update_submodules function by keeping the correct revision
along with the submodule path.

(Bitbake rev: 49e1ff920143dcd4e7f73933d7ab8a84b8ffa1a3)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-16 15:35:07 +00:00
Mark Hatle
a042179a78 bitbake: fetch2/gitsm.py: Fix the references when the module and path are different
Git does not require the module and target path to be the same in the
.gitmodules file.  This incorrect assumption was being made previously
causing various unpack failures.

An example .gitmodule showing this issue:

   [submodule "plugins/WaveShaper/Libs/inih"]
        path = plugins/wolf-shaper/Libs/inih
        url = https://github.com/pdesaulniers/inih.git

The unpack function also needed to work in a loop on the overall
submodules_queue.  Before it could have missed items that were not in the
primary repository.

(Bitbake rev: 5a7009c204f4d2254e3b2d83ad9319ac23f1cf4d)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-11-07 23:08:55 +00:00
Mark Hatle
a28637abbc bitbake: fetch2/gitsm.py: Disable branch checking on submodules
Submodules by definition refer to a specific commit, not branch.  If we don't
ignore the branch, then any commits on a submodule on a branch different then
the original module will trigger a failure that the commit is not on the
branch.

(Bitbake rev: fdc1dbf96f153b496de52acd8263366a1ff303ad)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-11-07 23:08:55 +00:00
Mark Hatle
8c3db8cb9e bitbake: gitsm: Allow relative URIs when fetching
Some repositories may specify a relative submodule path.  If this happens,
it is our responsibility to use the parents URL (ud) and handle any relative
processing ourselves.

(Bitbake rev: fd9893c338df7828b2c01f1d548aa86dfcf7c50a)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-10-04 23:00:24 +01:00
Laurent Bonnans
41e6a3efac bitbake: fetch2/gitsm: checkout submodules recursively
The new fetcher did not run 'git submodule update' recursively.

(Bitbake rev: 377ed943357b6d47d41d84edbf971741f44affa9)

Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-10-04 23:00:24 +01:00
Laurent Bonnans
c888446d12 bitbake: fetch2/gitsm: handle submodules nested inside subdirs
The new gitsm fetcher assumed that submodules were living directly in
the 'modules' directory, whereas they can be arbitrarily nested inside
subdirectories.

Solve it by first creating the parent of the destination directory for
the symlink and copy steps.

(Bitbake rev: 3dbc84e9c572f43209b79f3656d7dc35a6d982ba)

Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-10-04 23:00:24 +01:00
Laurent Bonnans
ccfb160ed6 bitbake: fetch2/gitsm: fix a typo
'qbareclone' in place of 'bareclone'

(Bitbake rev: 90a3181f1397ae05862f4e89a9bbac606e74504e)

Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-10-04 23:00:24 +01:00
Mark Hatle
5cd00e3e53 bitbake: fetch2/gitsm.py: Rework the git submodule fetcher
The prior fetcher did not know how to work with MIRRORS, and did not
honor BB_NO_NETWORK and similar.

The new fetcher approach recursively calls 'gitsm' download on each
submodule detected.  This ensures that it will go throug the
standard download process.

Each downloaded submodule is then 'attached' to the original download in
the 'modules' directory.  This mimics the behavior of:

    git submodule init

but there is no chance it will contact the network without permission.

It then corrects upstream reference URIs.

The unpack steps simply copies the items from the downloads to the destdir.
Once copied the submodules are connected and we then run:

    git submodule update

According to the git documentation, git submodule init can and will modify
the project configuration and may connect to the network.  Doing the
work manually prevents this.  (This manual process is allowed based
on my reading of the documentation.)

See: https://git-scm.com/book/en/v2/Git-Tools-Submodules

The small change to the existing test is due to this new code always assuming
the code is from a remote system, and not a 'local' repository.  If this
assumption proves to be incorrect -- code will need to be added to deal
with local repositories without an upstream URI.

(Bitbake rev: 9c6b39adf9781fa6745f48913a97c859fa37eb5b)

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-09-26 15:14:33 +01:00
Matt Hoosier
8ed0441be0 bitbake: fetch/gitsm: avoid live submodule fetching during unpack()
Although the submodules' histories have been fetched during the
do_fetch() phase, the mechanics used to clone the workdir copy
of the repo haven't been transferring the actual .git/modules
directory from the repo fetched into downloads/ during the
fetch task.

Fix that, and for good measure also explicitly tell Git to avoid
hitting the network during do_unpack() of the submodules.

[YOCTO #12739]

(Bitbake rev: 11b6a5d5c1b1bb0ce0c5bb3983610d13a3e8f84a)

Signed-off-by: Matt Hoosier <matt.hoosier@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2018-06-07 08:53:19 +01:00
Christopher Larson
f5308b8cc1 bitbake: fetch/gitsm: add support for shallow mirror tarballs
When we're building from a shallow mirror tarball, we don't want to do
anything with ud.clonedir, as it's not being used when we unpack. As such,
disable updating the submodules in that case. Also include the repositories in
.git/modules in the shallow tarball. It does not actually make the submodule
repositories shallow at this time.

(Bitbake rev: 6c0613f1f2f9d4f009545f82a9173e80396f9d34)

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2017-06-02 13:36:57 +01:00
Andre McCurdy
b16192c938 bitbake: fetch2: don't use deprecated bb.data APIs
Cleanup some more usage of bb.data APIs in the fetchers.

(Bitbake rev: 9752fd1c10b8fcc819822fa6eabc2c1050fcc03b)

Signed-off-by: Andre McCurdy <armccurdy@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2017-03-01 11:16:07 +00:00
Ola Redell
d937b5f5e7 bitbake: gitsm.py: Add force flag to git checkout command in update_submodules
When the gitsm fetcher is used with a repo that includes a .gitattributes
file that makes git modify files on cloning (e.g. line break characters),
the subsequent checkout performed in the update_submodules function fails.
This is fixed by adding the force flag (-f) to the checkout command.

(Bitbake rev: c05e1396625b14e66d795408ea2ae4cd2afc3209)

Signed-off-by: Ola Redell <ola.redell@retotech.se>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2017-01-17 11:29:29 +00:00
Matt Madison
ab09541d55 bitbake: fetch2: preserve current working directory
Fix the methods in all fetchers so they don't change
the current working directory of the calling process, which
could lead to "changed cwd" warnings from bitbake.

(Bitbake rev: 6aa78bf3bd1f75728209e2d01faef31cb8887333)

Signed-off-by: Matt Madison <matt@madison.systems>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-08-20 16:08:59 +01:00
Derek Straka
fda94f4e2d bitbake: bitbake: fetch2/gitsm: Fix fetch when the repository contains nested submodules
This fixes a problem when the repository contains multiple levels of submodules via a resursive submodule init.

(Bitbake rev: dbafbe229360ffe5908b106a9c10e274712b9b17)

Signed-off-by: Derek Straka <derek@asterius.io>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-03-26 07:34:58 +00:00
Felipe F. Tonello
b98866d003 bitbake: fetch2/gitsm: Fix when repository change submodules
This fix a problem when checking out a commit that changes the submodules
previously checkout.

Example:
Recipe uses branch A and then it updates to use branch B, but branch B has
different submodules dependencies then what branch A previously had.

(Bitbake rev: 54a3864246f2be0b62761f639a1d5c9407aded4f)

Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-02-04 23:47:49 +00:00
Felipe F. Tonello
62caaa4d6d bitbake: fetch2: Checkout to correct ref begore init and update submodules
This is nessary when specified branch with submodules is different then
default (master) branch.

[YOCTO #7771]

(Bitbake rev: f7b0b5e33e00f3ce0744322eee93835ee76bf184)

Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2015-07-07 13:47:32 +01:00
Chris Morgan
09edf20070 bitbake: fetch2/gitsm: Documentation improvements for gitsm:// fetcher
(Bitbake rev: ef2bf63e56b87e19d1a9059dd2d81a9a1a537254)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-05-19 12:04:34 +01:00
Paul Eggleton
957c9a80bc bitbake: fetch2: fix fetching git submodules with git 1.7.9.x or older
Git versions older than 1.7.10 put absolute paths in configuration files
for the submodule repositories, leading to errors when the repository
checkout is moved. We move the repository as a matter of course in the
gitsm fetcher; the failure occurs in do_unpack). Change the absolute
paths to be relative during processing to fix this.

(At the time of writing, Ubuntu 12.04.4 LTS ships Git version 1.7.9.5,
hence the desire to fix this rather than just mandating a newer Git
version.)

Fixes [YOCTO #5525].

(Bitbake rev: e700d5a41deed4ee837465af526ed30c8a579933)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-02-28 14:50:43 +00:00
Richard Purdie
7b580cd25c bitbake: fetch2/gitsm: Use ud.basecmd instead of hardcoding git
This allows FETCHCMD_git to override the fetcher command as the git fetcher does.

[YOCTO #5717]

(Bitbake rev: 23ab943be3a33077d6ad8be68bba53cd1e2270b4)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2014-01-18 23:29:07 +00:00
Richard Purdie
9d7f8e2a20 bitbake: fetch2: Stop passing around the pointless url parameter
There is no good reason to keep passing around the url parameter when
its contained within urldata (ud). This is left around due to
legacy reasons, some functions take it, some don't and its time
to cleanup.

This is fetcher internal API, there are a tiny number of external users
of the internal API (buildhistory and distrodata) which can be fixed up
after this change.

(Bitbake rev: 6a48474de9505a3700863f31839a7c53c5e18a8d)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-11-22 12:03:02 +00:00
Richard Purdie
a6c6a8ddb6 bitbake: bitbake/fetch: Add git submodules fetcher
This adds very basic git submodule support to the fetcher. It can be
used by replacing a git:// url prefix with a gitsm:// prefix, otherwise
behaviour is the same as the git fetcher. Whilst this code should be
functional, its not as efficient as the usual git fetcher due to the
need to checkout the tree to fetch/update the submodule information. git
doesn't support submodule operations on the bare clones the standard git
fetcher uses which is also problematic.

This code does however give a starting point to people wanting to use
submodules.

(Bitbake rev: 25e0b0bc50114f1fbf955de23cc0c96f5f7a41e3)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-03-25 15:58:31 +00:00