Skip to contentSkip to conversation

python3: customize the python interpreter for nativesdk

PATCH In review Yu, Mingli 2 participants 2 messages Feb 22, 2021

lore
Share & tools
lore

Yu, Mingli

author
#0 lore raw

PATCH 1/1 python3: customize the python interpreter for nativesdk

From: Mingli Yu <[email protected]>

Make sure the python interpreter is "#!/usr/bin/env python3" for nativesdk to avoid the shebang path exceeding the limit when install the sdk under the directory with long path.

Before:

 $ cd ${target_sdk_dir}
 $ vi ./sysroots/x86_64-oesdk-linux/usr/bin/2to3
 #!${target_sdk_dir}/sysroots/${SDK_SYS}/usr/bin/python3.9
 [snip]

After:

 $ cd ${target_sdk_dir}
 $ vi ./sysroots/x86_64-oesdk-linux/usr/bin/2to3
 #!/usr/bin/env python3
 [snip]
---
 meta/recipes-devtools/python/python3_3.9.2.bb | 4 ++++
 1 file changed, 4 insertions(+)
meta/recipes-devtools/python/python3_3.9.2.bb +4 -0
index 87231f97a6..9c87d9d2eb 100644
@@ -177,6 +177,10 @@ do_install_append() {
 }
 
 do_install_append_class-nativesdk () {
+    # Make sure we use /usr/bin/env python
+    for PYTHSCRIPT in `grep -rIl ${bindir}/python ${D}${bindir}`; do
+         sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
+    done
     create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN} TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
 }
 
Signature · 1 line
2.17.1
#1 lore raw

Is it possible to avoid the use of sed, and fix the problem at the source? Why is it specific to nativesdk and doesn't show up in target?

Alex

Quoted 48 lines · Mingli

From: Mingli Yu <[email protected]>

Make sure the python interpreter is "#!/usr/bin/env python3" for nativesdk to avoid the shebang path exceeding the limit when install the sdk under the directory with long path.

Before:

 $ cd ${target_sdk_dir}
 $ vi ./sysroots/x86_64-oesdk-linux/usr/bin/2to3
 #!${target_sdk_dir}/sysroots/${SDK_SYS}/usr/bin/python3.9
 [snip]

After:

 $ cd ${target_sdk_dir}
 $ vi ./sysroots/x86_64-oesdk-linux/usr/bin/2to3
 #!/usr/bin/env python3
 [snip]
---
 meta/recipes-devtools/python/python3_3.9.2.bb | 4 ++++
 1 file changed, 4 insertions(+)
meta/recipes-devtools/python/python3_3.9.2.bb +4 -0
index 87231f97a6..9c87d9d2eb 100644
@@ -177,6 +177,10 @@ do_install_append() {
 }
 
 do_install_append_class-nativesdk () {
+    # Make sure we use /usr/bin/env python
+    for PYTHSCRIPT in `grep -rIl ${bindir}/python ${D}${bindir}`; do
+         sed -i -e '1s|^#!.*|#!/usr/bin/env python3|' $PYTHSCRIPT
+    done
     create_wrapper ${D}${bindir}/python${PYTHON_MAJMIN}

TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
}

--
2.17.1