package: add support for extracting zstd archives

Teach the generic package handling code how to extract zstd (.tar.zst)
archives. When zstd is not installed on the host, host-zstd gets built
automatically.

Signed-off-by: Matt Staveley-Taylor <matt.stav.taylor@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Matt Staveley-Taylor 2024-04-08 02:38:44 +01:00 committed by Thomas Petazzoni
parent 2ca698051c
commit 7d0707cae4
5 changed files with 28 additions and 0 deletions

View File

@ -177,6 +177,13 @@ config BR2_LZCAT
Command to be used to extract a lzip'ed file to stdout. Command to be used to extract a lzip'ed file to stdout.
Default is "lzip -d -c" Default is "lzip -d -c"
config BR2_ZSTDCAT
string "zstdcat command"
default "zstdcat"
help
Command to be used to extract a zstd'ed file to stdout.
Default is "zstdcat"
config BR2_TAR_OPTIONS config BR2_TAR_OPTIONS
string "Tar options" string "Tar options"
default "" default ""

View File

@ -446,6 +446,7 @@ ZCAT := $(call qstrip,$(BR2_ZCAT))
BZCAT := $(call qstrip,$(BR2_BZCAT)) BZCAT := $(call qstrip,$(BR2_BZCAT))
XZCAT := $(call qstrip,$(BR2_XZCAT)) XZCAT := $(call qstrip,$(BR2_XZCAT))
LZCAT := $(call qstrip,$(BR2_LZCAT)) LZCAT := $(call qstrip,$(BR2_LZCAT))
ZSTDCAT := $(call qstrip,$(BR2_ZSTDCAT))
TAR_OPTIONS = $(call qstrip,$(BR2_TAR_OPTIONS)) -xf TAR_OPTIONS = $(call qstrip,$(BR2_TAR_OPTIONS)) -xf
ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),y) ifeq ($(BR2_PER_PACKAGE_DIRECTORIES),y)

View File

@ -59,6 +59,7 @@ INFLATE.tbz = $(BZCAT)
INFLATE.tbz2 = $(BZCAT) INFLATE.tbz2 = $(BZCAT)
INFLATE.tgz = $(ZCAT) INFLATE.tgz = $(ZCAT)
INFLATE.xz = $(XZCAT) INFLATE.xz = $(XZCAT)
INFLATE.zst = $(ZSTDCAT)
INFLATE.tar = cat INFLATE.tar = cat
# suitable-extractor(filename): returns extractor based on suffix # suitable-extractor(filename): returns extractor based on suffix
suitable-extractor = $(INFLATE$(suffix $(1))) suitable-extractor = $(INFLATE$(suffix $(1)))
@ -66,6 +67,7 @@ suitable-extractor = $(INFLATE$(suffix $(1)))
EXTRACTOR_PKG_DEPENDENCY.lzma = $(BR2_XZCAT_HOST_DEPENDENCY) EXTRACTOR_PKG_DEPENDENCY.lzma = $(BR2_XZCAT_HOST_DEPENDENCY)
EXTRACTOR_PKG_DEPENDENCY.xz = $(BR2_XZCAT_HOST_DEPENDENCY) EXTRACTOR_PKG_DEPENDENCY.xz = $(BR2_XZCAT_HOST_DEPENDENCY)
EXTRACTOR_PKG_DEPENDENCY.lz = $(BR2_LZIP_HOST_DEPENDENCY) EXTRACTOR_PKG_DEPENDENCY.lz = $(BR2_LZIP_HOST_DEPENDENCY)
EXTRACTOR_PKG_DEPENDENCY.zst = $(BR2_ZSTD_HOST_DEPENDENCY)
# extractor-pkg-dependency(filename): returns a Buildroot package # extractor-pkg-dependency(filename): returns a Buildroot package
# dependency needed to extract file based on suffix # dependency needed to extract file based on suffix

View File

@ -0,0 +1,4 @@
ifeq (,$(call suitable-host-package,zstd,$(ZSTDCAT)))
BR2_ZSTD_HOST_DEPENDENCY = host-zstd
ZSTDCAT = $(HOST_DIR)/bin/zstdcat
endif

View File

@ -0,0 +1,14 @@
#!/bin/sh
candidate="$1"
zstdcat=$(which "$candidate" 2>/dev/null)
if [ ! -x "$zstdcat" ]; then
zstdcat=$(which zstdcat 2>/dev/null)
if [ ! -x "$zstdcat" ]; then
# echo nothing: no suitable zstdcat found
exit 1
fi
fi
echo "$zstdcat"