Skip to content

Commit

Permalink
Merge pull request #47 from lifting-bits/install-python-to-venv
Browse files Browse the repository at this point in the history
Install python to venv
  • Loading branch information
artemdinaburg authored Sep 30, 2020
2 parents e9c1282 + f18521e commit 5a7ce20
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,21 @@ set(ANVILL_PYTHON_SOURCES
python/anvill/type.py
python/anvill/var.py)

if(NOT DEFINED ENV{VIRTUAL_ENV})
# NOT a venv install, specify --user and --prefix
set(extra_install_flags "--force --user --prefix=")
else()
#virtual env; install normally
set(extra_install_flags "")
endif()

if(ANVILL_INSTALL_PYTHON2_LIBS)
add_custom_target(install_anvill_python2
DEPENDS ${ANVILL_PYTHON_SOURCES})

add_custom_command(
TARGET install_anvill_python2 POST_BUILD
COMMAND which python2 && python2 setup.py install --force --user --prefix=
COMMAND which python2 && python2 setup.py install ${extra_install_flags}
COMMENT "Installing Anvill Python 2 API"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

Expand All @@ -158,7 +165,7 @@ if(ANVILL_INSTALL_PYTHON3_LIBS)

add_custom_command(
TARGET install_anvill_python3 POST_BUILD
COMMAND which python3 && python3 setup.py install --force --user --prefix=
COMMAND which python3 && python3 setup.py install ${extra_install_flags}
COMMENT "Installing Anvill Python 3 API"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

Expand Down
25 changes: 19 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ ARG LIBRARIES
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -qqy ninja-build python2.7 python3 python3-pip liblzma-dev zlib1g-dev libtinfo-dev curl git wget build-essential ninja-build ccache clang && \
apt-get install -qqy ninja-build python2.7 python3 python3-pip python3-venv liblzma-dev zlib1g-dev libtinfo-dev curl git wget build-essential ninja-build ccache clang && \
rm -rf /var/lib/apt/lists/*

# needed for 20.04 support until we migrate to py3
RUN curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py && python2.7 get-pip.py

Expand All @@ -45,24 +44,38 @@ ARG LIBRARIES
WORKDIR /anvill
COPY . ./

ENV PATH="${LIBRARIES}/llvm/bin:${LIBRARIES}/cmake/bin:${LIBRARIES}/protobuf/bin:${PATH}"
ENV CC="/usr/bin/clang"
ENV CXX="/usr/bin/clang++"
ENV TRAILOFBITS_LIBRARIES="${LIBRARIES}"
ENV VIRTUAL_ENV=/opt/trailofbits/venv
ENV PATH="${VIRTUAL_ENV}/bin:${LIBRARIES}/llvm/bin:${LIBRARIES}/cmake/bin:${LIBRARIES}/protobuf/bin:${PATH}"

# create a virtualenv in /opt/trailofbits/venv
RUN python3 -m venv ${VIRTUAL_ENV}

RUN mkdir -p build && cd build && \
cmake -G Ninja -DCMAKE_PREFIX_PATH=/opt/trailofbits/remill -DCMAKE_VERBOSE_MAKEFILE=True -DCMAKE_INSTALL_PREFIX=/opt/trailofbits/anvill .. && \
cmake --build . --target install

FROM base as dist
ARG LLVM_VERSION

ENV VIRTUAL_ENV=/opt/trailofbits/venv \
PATH="${VIRTUAL_ENV}/bin:/opt/trailofbits/anvill/bin:${PATH}" \
LLVM_VERSION=llvm${LLVM_VERSION}

# The below is commented out since neither binja
# nor IDA would be available in the dist container
# so it makes no sense to also add Python -- can't test the Python API
# without either of those.
# If the situation changes, this can be uncommented to also install Python in the dist image
#RUN apt-get update && \
# apt-get install -qqy python3 python3-pip python3-venv && \
# rm -rf /var/lib/apt/lists/*
# Allow for mounting of local folder
WORKDIR /anvill/local

COPY scripts/docker-decompile-json-entrypoint.sh /opt/trailofbits/anvill/docker-decompile-json-entrypoint.sh
COPY --from=remill /opt/trailofbits/remill /opt/trailofbits/remill
COPY --from=build /opt/trailofbits/anvill /opt/trailofbits/anvill
ENV LLVM_VERSION=llvm${LLVM_VERSION} \
PATH="/opt/trailofbits/anvill/bin:${PATH}"
COPY --from=build ${VIRTUAL_ENV} ${VIRTUAL_ENV}
ENTRYPOINT ["/opt/trailofbits/anvill/docker-decompile-json-entrypoint.sh"]

0 comments on commit 5a7ce20

Please sign in to comment.