From 32c80cfeb56439d1a12dc2ad9e51a4864791b99a Mon Sep 17 00:00:00 2001 From: Andrew Quijano Date: Tue, 10 Dec 2024 14:42:02 -0500 Subject: [PATCH] Remove duplicate pip installs, centalize all dependancy information --- Dockerfile | 55 +++++++++++++----------- panda/debian/.gitignore | 3 +- panda/dependencies/ubuntu_18.04_base.txt | 3 +- panda/dependencies/ubuntu_20.04_base.txt | 3 +- panda/dependencies/ubuntu_22.04_base.txt | 3 +- panda/python/core/.gitignore | 1 + panda/scripts/install_ubuntu.sh | 9 ++-- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index da5748372f1..44d4034bb5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ ARG BASE_IMAGE="ubuntu:20.04" ARG TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,aarch64-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu,mips64-softmmu,mips64el-softmmu" ARG LIBOSI_VERSION="v0.1.7" +ARG INSTALL_PREFIX="/usr/local" ### BASE IMAGE FROM $BASE_IMAGE as base ARG BASE_IMAGE +ARG INSTALL_PREFIX # Copy dependencies lists into container. We copy them all and then do a mv because # we need to transform base_image into a windows compatible filename which we can't @@ -24,14 +26,13 @@ FROM base AS builder ARG BASE_IMAGE ARG TARGET_LIST ARG LIBOSI_VERSION +ARG INSTALL_PREFIX RUN [ -e /tmp/build_dep.txt ] && \ apt-get -qq update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $(cat /tmp/build_dep.txt | grep -o '^[^#]*') && \ apt-get clean && \ - python3 -m pip install --upgrade --no-cache-dir pip && \ - python3 -m pip install --upgrade --no-cache-dir "cffi>1.14.3" && \ - python3 -m pip install --upgrade --no-cache-dir "capstone" && \ + python3 -m pip install "cffi>1.14.3" && \ curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal # Then install capstone from source @@ -53,13 +54,13 @@ COPY .git /panda/ # Note we diable NUMA for docker builds because it causes make check to fail in docker RUN git -C /panda submodule update --init dtc && \ - git -C /panda rev-parse HEAD > /usr/local/panda_commit_hash && \ + git -C /panda rev-parse HEAD > ${INSTALL_PREFIX}/panda_commit_hash && \ mkdir /panda/build && cd /panda/build && \ python3 -m pip install setuptools_scm && \ python3 -m setuptools_scm -r .. --strip-dev 2>/dev/null >/tmp/savedversion && \ /panda/configure \ --target-list="${TARGET_LIST}" \ - --prefix=/usr/local \ + --prefix=${INSTALL_PREFIX} \ --disable-numa \ --enable-llvm && \ rm -rf /panda/.git @@ -69,9 +70,9 @@ RUN PRETEND_VERSION=$(cat /tmp/savedversion) make -C /panda/build -j "$(nproc)" #### Develop setup: panda built + pypanda installed (in develop mode) - Stage 3 FROM builder as developer +ARG INSTALL_PREFIX RUN cd /panda/panda/python/core && \ PRETEND_VERSION=$(cat /tmp/savedversion) python3 setup.py develop && \ - ldconfig && \ update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \ cd /panda && \ ( git config --get-regexp http > /dev/null && \ @@ -81,17 +82,17 @@ WORKDIR /panda/ #### Install PANDA + pypanda from builder - Stage 4 FROM builder as installer +ARG INSTALL_PREFIX RUN make -C /panda/build install && \ - rm -r /usr/local/lib/panda/*/cosi \ - /usr/local/lib/panda/*/cosi_strace \ - /usr/local/lib/panda/*/gdb \ - /usr/local/lib/panda/*/snake_hook \ - /usr/local/lib/panda/*/rust_skeleton + rm -r ${INSTALL_PREFIX}/lib/panda/*/cosi \ + ${INSTALL_PREFIX}/lib/panda/*/cosi_strace \ + ${INSTALL_PREFIX}/lib/panda/*/gdb \ + ${INSTALL_PREFIX}/lib/panda/*/snake_hook \ + ${INSTALL_PREFIX}/lib/panda/*/rust_skeleton # Install pypanda RUN cd /panda/panda/python/core && \ PRETEND_VERSION=$(cat /tmp/savedversion) python3 setup.py install -RUN python3 -m pip install --ignore-install pycparser && python3 -m pip install --force-reinstall --no-binary :all: cffi # Build a whl too RUN cd /panda/panda/python/core && \ PRETEND_VERSION=$(cat /tmp/savedversion) python3 setup.py bdist_wheel @@ -103,40 +104,46 @@ RUN bash -c "ls $(pip show pandare | grep Location: | awk '{print $2}')/pandare/ # this layer is used to strip shared objects and change python data to be # symlinks to the installed panda data directory FROM installer as cleanup -RUN find /usr/local/lib/panda -name "*.so" -exec strip {} \; +ARG INSTALL_PREFIX +RUN find ${INSTALL_PREFIX}/lib/panda -name "*.so" -exec strip {} \; RUN PKG=`pip show pandare | grep Location: | awk '{print $2}'`/pandare/data; \ - rm -rf $PKG/pc-bios && ln -s /usr/local/share/panda $PKG/pc-bios; \ + rm -rf $PKG/pc-bios && ln -s ${INSTALL_PREFIX}/share/panda $PKG/pc-bios; \ for arch in `find $PKG -name "*-softmmu" -type d -exec basename {} \;` ; do \ ARCHP=$PKG/$arch; \ SARCH=`echo $arch | cut -d'-' -f 1`; \ rm $ARCHP/libpanda-$SARCH.so $ARCHP/llvm-helpers-$SARCH.bc; \ - ln -s /usr/local/share/panda/llvm-helpers-$SARCH.bc $ARCHP/llvm-helpers-$SARCH.bc1; \ - ln -s /usr/local/bin/libpanda-$SARCH.so $ARCHP/libpanda-$SARCH.so; \ + ln -s ${INSTALL_PREFIX}/share/panda/llvm-helpers-$SARCH.bc $ARCHP/llvm-helpers-$SARCH.bc1; \ + ln -s ${INSTALL_PREFIX}/bin/libpanda-$SARCH.so $ARCHP/libpanda-$SARCH.so; \ rm -rf $ARCHP/panda/plugins; \ - ln -s /usr/local/lib/panda/$SARCH/ $ARCHP/panda/plugins; \ + ln -s ${INSTALL_PREFIX}/lib/panda/$SARCH/ $ARCHP/panda/plugins; \ done ### Copy files for panda+pypanda from installer - Stage 5 FROM base as panda +ARG INSTALL_PREFIX +ARG TARGET_LIST # Include dependency lists for packager COPY --from=base /tmp/base_dep.txt /tmp COPY --from=base /tmp/build_dep.txt /tmp # Copy panda + libcapstone.so* + libosi libraries -COPY --from=cleanup /usr/local /usr/local +COPY --from=cleanup ${INSTALL_PREFIX} ${INSTALL_PREFIX} COPY --from=cleanup /usr/lib/libcapstone* /usr/lib/ COPY --from=cleanup /lib/libosi.so /lib/libiohal.so /lib/liboffset.so /lib/ # Workaround issue #901 - ensure LD_LIBRARY_PATH contains the panda plugins directories -#ARG TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu" -ENV LD_LIBRARY_PATH /usr/local/lib/python3.8/dist-packages/pandare/data/x86_64-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/i386-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/arm-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/ppc-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/mips-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/mipsel-softmmu/panda/plugins/ -#PANDA_PATH is used by rust plugins -ENV PANDA_PATH /usr/local/lib/python3.8/dist-packages/pandare/data +RUN LD_LIBRARY_PATH="" && \ + for arch in $(echo $TARGET_LIST | tr ',' ' '); do \ + LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${INSTALL_PREFIX}/lib/python3.8/dist-packages/pandare/data/${arch}/panda/plugins/"; \ + done && \ + export LD_LIBRARY_PATH +# PANDA_PATH is used by rust plugins +ENV PANDA_PATH ${INSTALL_PREFIX}/lib/python3.8/dist-packages/pandare/data # Ensure runtime dependencies are installed for our libpanda objects and panda plugins RUN ldconfig && \ update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \ - if (ldd /usr/local/lib/python*/dist-packages/pandare/data/*-softmmu/libpanda-*.so | grep 'not found'); then exit 1; fi && \ - if (ldd /usr/local/lib/python*/dist-packages/pandare/data/*-softmmu/panda/plugins/*.so | grep 'not found'); then exit 1; fi + if (ldd ${INSTALL_PREFIX}/lib/python*/dist-packages/pandare/data/*-softmmu/libpanda-*.so | grep 'not found'); then exit 1; fi && \ + if (ldd ${INSTALL_PREFIX}/lib/python*/dist-packages/pandare/data/*-softmmu/panda/plugins/*.so | grep 'not found'); then exit 1; fi \ No newline at end of file diff --git a/panda/debian/.gitignore b/panda/debian/.gitignore index 7bbf39a4c32..3277dbe3185 100644 --- a/panda/debian/.gitignore +++ b/panda/debian/.gitignore @@ -1 +1,2 @@ -panda.deb +*.deb +*.whl \ No newline at end of file diff --git a/panda/dependencies/ubuntu_18.04_base.txt b/panda/dependencies/ubuntu_18.04_base.txt index e4605e2ba9f..13328881c93 100644 --- a/panda/dependencies/ubuntu_18.04_base.txt +++ b/panda/dependencies/ubuntu_18.04_base.txt @@ -18,11 +18,12 @@ unzip # pyperipheral (only needed for armel) libpython3-dev -# pypanda dependencies +# panda python dependencies genisoimage libffi-dev python3-protobuf python3-colorama +python3-capstone # apt-rdepends qemu-system-common acl diff --git a/panda/dependencies/ubuntu_20.04_base.txt b/panda/dependencies/ubuntu_20.04_base.txt index 7b043e8c3ed..6d2eb6624d7 100644 --- a/panda/dependencies/ubuntu_20.04_base.txt +++ b/panda/dependencies/ubuntu_20.04_base.txt @@ -17,11 +17,12 @@ wget # pyperipheral (only needed for armel) libpython3-dev -# pypanda dependencies +# panda python dependencies genisoimage libffi-dev python3-protobuf python3-colorama +python3-capstone # Not sure what this one is needed for liblzo2-2 diff --git a/panda/dependencies/ubuntu_22.04_base.txt b/panda/dependencies/ubuntu_22.04_base.txt index ed4549b4cfe..ddf261d6979 100644 --- a/panda/dependencies/ubuntu_22.04_base.txt +++ b/panda/dependencies/ubuntu_22.04_base.txt @@ -17,11 +17,12 @@ wget # pyperipheral (only needed for armel) libpython3-dev -# pypanda dependencies +# panda python dependencies genisoimage libffi-dev python3-protobuf python3-colorama +python3-capstone # Not sure what this one is needed for liblzo2-2 diff --git a/panda/python/core/.gitignore b/panda/python/core/.gitignore index 4eebd474f78..fa0ca2b31c2 100644 --- a/panda/python/core/.gitignore +++ b/panda/python/core/.gitignore @@ -8,3 +8,4 @@ data a __pycache__ *.egg-info +.eggs/ \ No newline at end of file diff --git a/panda/scripts/install_ubuntu.sh b/panda/scripts/install_ubuntu.sh index 73b853e7281..4347909bffe 100755 --- a/panda/scripts/install_ubuntu.sh +++ b/panda/scripts/install_ubuntu.sh @@ -126,11 +126,6 @@ if [[ !$(dpkg -l | grep -q libosi) ]]; then popd fi -# PyPANDA needs CFFI from pip (the version in apt is too old) -# Install system-wide since PyPANDA install will also be system-wide -$SUDO python3 -m pip install pip -$SUDO python3 -m pip install "cffi>1.14.3" - progress "Trying to update DTC submodule" git submodule update --init dtc || true @@ -139,6 +134,10 @@ if [ -d "build" ]; then rm -rf "build" fi +# PyPANDA needs CFFI from pip (the version in apt is too old) +# Install system-wide since PyPANDA install will also be system-wide +$SUDO python3 -m pip install "cffi>1.14.3" + progress "Building PANDA..." mkdir build pushd build