Skip to contentSkip to conversation

Fix installation of python scripts

PATCH In review Anthony PERARD 2 participants 8 messages Mar 11, 2020 – May 19, 2020

lore
Share & tools
lore
#0 lore raw

cover Fix installation of python scripts

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/xen-unstable.git br.fix-python-install-v1

Hi,

A patch to make packaging of xen on centos8 easier. rpmbuild prevents unversions python shebang from been packaged. And the first patch fix a bug discovered with the second.

Cheers,

Anthony PERARD (2):
tools/python: Fix install-wrap
tools: Use INSTALL_PYTHON_PROG

 tools/misc/xencov_split   | 2 +-
 tools/python/Makefile     | 4 ++--
 tools/python/install-wrap | 2 +-
 tools/xenmon/Makefile     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/2 tools/python: Fix install-wrap

This allows to use install-wrap when the source scripts is in a subdirectory.

---
 tools/python/install-wrap | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/python/install-wrap +1 -1
index 00e2014016f9..fef24e01708d 100755
@@ -44,7 +44,7 @@ shift
 destf="$dest"
 for srcf in ${srcs}; do
 	if test -d "$dest"; then
-		destf="$dest/${srcf%%*/}"
+		destf="$dest/${srcf##*/}"
 	fi
 	org="$(sed -n '2q; /^#! *\/usr\/bin\/env python *$/p' $srcf)"
 	if test "x$org" = x; then
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [XEN PATCH 1/2] tools/python: Fix install-wrap

Quoted 13 lines · Anthony PERARD

This allows to use install-wrap when the source scripts is in a subdirectory.

---
 tools/python/install-wrap | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/python/install-wrap +0 -0
index 00e2014016f9..fef24e01708d 100755

tools/python/install-wrap shift · line 47

Quoted 5 lines
tools/python/install-wrap +1 -1
@@ -44,7 +44,7 @@ shift
 destf="$dest"
 for srcf in ${srcs}; do
 	if test -d "$dest"; then
-		destf="$dest/${srcf%%*/}"
+		destf="$dest/${srcf##*/}"

This seems to have changed the pattern from "Remove Largest Suffix" to "Remove Largest Prefix".

What does it do in practice?

For POSIX sh

x=posix/src/std
echo ${x%%*/} -> posix/src/std
echo ${x##*/} -> std

I would think the former is what you want. But I could be missing something obvious.

Wei.

Quoted 6 lines
tools/python/install-wrap +0 -0
 	fi
 	org="$(sed -n '2q; /^#! *\/usr\/bin\/env python *$/p' $srcf)"
 	if test "x$org" = x; then
Signature · 1 line
Anthony PERARD
#3 lore raw

Re: [XEN PATCH 1/2] tools/python: Fix install-wrap

Quoted 27 lines · Wei Liu

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 13 lines · Anthony PERARD

This allows to use install-wrap when the source scripts is in a subdirectory.

---
 tools/python/install-wrap | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/python/install-wrap +0 -0
index 00e2014016f9..fef24e01708d 100755

tools/python/install-wrap shift · line 47

Quoted 5 lines
tools/python/install-wrap +1 -1
@@ -44,7 +44,7 @@ shift
 destf="$dest"
 for srcf in ${srcs}; do
 	if test -d "$dest"; then
-		destf="$dest/${srcf%%*/}"
+		destf="$dest/${srcf##*/}"

This seems to have changed the pattern from "Remove Largest Suffix" to "Remove Largest Prefix".

What does it do in practice?

Quoted 8 lines

For POSIX sh

x=posix/src/std
echo ${x%%*/} -> posix/src/std
echo ${x##*/} -> std

I would think the former is what you want. But I could be missing something obvious.

The former is a noop. It's the same as not doing anything.

Unless x="dir/dir/" and in that case, the %% would remove everything, resulting in an empty string.

$srcf contains the path to where the script which we want to install is, which is a relative path from where the ./install-wrap is executed from. $destf is the final destination of the script, but if $dest is a directory, then ./install-wrap wants to install the script in $dest, not in some sub-directory of it. ./install-wrap doesn't handle this sub-directory it fails to execute when there is one. (It's probably the $install that failed to copy $srcf in a non-existing directory.)

This from the next patch is probably where things fails

    $(INSTALL_PYTHON_PROG) scripts/convert-legacy-stream $(DESTDIR)$(LIBEXEC_BIN)
Signature · 1 line
Anthony PERARD
Acked-by
#4 lore raw

Re: [XEN PATCH 1/2] tools/python: Fix install-wrap

Quoted 3 lines · Anthony PERARD
Quoted 2 lines · Wei Liu

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Haha :-)

Quoted 47 lines
Quoted 25 lines · Anthony PERARD
Quoted 13 lines

This allows to use install-wrap when the source scripts is in a subdirectory.

---
 tools/python/install-wrap | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/python/install-wrap +0 -0
index 00e2014016f9..fef24e01708d 100755

tools/python/install-wrap shift · line 47

Quoted 5 lines
tools/python/install-wrap +1 -1
@@ -44,7 +44,7 @@ shift
 destf="$dest"
 for srcf in ${srcs}; do
 	if test -d "$dest"; then
-		destf="$dest/${srcf%%*/}"
+		destf="$dest/${srcf##*/}"

This seems to have changed the pattern from "Remove Largest Suffix" to "Remove Largest Prefix".

What does it do in practice?

Quoted 8 lines

For POSIX sh

x=posix/src/std
echo ${x%%*/} -> posix/src/std
echo ${x##*/} -> std

I would think the former is what you want. But I could be missing something obvious.

The former is a noop. It's the same as not doing anything.

Unless x="dir/dir/" and in that case, the %% would remove everything, resulting in an empty string.

$srcf contains the path to where the script which we want to install is, which is a relative path from where the ./install-wrap is executed from. $destf is the final destination of the script, but if $dest is a directory, then ./install-wrap wants to install the script in $dest, not in some sub-directory of it. ./install-wrap doesn't handle this sub-directory it fails to execute when there is one. (It's probably the $install that failed to copy $srcf in a non-existing directory.)

Quoted 2 lines

This from the next patch is probably where things fails

    $(INSTALL_PYTHON_PROG) scripts/convert-legacy-stream $(DESTDIR)$(LIBEXEC_BIN)

I see. Thanks for explaining.

Quoted 3 lines
Signature · 2 lines
-- 
Anthony PERARD
#5 lore raw

PATCH 2/2 tools: Use INSTALL_PYTHON_PROG

In reply to Anthony PERARD

Whenever python scripts are install, have the shebang be modified to use whatever PYTHON_PATH is. This is useful for system where python isn't available, or where the package build tools prevent unversioned shebang.

INSTALL_PYTHON_PROG only looks for "#!/usr/bin/env python".

---
 tools/misc/xencov_split | 2 +-
 tools/python/Makefile   | 4 ++--
 tools/xenmon/Makefile   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/misc/xencov_split +1 -1
index 1f20518b8637..5771f6cfc285 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
 import sys, os, os.path as path, struct, errno
 from optparse import OptionParser
tools/python/Makefile +2 -2
index e99f78a5373a..8d22c0367657 100644
@@ -20,8 +20,8 @@ install:
 		setup.py install --record $(INSTALL_LOG) $(PYTHON_PREFIX_ARG) \
 		--root="$(DESTDIR)" --force
 
-	$(INSTALL_PROG) scripts/convert-legacy-stream $(DESTDIR)$(LIBEXEC_BIN)
-	$(INSTALL_PROG) scripts/verify-stream-v2 $(DESTDIR)$(LIBEXEC_BIN)
+	$(INSTALL_PYTHON_PROG) scripts/convert-legacy-stream $(DESTDIR)$(LIBEXEC_BIN)
+	$(INSTALL_PYTHON_PROG) scripts/verify-stream-v2 $(DESTDIR)$(LIBEXEC_BIN)
 
 .PHONY: uninstall
 uninstall:
tools/xenmon/Makefile +1 -1
index e1712304d07d..3e150b065998 100644
@@ -32,7 +32,7 @@ install: build
 	$(INSTALL_DIR) $(DESTDIR)$(sbindir)
 	$(INSTALL_PROG) xenbaked $(DESTDIR)$(sbindir)/xenbaked
 	$(INSTALL_PROG) xentrace_setmask  $(DESTDIR)$(sbindir)/xentrace_setmask
-	$(INSTALL_PROG) xenmon.py  $(DESTDIR)$(sbindir)/xenmon
+	$(INSTALL_PYTHON_PROG) xenmon.py  $(DESTDIR)$(sbindir)/xenmon
 
 .PHONY: uninstall
 uninstall:
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/2
#6 lore raw

Re: [XEN PATCH 2/2] tools: Use INSTALL_PYTHON_PROG

Quoted 7 lines · Anthony PERARD

Whenever python scripts are install, have the shebang be modified to use whatever PYTHON_PATH is. This is useful for system where python isn't available, or where the package build tools prevent unversioned shebang.

INSTALL_PYTHON_PROG only looks for "#!/usr/bin/env python".

#7 lore raw
In reply to Anthony PERARD

Ping?

Cheers.

Quoted 20 lines · Anthony PERARD

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/xen-unstable.git br.fix-python-install-v1

Hi,

A patch to make packaging of xen on centos8 easier. rpmbuild prevents unversions python shebang from been packaged. And the first patch fix a bug discovered with the second.

Cheers,

Anthony PERARD (2):
tools/python: Fix install-wrap
tools: Use INSTALL_PYTHON_PROG

 tools/misc/xencov_split   | 2 +-
 tools/python/Makefile     | 4 ++--
 tools/python/install-wrap | 2 +-
 tools/xenmon/Makefile     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
Anthony PERARD