download/git: support Git LFS

Git Large File Storage replaces large files with text pointers in the
Git repository while storing the contents on a remote server.  If a
repository is using this extension, then git-lfs must be used to
checkout the large files before the source archive is generated.

Signed-off-by: John Keeping <john@metanate.com>
[vfazio:
  - add git-lfs to DL_TOOLS_DEPENDENCIES
  - fixup for 5a0d681394
    ("infra/pkg-download: make the DOWNLOAD macro fully parameterised")
]
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
[Arnout:
 - don't "git lfs install";
 - recurse into submodules.
]
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
John Keeping
2020-01-21 14:33:37 -06:00
committed by Arnout Vandecappelle (Essensium/Mind)
parent b4841d722f
commit cff428fe31
5 changed files with 26 additions and 4 deletions

View File

@@ -344,6 +344,10 @@ not and can not work as people would expect it should:
submodules when they contain bundled libraries, in which case we submodules when they contain bundled libraries, in which case we
prefer to use those libraries from their own package. prefer to use those libraries from their own package.
* +LIBFOO_GIT_LFS+ should be set to +YES+ if the Git repository uses
Git LFS to store large files out of band. This is only available for
packages downloaded with git (i.e. when +LIBFOO_SITE_METHOD=git+).
* +LIBFOO_STRIP_COMPONENTS+ is the number of leading components * +LIBFOO_STRIP_COMPONENTS+ is the number of leading components
(directories) that tar must strip from file names on extraction. (directories) that tar must strip from file names on extraction.
The tarball for most packages has one leading component named The tarball for most packages has one leading component named

View File

@@ -119,6 +119,7 @@ define DOWNLOAD
-N '$($(2)_RAWNAME)' \ -N '$($(2)_RAWNAME)' \
-o '$($(2)_DL_DIR)/$(notdir $(1))' \ -o '$($(2)_DL_DIR)/$(notdir $(1))' \
$(if $($(2)_GIT_SUBMODULES),-r) \ $(if $($(2)_GIT_SUBMODULES),-r) \
$(if $($(2)_GIT_LFS),-l) \
$(foreach uri,$(call DOWNLOAD_URIS,$(1),$(2)),-u $(uri)) \ $(foreach uri,$(call DOWNLOAD_URIS,$(1),$(2)),-u $(uri)) \
$(QUIET) \ $(QUIET) \
-- \ -- \

View File

@@ -1207,6 +1207,9 @@ ifeq ($$($(2)_SITE_METHOD),svn)
DL_TOOLS_DEPENDENCIES += svn DL_TOOLS_DEPENDENCIES += svn
else ifeq ($$($(2)_SITE_METHOD),git) else ifeq ($$($(2)_SITE_METHOD),git)
DL_TOOLS_DEPENDENCIES += git DL_TOOLS_DEPENDENCIES += git
ifneq ($$($(2)_GIT_LFS),)
DL_TOOLS_DEPENDENCIES += git-lfs
endif
else ifeq ($$($(2)_SITE_METHOD),bzr) else ifeq ($$($(2)_SITE_METHOD),bzr)
DL_TOOLS_DEPENDENCIES += bzr DL_TOOLS_DEPENDENCIES += bzr
else ifeq ($$($(2)_SITE_METHOD),scp) else ifeq ($$($(2)_SITE_METHOD),scp)

View File

@@ -17,15 +17,15 @@
# We want to catch any unexpected failure, and exit immediately. # We want to catch any unexpected failure, and exit immediately.
set -e set -e
export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:ru:qf:e" export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:lru:qf:e"
main() { main() {
local OPT OPTARG local OPT OPTARG
local backend output hfile recurse quiet rc local backend output hfile large_file recurse quiet rc
local -a uris local -a uris
# Parse our options; anything after '--' is for the backend # Parse our options; anything after '--' is for the backend
while getopts ":c:d:D:o:n:N:H:rf:u:q" OPT; do while getopts ":c:d:D:o:n:N:H:lrf:u:q" OPT; do
case "${OPT}" in case "${OPT}" in
c) cset="${OPTARG}";; c) cset="${OPTARG}";;
d) dl_dir="${OPTARG}";; d) dl_dir="${OPTARG}";;
@@ -34,6 +34,7 @@ main() {
n) raw_base_name="${OPTARG}";; n) raw_base_name="${OPTARG}";;
N) base_name="${OPTARG}";; N) base_name="${OPTARG}";;
H) hfile="${OPTARG}";; H) hfile="${OPTARG}";;
l) large_file="-l";;
r) recurse="-r";; r) recurse="-r";;
f) filename="${OPTARG}";; f) filename="${OPTARG}";;
u) uris+=( "${OPTARG}" );; u) uris+=( "${OPTARG}" );;
@@ -127,7 +128,7 @@ main() {
-f "${filename}" \ -f "${filename}" \
-u "${uri}" \ -u "${uri}" \
-o "${tmpf}" \ -o "${tmpf}" \
${quiet} ${recurse} -- "${@}" ${quiet} ${large_file} ${recurse} -- "${@}"
then then
# cd back to keep path coherence # cd back to keep path coherence
cd "${OLDPWD}" cd "${OLDPWD}"

View File

@@ -51,10 +51,12 @@ _on_error() {
} }
quiet= quiet=
large_file=0
recurse=0 recurse=0
while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
case "${OPT}" in case "${OPT}" in
q) quiet=-q; exec >/dev/null;; q) quiet=-q; exec >/dev/null;;
l) large_file=1;;
r) recurse=1;; r) recurse=1;;
o) output="${OPTARG}";; o) output="${OPTARG}";;
u) uri="${OPTARG}";; u) uri="${OPTARG}";;
@@ -205,6 +207,17 @@ if [ ${recurse} -eq 1 ]; then
done done
fi fi
# If there are large files then fetch them.
if [ ${large_file} -eq 1 ]; then
_git lfs fetch
_git lfs checkout
# If there are also submodules, recurse into them,
if [ ${recurse} -eq 1 ]; then
_git submodule foreach --recursive ${GIT} lfs fetch
_git submodule foreach --recursive ${GIT} lfs checkout
fi
fi
popd >/dev/null popd >/dev/null
# Generate the archive. # Generate the archive.