Implement an option to store downloads in subdirs

... following the buildroot model.

Signed-off-by: Alexey Neyman <stilor@att.net>
This commit is contained in:
Alexey Neyman 2019-02-13 01:05:13 -08:00
parent 2da27758a9
commit 2219aab336
4 changed files with 54 additions and 20 deletions

View File

@ -2,7 +2,7 @@
## select CC_SUPPORT_CXX if !LIBC_NONE ## select CC_SUPPORT_CXX if !LIBC_NONE
## select CC_SUPPORT_FORTRAN ## select CC_SUPPORT_FORTRAN
## select CC_SUPPORT_JAVA if !GCC_7_or_later ## select CC_SUPPORT_JAVA if !GCC_7_or_later && OBSOLETE
## select CC_SUPPORT_ADA ## select CC_SUPPORT_ADA
## select CC_SUPPORT_OBJC ## select CC_SUPPORT_OBJC
## select CC_SUPPORT_OBJCXX ## select CC_SUPPORT_OBJCXX

View File

@ -19,6 +19,17 @@ config SAVE_TARBALLS
If you say 'y' here, new downloaded tarballs will be saved in the If you say 'y' here, new downloaded tarballs will be saved in the
directory you entered above. directory you entered above.
config TARBALLS_BUILDROOT_LAYOUT
bool "Prefer buildroot-style layout of the downloads"
help
Buildroot switched the layout of its downloads directory to place
files for each package into a subdirectory named after that package.
Enable this option to have crosstool-NG create similar layout.
If this option is set and the required archive is located in
the directory with a legacy, flat layout, the archive will be moved
into a subdirectory. If this is option is not set, subdirectories
will neither be checked nor used to store the downloads.
config WORK_DIR config WORK_DIR
string string
prompt "Working directory" prompt "Working directory"

View File

@ -14,8 +14,8 @@ do_cc_get() {
# GCC source tree, which will not be there unless we get it and # GCC source tree, which will not be there unless we get it and
# put it there ourselves # put it there ourselves
if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" ]; then if [ "${CT_CC_LANG_JAVA_USE_ECJ}" = "y" ]; then
if ! CT_GetFile package=ecj basename=ecj-latest extensions=.jar \ if ! CT_GetFile package=ecj basename=ecj-latest extensions=.jar dir_name=gcc \
mirrors=$(CT_Mirrors sourceware java); then mirrors="$(CT_Mirrors sourceware java)"; then
# Should be a package, too - but with Java retirement in GCC, # Should be a package, too - but with Java retirement in GCC,
# it may not make sense. # it may not make sense.
CT_Abort "Failed to download ecj-latest.jar" CT_Abort "Failed to download ecj-latest.jar"

View File

@ -761,29 +761,34 @@ CT_DoGetFile()
# and if so, symlinks it for later usage. This function is called from # and if so, symlinks it for later usage. This function is called from
# the `if' condition (via the CT_GetFile) and therefore must return # the `if' condition (via the CT_GetFile) and therefore must return
# on error rather than relying on the shell's ERR trap to catch it. # on error rather than relying on the shell's ERR trap to catch it.
# Usage: CT_SaveLocal </full/path/file.name> # Usage: CT_SaveLocal </full/path/file.name> <subdirectory>
CT_SaveLocal() CT_SaveLocal()
{ {
local file="$1" local file="$1"
local savedir="${CT_LOCAL_TARBALLS_DIR}${CT_TARBALLS_BUILDROOT_LAYOUT:+/$2}"
local basename="${file##*/}" local basename="${file##*/}"
if [ "${CT_SAVE_TARBALLS}" = "y" ]; then if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
CT_DoLog EXTRA "Saving '${basename}' to local storage" CT_DoLog EXTRA "Saving '${basename}' to local storage"
# The subdirectory for this package may not exist yet; create it
if [ ! -d "${savedir}" ]; then
CT_DoExecLog ALL mkdir -p "${savedir}"
fi
# The file may already exist if downloads are forced: remove it first # The file may already exist if downloads are forced: remove it first
if ! CT_DoExecLog ALL rm -f "${CT_LOCAL_TARBALLS_DIR}/${basename}"; then if ! CT_DoExecLog ALL rm -f "${savedir}/${basename}"; then
return 1 return 1
fi fi
if ! CT_DoExecLog ALL mv -f "${file}" "${CT_LOCAL_TARBALLS_DIR}"; then if ! CT_DoExecLog ALL mv -f "${file}" "${savedir}"; then
# Move may have failed if the local tarball storage is on a different # Move may have failed if the local tarball storage is on a different
# filesystem. Fallback to copy+delete. # filesystem. Fallback to copy+delete.
if ! CT_DoExecLog ALL cp -f "${file}" "${CT_LOCAL_TARBALLS_DIR}"; then if ! CT_DoExecLog ALL cp -f "${file}" "${savedir}"; then
return 1 return 1
fi fi
if ! CT_DoExecLog ALL rm -f "${file}"; then if ! CT_DoExecLog ALL rm -f "${file}"; then
return 1 return 1
fi fi
fi fi
if ! CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${basename}" "${file}"; then if ! CT_DoExecLog ALL ln -s "${savedir}/${basename}" "${file}"; then
return 1 return 1
fi fi
fi fi
@ -854,7 +859,7 @@ CT_ZCat()
# Verify the file against a detached signature. # Verify the file against a detached signature.
# Fetched from the URL, or obtained from the package directory. # Fetched from the URL, or obtained from the package directory.
# Usage: CT_DoVerifySignature <local-file-path> <URL-used-for-download> <signature-format> # Usage: CT_DoVerifySignature <local-file-path> <URL-used-for-download> <signature-format> <save-subdirectory>
CT_DoVerifySignature() CT_DoVerifySignature()
{ {
local path="$1" local path="$1"
@ -865,6 +870,7 @@ CT_DoVerifySignature()
local format="$3" local format="$3"
local method="${format%/*}" local method="${format%/*}"
local ext="${format#*/}" local ext="${format#*/}"
local save_subdir="$4"
local sigfile local sigfile
local cat local cat
@ -908,7 +914,7 @@ CT_DoVerifySignature()
CT_Popd CT_Popd
# If we get here, verification succeeded. # If we get here, verification succeeded.
if ! CT_SaveLocal "${CT_TARBALLS_DIR}/${sigfile}${ext}"; then if ! CT_SaveLocal "${CT_TARBALLS_DIR}/${sigfile}${ext}" "${save_subdir}"; then
CT_Popd CT_Popd
return 1 return 1
fi fi
@ -922,12 +928,14 @@ CT_GetFile()
local -a argnames=( local -a argnames=(
package # Name of the package package # Name of the package
pkg_dir # Directory with package's auxiliary files pkg_dir # Directory with package's auxiliary files
dir_name # Package's directory name in downloads dir
basename # Base name of file/archive basename # Base name of file/archive
extensions # Extension(s) for the file/archive extensions # Extension(s) for the file/archive
digest # If 'y', verify the digest digest # If 'y', verify the digest
signature_format # Format of the signature signature_format # Format of the signature
mirrors # Mirrors to download from mirrors # Mirrors to download from
) )
local dl_dir
local -a URLS local -a URLS
local ext url local ext url
@ -935,6 +943,9 @@ CT_GetFile()
eval "local ${arg//[[:space:]]/\\ }" eval "local ${arg//[[:space:]]/\\ }"
done done
CT_TestOrAbort "Internal error: dir_name not set" -n "${dir_name}"
dl_dir="${CT_LOCAL_TARBALLS_DIR:+${CT_LOCAL_TARBALLS_DIR}${CT_TARBALLS_BUILDROOT_LAYOUT:+/${dir_name}}}"
# Does any of the requested files exist localy? # Does any of the requested files exist localy?
for ext in ${extensions}; do for ext in ${extensions}; do
# Do we already have it in *our* tarballs dir? # Do we already have it in *our* tarballs dir?
@ -943,12 +954,24 @@ CT_GetFile()
return 0 return 0
fi fi
if [ -n "${CT_LOCAL_TARBALLS_DIR}" -a "${CT_FORCE_DOWNLOAD}" != "y" -a \ if [ "${CT_FORCE_DOWNLOAD}" != "y" ]; then
-r "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" ]; then if [ -n "${dl_dir}" -a -r "${dl_dir}/${basename}${ext}" ]; then
CT_DoLog DEBUG "Got '${basename}' from local storage" CT_DoLog DEBUG "Got '${basename}' from local storage"
CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" \ CT_DoExecLog ALL ln -s "${dl_dir}/${basename}${ext}" \
"${CT_TARBALLS_DIR}/${basename}${ext}" "${CT_TARBALLS_DIR}/${basename}${ext}"
return 0 return 0
elif [ -n "${CT_LOCAL_TARBALLS_DIR}" -a -r "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" ]; then
# Only different if we're using new buildroot layout
CT_DoLog DEBUG "Got '${basename}' from local storage"
CT_DoLog INFO "Moving the ${basename}${ext} into ${dir_name}/${basename}${ext}"
if [ ! -d "${dl_dir}" ]; then
CT_DoExecLog ALL mkdir -p "${dl_dir}"
fi
CT_DoExecLog ALL mv "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" "${dl_dir}/${basename}${ext}"
CT_DoExecLog ALL ln -s "${dl_dir}/${basename}${ext}" \
"${CT_TARBALLS_DIR}/${basename}${ext}"
return 0
fi
fi fi
done done
@ -998,7 +1021,7 @@ CT_GetFile()
CT_DoExecLog ALL rm "${CT_TARBALLS_DIR}/${basename}${ext}" CT_DoExecLog ALL rm "${CT_TARBALLS_DIR}/${basename}${ext}"
return 1 return 1
fi fi
if ! CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}${ext}"; then if ! CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}${ext}" "${dir_name}"; then
return 1 return 1
fi fi
return 0 return 0
@ -2055,7 +2078,7 @@ CT_DoFetch()
basename="${pkg_name}-${version}" basename="${pkg_name}-${version}"
fi fi
pkg_dir="${pkg_name}/${version}" pkg_dir="${pkg_name}/${version}"
if ! CT_GetFile package="${pkg_name}" pkg_dir="${pkg_dir}" \ if ! CT_GetFile package="${pkg_name}" pkg_dir="${pkg_dir}" dir_name="${dir_name}" \
basename="${archive_filename}" extensions="${archive_formats}" \ basename="${archive_filename}" extensions="${archive_formats}" \
digest="${CT_VERIFY_DOWNLOAD_DIGEST}" \ digest="${CT_VERIFY_DOWNLOAD_DIGEST}" \
signature_format="${CT_VERIFY_DOWNLOAD_SIGNATURE:+${signature_format}}" \ signature_format="${CT_VERIFY_DOWNLOAD_SIGNATURE:+${signature_format}}" \
@ -2090,7 +2113,7 @@ CT_DoFetch()
# attempt getting it from local storage or from the mirror if configured. # attempt getting it from local storage or from the mirror if configured.
# Bzip2 offers a reasonable compromise between compression speed and size. # Bzip2 offers a reasonable compromise between compression speed and size.
if [ "${unique_id}" != "to.be.determined" ] && \ if [ "${unique_id}" != "to.be.determined" ] && \
CT_GetFile package="${pkg_name}" \ CT_GetFile package="${pkg_name}" dir_name="${dir_name}" \
basename="${basename}" extensions='.tar.bz2'; then basename="${basename}" extensions='.tar.bz2'; then
return 0 return 0
fi fi
@ -2112,7 +2135,7 @@ CT_DoFetch()
CT_DoExecLog ALL mv "${pkg_name}${devel_subdir:+/${devel_subdir}}" "${basename}" CT_DoExecLog ALL mv "${pkg_name}${devel_subdir:+/${devel_subdir}}" "${basename}"
CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${basename}" CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${basename}"
if ! CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}.tar.bz2"; then if ! CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${dir_name}"; then
CT_Abort "${pkg_name}: failed to save to local storage" CT_Abort "${pkg_name}: failed to save to local storage"
fi fi
CT_Popd CT_Popd