[RFC,04/15] bitbake: fetch2: Add striplevel support to unpack

Message ID 20211124144739.2250-5-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series Rework npm support | expand

Commit Message

Stefan Herbrechtsmeier Nov. 24, 2021, 2:47 p.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Add striplevel support to unpack tar archives into specified sub
directories. The node package manager (npm) need this feature to unpack
packages into its node_modules directory.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 bitbake/lib/bb/fetch2/__init__.py | 3 +++
 1 file changed, 3 insertions(+)

Comments

Alexander Kanavin Nov. 24, 2021, 3:14 p.m. UTC | #1
Please extend the explanation a bit: how would a typical SRC_URI look that
uses the feature, what is the typical tarball structure and how it maps to
the unpacked tree.

Alex

On Wed, 24 Nov 2021 at 15:48, Stefan Herbrechtsmeier <
stefan.herbrechtsmeier-oss@weidmueller.com> wrote:

> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
>
> Add striplevel support to unpack tar archives into specified sub
> directories. The node package manager (npm) need this feature to unpack
> packages into its node_modules directory.
>
> Signed-off-by: Stefan Herbrechtsmeier <
> stefan.herbrechtsmeier@weidmueller.com>
> ---
>
>  bitbake/lib/bb/fetch2/__init__.py | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/bitbake/lib/bb/fetch2/__init__.py
> b/bitbake/lib/bb/fetch2/__init__.py
> index ded3106173..05b2d2e924 100644
> --- a/bitbake/lib/bb/fetch2/__init__.py
> +++ b/bitbake/lib/bb/fetch2/__init__.py
> @@ -1462,6 +1462,9 @@ class FetchMethod(object):
>                  cmd = 'tar x --no-same-owner -f %s' % file
>              elif file.endswith('.tgz') or file.endswith('.tar.gz') or
> file.endswith('.tar.Z'):
>                  cmd = 'tar xz --no-same-owner -f %s' % file
> +                striplevel = urldata.parm.get('striplevel')
> +                if striplevel:
> +                    cmd += ' --strip-components=%s' % striplevel
>              elif file.endswith('.tbz') or file.endswith('.tbz2') or
> file.endswith('.tar.bz2'):
>                  cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
>              elif file.endswith('.gz') or file.endswith('.Z') or
> file.endswith('.z'):
> --
> 2.20.1
>
>

Patch

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index ded3106173..05b2d2e924 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -1462,6 +1462,9 @@  class FetchMethod(object):
                 cmd = 'tar x --no-same-owner -f %s' % file
             elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
                 cmd = 'tar xz --no-same-owner -f %s' % file
+                striplevel = urldata.parm.get('striplevel')
+                if striplevel:
+                    cmd += ' --strip-components=%s' % striplevel
             elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'):
                 cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
             elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'):