Re: [libvirt PATCH 2/3] scripts: Add $DESTDIR support to meson-install-web.py

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 19, 2022 at 04:17:44PM +0200, Andrea Bolognani wrote:
> meson already supports $DESTDIR natively, but in this case
> we're using a custom script and so we have to do some extra
> work ourselves.
> 
> Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
> ---
>  scripts/meson-install-web.py | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/scripts/meson-install-web.py b/scripts/meson-install-web.py
> index fdf407ba33..e7456fa750 100755
> --- a/scripts/meson-install-web.py
> +++ b/scripts/meson-install-web.py
> @@ -6,10 +6,23 @@ import sys
>  
>  from pathlib import Path
>  
> +destdir = os.getenv('DESTDIR')
> +if destdir:
> +    destdir = Path(destdir)
> +    if not destdir.is_absolute():
> +        print('$DESTDIR must be an absolute path')
> +        sys.exit(1)

I don't see any reason for this check. Yes, DESTDIR is mostly used with
absolute path but the other two scripts where we use DESTDIR don't have
this check and meson itself doesn't complaint if the path is
not absolute as well.

That brings me to the other point that there is no need to use pathlib
at all. We can just do the same as scripts/meson-install-dirs.py or
scripts/meson-install-symlink.py:

destdir = os.environ.get('DESTDIR', os.sep)

for desc in sys.argv[1:]:
    inst = desc.split(':')
    dst = os.path.join(destdir, inst[1].strip(os.sep))
    os.makedirs(dst, exist_ok=True)
    shutil.copy(src, dst)

Pavel

>  for desc in sys.argv[1:]:
>      inst = desc.split(':')
>      src = Path(inst[0])
>      dst = Path(inst[1])
>  
> +    if destdir:
> +        # Turn dst into a relative path by dropping its first component
> +        # and append it to destdir to obtain the absolute destination
> +        # path that respects the value $DESTDIR found in the environment
> +        dst = Path(destdir, *dst.parts[1:])
> +
>      dst.mkdir(parents=True, exist_ok=True)
>      shutil.copy(src, dst)
> -- 
> 2.35.3
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux