From 8b08d212c30c3c75eb23084f1e5552f970fe8b1d Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 7 Jul 2020 12:48:27 -0700 Subject: [PATCH] Fix DIB scripts python version Now that DIB is python3 only we can remove a hack that made sure scripts outside the chroot ran with the correct version of python. This is necessary as python3 does not resolve symbolic links to the binary like python2.x did, which causes element scripts to fail finding modules when DIB was run from inside a venv. This patch does the following: 1. Reverts 9c7b8d17144ae04dcd56cd736a8f05c76ec87cc1 which was the workaround for mixed python2/3 environments. 2. Updates the scripts to use "python3" instead of "python". Change-Id: If2402bb02fc8a4778fa9434fa167ea1fafd87c28 --- .../package-installs/bin/package-installs-squash | 2 +- .../elements/svc-map/extra-data.d/10-merge-svc-map-files | 2 +- diskimage_builder/lib/common-functions | 8 -------- diskimage_builder/lib/disk-image-create | 9 --------- diskimage_builder/lib/img-functions | 1 - diskimage_builder/lib/outfilter.py | 2 +- 6 files changed, 3 insertions(+), 21 deletions(-) diff --git a/diskimage_builder/elements/package-installs/bin/package-installs-squash b/diskimage_builder/elements/package-installs/bin/package-installs-squash index 44f26c9bc..f50743664 100755 --- a/diskimage_builder/elements/package-installs/bin/package-installs-squash +++ b/diskimage_builder/elements/package-installs/bin/package-installs-squash @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2014 Hewlett-Packard Development Company, L.P. # diff --git a/diskimage_builder/elements/svc-map/extra-data.d/10-merge-svc-map-files b/diskimage_builder/elements/svc-map/extra-data.d/10-merge-svc-map-files index bf36c8aa2..89ff2c3b7 100755 --- a/diskimage_builder/elements/svc-map/extra-data.d/10-merge-svc-map-files +++ b/diskimage_builder/elements/svc-map/extra-data.d/10-merge-svc-map-files @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index c5c314af2..e38fc2798 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -241,14 +241,6 @@ function cleanup_image_dir () { rm -rf --one-file-system $TMP_IMAGE_DIR } -function cleanup_temp_python_exec () { - if [ ! -z "$DIB_ORIGINAL_PATH" ]; then - export PATH=$DIB_ORIGINAL_PATH - fi - rm "$DIB_PYTHON_EXEC_TMP/python" || true - rmdir "$DIB_PYTHON_EXEC_TMP" || true -} - # Run a directory of hooks outside the target (that is, no chrooting). function run_d() { check_element diff --git a/diskimage_builder/lib/disk-image-create b/diskimage_builder/lib/disk-image-create index e08497e02..a13336820 100644 --- a/diskimage_builder/lib/disk-image-create +++ b/diskimage_builder/lib/disk-image-create @@ -175,14 +175,6 @@ export DIB_DEBUG_TRACE export DIB_IMAGE_CACHE=${DIB_IMAGE_CACHE:-~/.cache/image-create} mkdir -p $DIB_IMAGE_CACHE -# Setup a symbolic link to the correct python exec so that element -# scripts running outside the chroot using "#!/usr/bin/env python" get -# the right python version. -export DIB_ORIGINAL_PATH=$PATH -export DIB_PYTHON_EXEC_TMP=$(mktemp -d -t --tmpdir=$HOME .DIB_PYTHON_TMP.XXXXXXXX) -ln -s "$DIB_PYTHON_EXEC" "$DIB_PYTHON_EXEC_TMP/python" -export PATH=$DIB_PYTHON_EXEC_TMP:$DIB_ORIGINAL_PATH - # We have a couple of critical sections (touching parts of the host # system or download images to common cache) that we use flock around. # Use this directory for lockfiles. @@ -617,7 +609,6 @@ fi # Remove the leftovers, i.e. the temporary image directory. cleanup_image_dir -cleanup_temp_python_exec # Restore fd 1&2 from the outfilter.py redirect back to the original # saved fd. Note small hack that we can't really wait properly for diff --git a/diskimage_builder/lib/img-functions b/diskimage_builder/lib/img-functions index 5ab0212d0..fa75d7c92 100644 --- a/diskimage_builder/lib/img-functions +++ b/diskimage_builder/lib/img-functions @@ -43,7 +43,6 @@ function cleanup () { dib-block-device umount cleanup_build_dir cleanup_image_dir - cleanup_temp_python_exec } # Helper function to run a command inside the chroot diff --git a/diskimage_builder/lib/outfilter.py b/diskimage_builder/lib/outfilter.py index 770742c28..450d7dbc1 100644 --- a/diskimage_builder/lib/outfilter.py +++ b/diskimage_builder/lib/outfilter.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright 2014 Hewlett-Packard Development Company, L.P. #