* [PATCH v3 2/2] bitbake: fetch2/git: git-lfs check
@ 2019-04-25 1:54 Naveen Saini
2019-04-25 9:51 ` Richard Purdie
0 siblings, 1 reply; 2+ messages in thread
From: Naveen Saini @ 2019-04-25 1:54 UTC (permalink / raw)
To: openembedded-core
Build will fail if repository has lfs contents in absense of git-lfs tool on host.
Build will pass if repository may or may not contains lfs content if host has git-lfs installed.
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
---
bitbake/lib/bb/fetch2/git.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 8185bf4..d862942 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -503,6 +503,15 @@ class Git(FetchMethod):
repourl = self._get_repo_url(ud)
runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d, workdir=destdir)
+
+ if self._contains_lfs(ud, d, destdir):
+ origbbenv = d.getVar("BB_ORIGENV", False)
+ path = origbbenv.getVar("PATH")
+ gitlfstool = bb.utils.which(path, "git-lfs", executable=True)
+ if not gitlfstool:
+ raise bb.fetch2.FetchError("Repository %s has lfs content, install git-lfs plugin on host to download" % (repourl))
+
+
if not ud.nocheckout:
if subdir != "":
runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d,
@@ -553,6 +562,21 @@ class Git(FetchMethod):
raise bb.fetch2.FetchError("The command '%s' gave output with more then 1 line unexpectedly, output: '%s'" % (cmd, output))
return output.split()[0] != "0"
+ def _contains_lfs(self, ud, d, wd):
+ """
+ Check git lfs repository
+ """
+ cmd = "%s grep lfs HEAD:.gitattributes | wc -l" % (
+ ud.basecmd)
+ try:
+ output = runfetchcmd(cmd, d, quiet=True, workdir=wd)
+ except bb.fetch2.FetchError:
+ return False
+ if int(output) > 0:
+ return True
+ else:
+ return False
+
def _get_repo_url(self, ud):
"""
Return the repository URL
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3 2/2] bitbake: fetch2/git: git-lfs check
2019-04-25 1:54 [PATCH v3 2/2] bitbake: fetch2/git: git-lfs check Naveen Saini
@ 2019-04-25 9:51 ` Richard Purdie
0 siblings, 0 replies; 2+ messages in thread
From: Richard Purdie @ 2019-04-25 9:51 UTC (permalink / raw)
To: Naveen Saini, openembedded-core
On Thu, 2019-04-25 at 09:54 +0800, Naveen Saini wrote:
> Build will fail if repository has lfs contents in absense of git-lfs tool on host.
> Build will pass if repository may or may not contains lfs content if host has git-lfs installed.
Bitbake patches need to go to the bitbake list.
> Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
> ---
> bitbake/lib/bb/fetch2/git.py | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
> index 8185bf4..d862942 100644
> --- a/bitbake/lib/bb/fetch2/git.py
> +++ b/bitbake/lib/bb/fetch2/git.py
> @@ -503,6 +503,15 @@ class Git(FetchMethod):
>
> repourl = self._get_repo_url(ud)
> runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d, workdir=destdir)
> +
> + if self._contains_lfs(ud, d, destdir):
> + origbbenv = d.getVar("BB_ORIGENV", False)
> + path = origbbenv.getVar("PATH")
> + gitlfstool = bb.utils.which(path, "git-lfs", executable=True)
> + if not gitlfstool:
> + raise bb.fetch2.FetchError("Repository %s has lfs content, install git-lfs plugin on host to download" % (repourl))
Can we just rely on the usual PATH here please, I don't think we need
to touch BB_ORIGENV? We can assume the environment will be setup with
git-lfs if its present.
> +
> if not ud.nocheckout:
> if subdir != "":
> runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d,
> @@ -553,6 +562,21 @@ class Git(FetchMethod):
> raise bb.fetch2.FetchError("The command '%s' gave output with more then 1 line unexpectedly, output: '%s'" % (cmd, output))
> return output.split()[0] != "0"
>
> + def _contains_lfs(self, ud, d, wd):
> + """
> + Check git lfs repository
If we're going to add a comment, please make it useful, e.g.
Check if the repository has 'lfs' (large file) content
> + """
> + cmd = "%s grep lfs HEAD:.gitattributes | wc -l" % (
> + ud.basecmd)
> + try:
> + output = runfetchcmd(cmd, d, quiet=True, workdir=wd)
> + except bb.fetch2.FetchError:
> + return False
> + if int(output) > 0:
> + return True
> + else:
> + return False
Can be slightly simplified to:
try:
output = runfetchcmd(cmd, d, quiet=True, workdir=wd)
if int(output) > 0:
return True
except
bb.fetch2.FetchError:
pass
return False
I did wonder if we could/should also catch an exception if the output
can't be turned into an int for some reason with:
except bb.fetch2.FetchError, ValueError:
Cheers,
Richard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-04-25 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-25 1:54 [PATCH v3 2/2] bitbake: fetch2/git: git-lfs check Naveen Saini
2019-04-25 9:51 ` Richard Purdie
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.