From f242016a0921f3aeac885b3332acd14fdaf14af1 Mon Sep 17 00:00:00 2001 From: David Holsgrove Date: Thu, 4 Oct 2012 13:26:14 +1000 Subject: scripts/functions: add a generic custom location infrastructure Add a generic custom location infrastructure (inspired by the one in kernel/linux) to allow the user to use custom tarballs or directories for any component. Signed-off-by: "David Holsgrove" [yann.morin.1998@free.fr: move config option, improve help text, fix API doc] Signed-off-by: "Yann E. MORIN" Message-Id: <131c163c69f9cc81d2be.1349931191@localhost.localdomain> PatchWork-Id: 190784 Message-Id: <0bbaba9190a76ba97f72.1349931192@localhost.localdomain> PatchWork-Id: 190785 diff --git a/config/global/paths.in b/config/global/paths.in index ed26dfc..c4d0593 100644 --- a/config/global/paths.in +++ b/config/global/paths.in @@ -19,6 +19,15 @@ config SAVE_TARBALLS If you say 'y' here, new downloaded tarballs will be saved in the directory you entered above. +config CUSTOM_LOCATION_ROOT_DIR + string + depends on EXPERIMENTAL + prompt "Directory containing custom source components" + help + This is the path CT-NG will attempt to use as a root for locating + local copies of source components (CUSTOM_LOCATION_ROOT_DIR/component) + unless a component declares its own specific custom location. + config WORK_DIR string prompt "Working directory" if ! BACKEND diff --git a/scripts/functions b/scripts/functions index 9bbc753..9a47688 100644 --- a/scripts/functions +++ b/scripts/functions @@ -516,6 +516,41 @@ CT_GetLocal() { return 1 } +# This function gets the custom source from either a tarball or directory +# Usage: CT_GetCustom +CT_GetCustom() { + local custom_component="$1" + local custom_version="$2" + local custom_location="$3" + local custom_name="${custom_component}-${custom_version}" + + CT_TestAndAbort "${custom_name}: CT_CUSTOM_LOCATION_ROOT_DIR or ${custom_component}'s CUSTOM_LOCATION must be set." \ + -z "${CT_CUSTOM_LOCATION_ROOT_DIR}" -a -z "${custom_location}" + + if [ -n "${CT_CUSTOM_LOCATION_ROOT_DIR}" \ + -a -z "${custom_location}" ]; then + custom_location="${CT_CUSTOM_LOCATION_ROOT_DIR}/${custom_component}" + fi + + CT_DoLog EXTRA "Using '${custom_name}' from custom location" + if [ ! -d "${custom_location}" ]; then + # We need to know the custom tarball extension, + # so we can create a properly-named symlink, which + # we use later on in 'extract' + case "${custom_location}" in + *.tar.bz2) custom_name="${custom_name}.tar.bz2";; + *.tar.gz|*.tgz) custom_name="${custom_name}.tar.gz";; + *.tar) custom_name="${custom_name}.tar";; + *) CT_Abort "Unknown extension for custom tarball '${custom_location}'";; + esac + CT_DoExecLog DEBUG ln -sf "${custom_location}" \ + "${CT_TARBALLS_DIR}/${custom_name}" + else + CT_DoExecLog DEBUG ln -snf "${custom_location}" \ + "${CT_SRC_DIR}/${custom_name}" + fi +} + # This function saves the specified to local storage if possible, # and if so, symlinks it for later usage # Usage: CT_SaveLocal -- cgit v0.10.2-6-g49f6