toolchain-shar-extract.sh: replace which with "command -v"
PATCH v3 1/3 toolchain-shar-extract.sh: replace which with "command -v"
Command 'which' is not POSIX or even universally installed on Linux systems, replace it with 'command -v'.
Signed-off-by Ming Liu <[email protected]>
--- meta/files/toolchain-shar-extract.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
meta/files/toolchain-shar-extract.sh +3 -3
@@ -2,8 +2,8 @@ export LC_ALL=en_US.UTF-8 #Make sure at least one python is installed -INIT_PYTHON=$(which python3 2>/dev/null ) -[ -z "$INIT_PYTHON" ] && INIT_PYTHON=$(which python2 2>/dev/null) +INIT_PYTHON=$(command -v python3 2>/dev/null ) +[ -z "$INIT_PYTHON" ] && INIT_PYTHON=$(command -v python2 2>/dev/null) [ -z "$INIT_PYTHON" ] && echo "Error: The SDK needs a python installed" && exit 1 # Remove invalid PATH elements first (maybe from a previously setup toolchain now deleted
@@ -229,7 +229,7 @@ if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; the exit 1 fi - SUDO_EXEC=$(which "sudo") + SUDO_EXEC=$(command -v "sudo") if [ -z $SUDO_EXEC ]; then echo "No command 'sudo' found, please install sudo first. Abort!" exit 1
Signature · 1 line
2.43.0
PATCH v3 2/3 toolchain-shar-extract.sh: check required tool before extracting SDK
To extract the SDK archive, the proper tools need to be present on system, check unzip for zip archive type, check xz for tar.xz archive type.
Signed-off-by Ming Liu <[email protected]>
--- meta/files/toolchain-shar-extract.sh | 8 ++++++++ 1 file changed, 8 insertions(+)
meta/files/toolchain-shar-extract.sh +8 -0
@@ -245,6 +245,10 @@ fi printf "Extracting SDK..." if [ @SDK_ARCHIVE_TYPE@ = "zip" ]; then + if [ -z "$(command -v unzip)" ]; then + echo "Aborted, unzip is required to extract the SDK archive, please make sure it's installed on your system!" + exit 1 + fi tail -n +$payload_offset "$0" > sdk.zip if $SUDO_EXEC unzip $EXTRA_TAR_OPTIONS sdk.zip -d $target_sdk_dir;then rm sdk.zip
@@ -252,6 +256,10 @@ if [ @SDK_ARCHIVE_TYPE@ = "zip" ]; then rm sdk.zip && exit 1 fi else + if [ -z "$(command -v xz)" ]; then + echo "Aborted, xz is required to extract the SDK archive, please make sure it's installed on your system!" + exit 1 + fi tail -n +$payload_offset "$0"| $SUDO_EXEC tar mxJ -C $target_sdk_dir --checkpoint=.2500 $EXTRA_TAR_OPTIONS || exit 1 fi echo "done"
Signature · 1 line
2.43.0
PATCH v3 3/3 meta: support tar.zst SDK_ARCHIVE_TYPE
In reply to Ming Liuzst is much faster than the default xz, test result on my Precision 5680 machine:
Installing a tar.xz SDK takes 37 seconds while tar.zst only takes 17 seconds.
Let's introduce support for tar.zst.
Also add a sanity check for supported archive types.
Signed-off-by Ming Liu <[email protected]>
--- meta/classes-recipe/populate_sdk_base.bbclass | 12 ++++++++++-- meta/files/toolchain-shar-extract.sh | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-)
meta/classes-recipe/populate_sdk_base.bbclass +10 -2
@@ -84,6 +84,7 @@ SDK_XZ_OPTIONS ?= "${XZ_DEFAULTS} ${SDK_XZ_COMPRESSION_LEVEL}" SDK_ZIP_OPTIONS ?= "-y" SDK_7ZIP_OPTIONS ?= "-mx=9 -mm=BZip2" SDK_7ZIP_TYPE ?= "7z" +SDK_ZSTD_COMPRESSION_LEVEL = "-17" # To support different sdk type according to SDK_ARCHIVE_TYPE, now support zip and tar.xz python () {
@@ -95,9 +96,16 @@ python () { elif d.getVar('SDK_ARCHIVE_TYPE') == '7zip': d.setVar('SDK_ARCHIVE_DEPENDS', 'p7zip-native') d.setVar('SDK_ARCHIVE_CMD', 'cd ${SDK_OUTPUT}/${SDKPATH}; 7za a -r ${SDK_7ZIP_OPTIONS} ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_7ZIP_TYPE} .') - else: + elif d.getVar('SDK_ARCHIVE_TYPE') == 'tar.zst': + d.setVar('SDK_ARCHIVE_DEPENDS', 'zstd-native') + d.setVar('SDK_ARCHIVE_CMD', + 'cd ${SDK_OUTPUT}/${SDKPATH}; tar ${SDKTAROPTS} -cf - . | zstd -f -k -T0 -c ${SDK_ZSTD_COMPRESSION_LEVEL} > ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE}') + elif d.getVar('SDK_ARCHIVE_TYPE') == 'tar.xz': d.setVar('SDK_ARCHIVE_DEPENDS', 'xz-native') - d.setVar('SDK_ARCHIVE_CMD', 'cd ${SDK_OUTPUT}/${SDKPATH}; tar ${SDKTAROPTS} -cf - . | xz ${SDK_XZ_OPTIONS} > ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE}') + d.setVar('SDK_ARCHIVE_CMD', + 'cd ${SDK_OUTPUT}/${SDKPATH}; tar ${SDKTAROPTS} -cf - . | xz ${SDK_XZ_OPTIONS} > ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE}') + else: + bb.fatal("Invalid SDK_ARCHIVE_TYPE: %s, the supported SDK archive types are: zip, 7z, tar.xz, tar.zst" % d.getVar('SDK_ARCHIVE_TYPE')) } SDK_RDEPENDS = "${TOOLCHAIN_TARGET_TASK} ${TOOLCHAIN_HOST_TASK}"
meta/files/toolchain-shar-extract.sh +6 -0
@@ -255,6 +255,12 @@ if [ @SDK_ARCHIVE_TYPE@ = "zip" ]; then else rm sdk.zip && exit 1 fi +elif [ @SDK_ARCHIVE_TYPE@ = "tar.zst" ]; then + if [ -z "$(command -v zstd)" ]; then + echo "Aborted, zstd is required to extract the SDK archive, please make sure it's installed on your system!" + exit 1 + fi + tail -n +$payload_offset "$0"| zstd -T0 -dc | $SUDO_EXEC tar mx -C $target_sdk_dir --checkpoint=.2500 $EXTRA_TAR_OPTIONS || exit 1 else if [ -z "$(command -v xz)" ]; then echo "Aborted, xz is required to extract the SDK archive, please make sure it's installed on your system!"
Signature · 1 line
2.43.0