Skip to content

Commit bbdeaa2

Browse files
committed
Finish Python updates, and update the Debian packaging to be more
standardized
1 parent cc0a43e commit bbdeaa2

File tree

14 files changed

+121
-67
lines changed

14 files changed

+121
-67
lines changed

.github/workflows/parallel_tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ on:
2020
jobs:
2121

2222
test_installer: # test install_ubuntu.sh
23-
runs-on: panda-arc # Note 22.04 would work, but it requires docker > 20.10.7 which is not on our CI box (yet)
23+
runs-on: panda-arc
2424
container:
25-
image: ubuntu:20.04
25+
image: ubuntu:22.04
2626
steps:
2727
- name: Update
2828
run: apt-get -qq update -y
@@ -31,9 +31,9 @@ jobs:
3131
- name: Set up Python
3232
uses: actions/setup-python@v5
3333
with:
34-
python-version: 3.9
34+
python-version: '3.10'
3535
- name: Install Python dev headers
36-
run: apt-get -qq install -y libpython3.9-dev
36+
run: apt-get -qq install -y libpython3.10-dev
3737
- uses: actions/checkout@v4 # Clones to $GITHUB_WORKSPACE. NOTE: this requires git > 2.18 (not on ubuntu 18.04 by default) to get .git directory
3838
- name: Lint PyPANDA with flake8
3939
run: |

.github/workflows/publish_docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
- name: Build package
4848
working-directory: panda/debian
49-
run: ./setup.sh Ubuntu ${{ matrix.ubuntu_version }}
49+
run: ./setup.sh Ubuntu ${{ matrix.ubuntu_version }} ${{ needs.create_release.outputs.v-version }}
5050

5151
- name: Upload wheel and debian packages to release
5252
uses: softprops/action-gh-release@v2

Dockerfile

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
ARG BASE_IMAGE="ubuntu:20.04"
22
ARG TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,aarch64-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu,mips64-softmmu,mips64el-softmmu"
3-
ARG LIBOSI_VERSION="v0.1.7"
43

54
### BASE IMAGE
6-
FROM $BASE_IMAGE as base
5+
FROM $BASE_IMAGE AS base
76
ARG BASE_IMAGE
87

98
# Copy dependencies lists into container. We copy them all and then do a mv because
@@ -16,22 +15,19 @@ RUN mv /tmp/$(echo "$BASE_IMAGE" | sed 's/:/_/g')_build.txt /tmp/build_dep.txt &
1615
# Base image just needs runtime dependencies
1716
RUN [ -e /tmp/base_dep.txt ] && \
1817
apt-get -qq update && \
19-
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y --no-install-recommends curl $(cat /tmp/base_dep.txt | grep -o '^[^#]*') && \
18+
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y --no-install-recommends curl jq $(cat /tmp/base_dep.txt | grep -o '^[^#]*') && \
2019
apt-get clean
2120

2221
### BUILD IMAGE - STAGE 2
2322
FROM base AS builder
2423
ARG BASE_IMAGE
2524
ARG TARGET_LIST
26-
ARG LIBOSI_VERSION
2725

2826
RUN [ -e /tmp/build_dep.txt ] && \
2927
apt-get -qq update && \
3028
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $(cat /tmp/build_dep.txt | grep -o '^[^#]*') && \
3129
apt-get clean && \
3230
python3 -m pip install --upgrade --no-cache-dir pip && \
33-
python3 -m pip install --upgrade --no-cache-dir "cffi>1.14.3" && \
34-
python3 -m pip install --upgrade --no-cache-dir "capstone" && \
3531
curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal
3632

3733
# Then install capstone from source
@@ -43,13 +39,19 @@ RUN cd /tmp && \
4339
ENV PATH="/root/.cargo/bin:${PATH}"
4440

4541
# install libosi
46-
RUN cd /tmp && curl -LJO https://github.com/panda-re/libosi/releases/download/${LIBOSI_VERSION}/libosi_$(echo "$BASE_IMAGE" | awk -F':' '{print $2}').deb && dpkg -i /tmp/libosi_$(echo "$BASE_IMAGE" | awk -F':' '{print $2}').deb
42+
RUN cd /tmp && \
43+
BASE_IMAGE_VERSION=$(echo "$BASE_IMAGE" | awk -F':' '{print $2}') && \
44+
LIBOSI_VERSION=$(curl -s https://api.github.com/repos/panda-re/libosi/releases/latest | jq -r .tag_name) && \
45+
curl -LJO https://github.com/panda-re/libosi/releases/download/${LIBOSI_VERSION}/libosi_${BASE_IMAGE_VERSION}.deb && \
46+
dpkg -i /tmp/libosi_${BASE_IMAGE_VERSION}.deb && \
47+
rm -rf /tmp/libosi_${BASE_IMAGE_VERSION}.deb
4748

4849
# Build and install panda
4950
# Copy repo root directory to /panda, note we explicitly copy in .git directory
5051
# Note .dockerignore file keeps us from copying things we don't need
5152
COPY . /panda/
5253
COPY .git /panda/
54+
RUN python3 -m pip install -r /panda/panda/python/core/requirements.txt
5355

5456
# Note we diable NUMA for docker builds because it causes make check to fail in docker
5557
RUN git -C /panda submodule update --init dtc && \
@@ -64,12 +66,11 @@ RUN git -C /panda submodule update --init dtc && \
6466
--disable-numa \
6567
--enable-llvm && \
6668
rm -rf /panda/.git
67-
6869

6970
RUN PRETEND_VERSION=$(cat /tmp/savedversion) make -C /panda/build -j "$(nproc)"
7071

7172
#### Develop setup: panda built + pypanda installed (in develop mode) - Stage 3
72-
FROM builder as developer
73+
FROM builder AS developer
7374
RUN cd /panda/panda/python/core && \
7475
python3 create_panda_datatypes.py && \
7576
PRETEND_VERSION=$(cat /tmp/savedversion) pip install -e . && \
@@ -82,22 +83,21 @@ RUN cd /panda/panda/python/core && \
8283
WORKDIR /panda/
8384

8485
#### Install PANDA + pypanda from builder - Stage 4
85-
FROM builder as installer
86+
FROM builder AS installer
8687
RUN make -C /panda/build install && \
8788
rm -r /usr/local/lib/panda/*/cosi \
8889
/usr/local/lib/panda/*/cosi_strace \
8990
/usr/local/lib/panda/*/gdb \
9091
/usr/local/lib/panda/*/snake_hook \
9192
/usr/local/lib/panda/*/rust_skeleton
9293

93-
# Install pypanda
94+
# Build wheel and install pypanda
9495
RUN cd /panda/panda/python/core && \
9596
python3 create_panda_datatypes.py --install && \
9697
PRETEND_VERSION=$(cat /tmp/savedversion) pip install .
9798
RUN python3 -m pip install --upgrade pip "setuptools<65.6.0" && \
9899
python3 -m pip install "pycparser<2.22" && \
99100
python3 -m pip install --force-reinstall --no-binary :all: cffi
100-
# Build a whl too
101101
RUN cd /panda/panda/python/core && \
102102
python3 create_panda_datatypes.py --install && \
103103
PRETEND_VERSION=$(cat /tmp/savedversion) python3 -m build --wheel .
@@ -108,7 +108,7 @@ RUN bash -c "ls $(pip show pandare | grep Location: | awk '{print $2}')/pandare/
108108

109109
# this layer is used to strip shared objects and change python data to be
110110
# symlinks to the installed panda data directory
111-
FROM installer as cleanup
111+
FROM installer AS cleanup
112112
RUN find /usr/local/lib/panda -name "*.so" -exec strip {} \;
113113
RUN PKG=`pip show pandare | grep Location: | awk '{print $2}'`/pandare/data; \
114114
rm -rf $PKG/pc-bios && ln -s /usr/local/share/panda $PKG/pc-bios; \
@@ -123,7 +123,7 @@ RUN PKG=`pip show pandare | grep Location: | awk '{print $2}'`/pandare/data; \
123123
done
124124

125125
### Copy files for panda+pypanda from installer - Stage 5
126-
FROM base as panda
126+
FROM base AS panda
127127

128128
# Include dependency lists for packager
129129
COPY --from=base /tmp/base_dep.txt /tmp
@@ -132,15 +132,14 @@ COPY --from=base /tmp/build_dep.txt /tmp
132132
# Copy panda + libcapstone.so* + libosi libraries
133133
COPY --from=cleanup /usr/local /usr/local
134134
COPY --from=cleanup /usr/lib/libcapstone* /usr/lib/
135-
COPY --from=cleanup /lib/libosi.so /lib/libiohal.so /lib/liboffset.so /lib/
135+
COPY --from=cleanup /usr/lib/x86_64-linux-gnu/libosi.so /usr/lib/x86_64-linux-gnu/libiohal.so /usr/lib/x86_64-linux-gnu/liboffset.so /usr/lib/x86_64-linux-gnu/
136136

137137
# Workaround issue #901 - ensure LD_LIBRARY_PATH contains the panda plugins directories
138138
#ARG TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu"
139139
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/
140140
#PANDA_PATH is used by rust plugins
141141
ENV PANDA_PATH /usr/local/lib/python3.8/dist-packages/pandare/data
142142

143-
144143
# Ensure runtime dependencies are installed for our libpanda objects and panda plugins
145144
RUN ldconfig && \
146145
update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \

panda/debian/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
panda.deb
1+
*.deb
2+
*.whl

panda/debian/Dockerfile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
ARG PACKAGE_VERSION=""
2+
13
# First run the main Dockerfile to build the base image and name it panda. Then we run here
24
# to generate a debian package
35

4-
FROM debian:buster-slim
6+
FROM debian:bookworm-slim
57

68
# Install necessary tools for packaging
79
RUN apt-get -qq update && \
@@ -12,6 +14,9 @@ RUN apt-get -qq update && \
1214
COPY --from=panda /tmp/base_dep.txt /tmp
1315
COPY --from=panda /tmp/build_dep.txt /tmp
1416

17+
# NOTE: If you use the panda debian package, you still need to manually curl
18+
# the libosi and libcapstone-dev package as seen in the main Dockerfile/install_ubuntu.sh
19+
1520
# Set up /package-root with files from panda we'll package
1621
COPY --from=panda /usr/local/bin/panda* /usr/local/bin/libpanda* /usr/local/bin/qemu-img /package-root/usr/local/bin/
1722
COPY --from=panda /usr/local/etc/panda /package-root/usr/local/etc/panda
@@ -21,6 +26,16 @@ COPY --from=panda /usr/local/share/panda /package-root/usr/local/share/panda
2126
# Create DEBIAN directory and control file
2227
COPY control /package-root/DEBIAN/control
2328

29+
# Generate MD5 checksums for all files and save to DEBIAN/md5sums
30+
RUN cd /package-root && \
31+
find . -type f ! -path './DEBIAN/*' -exec md5sum {} + | sed 's| \./| |' > /package-root/DEBIAN/md5sums
32+
33+
# Update control file with the correct version, and place installed size
34+
ARG PACKAGE_VERSION
35+
RUN INSTALLED_SIZE=$(du -sk /package-root | cut -f1) && \
36+
sed -i "s/^Installed-Size:.*/Installed-Size: ${INSTALLED_SIZE}/" /package-root/DEBIAN/control
37+
RUN sed -i "s/^Version:.*/Version: ${PACKAGE_VERSION}/" /package-root/DEBIAN/control
38+
2439
# Update control file with dependencies
2540
# Build time. We only select dependencies that are not commented out or blank
2641
RUN dependencies=$(grep '^[a-zA-Z]' /tmp/build_dep.txt | tr '\n' ',' | sed 's/,,\+/,/g'| sed 's/,$//') && \
@@ -30,6 +45,9 @@ RUN dependencies=$(grep '^[a-zA-Z]' /tmp/build_dep.txt | tr '\n' ',' | sed 's/,,
3045
RUN dependencies=$(grep '^[a-zA-Z]' /tmp/base_dep.txt | tr '\n' ',' | sed 's/,,\+/,/g' | sed 's/,$//') && \
3146
sed -i "s/DEPENDS_LIST/Depends: ipxe-qemu,${dependencies}/" /package-root/DEBIAN/control
3247

48+
# Add triggers script to run ldconfig after installation
49+
COPY triggers /package-root/DEBIAN/triggers
50+
3351
# Build the package
3452
RUN fakeroot dpkg-deb --build /package-root /pandare.deb
3553

panda/debian/control

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
Package: pandare
2-
Version: 3.1.0
3-
Architecture: all
2+
Source: pandare
3+
Version: <version-placeholder>
4+
Architecture: amd64
45
BUILD_DEPENDS_LIST
56
DEPENDS_LIST
6-
Maintainer: Andrew Fasano <fasano@mit.edu>
7+
Maintainer: Luke Craig <luke.craig@mit.edu>
8+
Installed-Size: <size-in-kb>
9+
Section: devel
10+
Priority: optional
11+
Multi-Arch: same
12+
Homepage: https://github.com/panda-re/panda
713
Description: dynamic analysis platform
814
Platform for Architecture Neutral Dynamic Analysis (PANDA) is a processor
915
emulator designed to support analyses of guest code. PANDA supports record-

panda/debian/setup.sh

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,80 @@ if [[ $# -eq 1 ]]; then
2525
echo " To build a package for current Ubuntu version:"
2626
echo " $0"
2727
echo " To build a package for a specific OS/version (only Ubuntu supported for now):"
28-
echo " $0 <OS> <version>"
28+
echo " $0 <OS> <ubuntu-version> <tag-version>"
2929
exit 1
3030
fi
3131

3232
if [[ $# -eq 2 ]]; then
3333
version=$2
34-
3534
else
3635
version=$(lsb_release -r | awk '{print $2}')
3736
fi
3837

38+
if [[ $# -eq 3 ]]; then
39+
tag_version=$3
40+
else
41+
tag_version='v3.1.0'
42+
fi
43+
44+
# Remove leading 'v' if present, e. g. v1.5.1 -> 1.5.1
45+
if [[ "$tag_version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
46+
tag_version=${tag_version:1}
47+
fi
48+
49+
# Check if the version follows the format X.Y.Z, e. g. 1.5.1 or 1.9.1
50+
if [[ ! "$tag_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
51+
echo "ERROR: Version must be in the format X.Y.Z, provided tag version: $tag_version"
52+
exit 1
53+
fi
54+
3955
# Check if the given version is supported
4056
if [[ ! -f "../dependencies/ubuntu_${version}_base.txt" ]]; then
4157
echo "ERROR: Ubuntu ${version} is not supported, no dependencies file found"
4258
exit 1
4359
fi
4460

61+
# Check if HTTP_PROXY and HTTPS_PROXY are set, if not set them to blank
62+
HTTP_PROXY="${HTTP_PROXY:-}"
63+
HTTPS_PROXY="${HTTPS_PROXY:-}"
64+
4565
# Build the installer to generate the wheel file
46-
DOCKER_BUILDKIT=1 docker build --target installer -t panda --build-arg BASE_IMAGE="ubuntu:${version}" ../..
66+
DOCKER_BUILDKIT=1 docker build \
67+
--target installer \
68+
-t panda_installer \
69+
--build-arg HTTP_PROXY="${HTTP_PROXY}" \
70+
--build-arg HTTPS_PROXY="${HTTPS_PROXY}" \
71+
--build-arg BASE_IMAGE="ubuntu:${version}" \
72+
../..
4773

4874
# Copy wheel file out of container to host
49-
# this also preserves wheel name, which is important as pip install WILL fail if you arbitarily change the generated wheel file name
50-
docker run --rm -v $(pwd):/out panda bash -c "cp /panda/panda/python/core/dist/*.whl /out"
75+
# This also preserves wheel name, which is important as pip install WILL fail if you arbitrarily change the generated wheel file name
76+
docker run --rm \
77+
-v $(pwd):/out \
78+
panda_installer \
79+
bash -c "cp /panda/panda/python/core/dist/*.whl /out"
5180

5281
# Finish building main panda container for the target ubuntu version
53-
DOCKER_BUILDKIT=1 docker build --target panda -t panda --build-arg BASE_IMAGE="ubuntu:${version}" ../..
82+
DOCKER_BUILDKIT=1 docker build \
83+
--cache-from panda_installer \
84+
--target panda \
85+
-t panda \
86+
--build-arg BASE_IMAGE="ubuntu:${version}" \
87+
../..
5488

5589
# Now build the packager container from that
56-
docker build -t packager .
90+
DOCKER_BUILDKIT=1 docker build \
91+
--cache-from panda \
92+
-t packager \
93+
--build-arg HTTP_PROXY="${HTTP_PROXY}" \
94+
--build-arg HTTPS_PROXY="${HTTPS_PROXY}" \
95+
--build-arg PACKAGE_VERSION="${tag_version}" \
96+
.
5797

5898
# Copy deb file out of container to host
59-
docker run --rm -v $(pwd):/out packager bash -c "cp /pandare.deb /out"
60-
mv pandare.deb pandare_${version}.deb
99+
docker run --rm \
100+
-v $(pwd):/out \
101+
packager \
102+
bash -c "cp /pandare.deb /out"
103+
104+
mv pandare.deb pandare_${version}.deb

panda/debian/triggers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Trigger ldconfig after install
2+
activate-noawait ldconfig
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Jinja2==3.1.2
1+
Jinja2>=3.1.4
22
MarkupSafe==2.1.3

panda/python/core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ data
88
a
99
__pycache__
1010
*.egg-info
11+
.eggs/

panda/python/core/create_panda_datatypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,14 @@ def copy_objs():
690690
'and prep for PyPanda wheel installation')
691691
parser.add_argument('--install', '-i', dest='install', action='store_true',
692692
help='If set, this means update pandare folder for installation')
693-
parser.add_argument('--recompile', '-r', dest='recompile', action='store_true',
694-
help='If set, recompile the headers with cffi')
693+
parser.add_argument('--no-compile', dest='compile', action='store_false',
694+
help='If set, do not compile the headers with cffi')
695695
args = parser.parse_args()
696696
"""
697697
Install as a local module (not to system) by
698698
1) Creating datatype files for local-use
699699
2) Running regular setup tools logic
700700
"""
701-
main()
701+
main(args.compile)
702702
if args.install:
703703
copy_objs()

panda/python/core/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ requires-python = ">=3.6"
3434
dependencies = [
3535
"cffi>=1.14.3",
3636
"protobuf>=4.25.1",
37-
"colorama"
37+
"colorama",
38+
"capstone==5.0.3"
3839
]
3940

4041
[tool.setuptools_scm]

panda/python/core/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cffi>=1.14.3
22
protobuf>=4.25.1
3+
capstone==5.0.3
34
colorama

0 commit comments

Comments
 (0)