# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Clang provides both the preprocessor that the tool drives and the libclang
# library that its bindings load. Debian trixie carries Clang 19, the oldest
# release of the distribution new enough for the tool, and Python 3.13.
FROM debian:trixie

# The Poetry of the distribution predates PEP 621 support and drifts with the
# distribution, so the image installs the same Poetry release that wrote
# poetry.lock and satisfies the poetry-core>=2.5.0 floor of pyproject.toml, which
# is what produces the PEP 639 metadata of the release.
# The variable of the installation chapter, pointing at the Clang of the release.
ENV LLVM_ROOT=/usr/lib/llvm-19
ENV POETRY_CACHE_DIR=/opt/cache/pypoetry
RUN apt-get update -q \
 && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    build-essential \
    ca-certificates \
    clang \
    libclang-dev \
    python3 \
    python3-pip \
    python3-venv \
 && python3 -m venv /opt/poetry \
 && /opt/poetry/bin/pip install --no-cache-dir poetry==2.5.1 \
 && ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry \
 && poetry config virtualenvs.in-project true \
 && apt-get clean && rm -rf /var/lib/apt/lists/*
# Warm the download cache of the image with every locked dependency and build the
# in-project virtualenv that the entry point runs. The cache directory is fixed by
# the ENV above, so it is the same for the image build and for a job that installs
# into its own checkout. Unlike the images of the sibling projects, the virtualenv
# stays in the image: the image is the product that the usage chapter documents,
# and its wrapper script runs the tool out of this virtualenv.
ADD . /opt/mcdc_checker/
RUN cd /opt/mcdc_checker \
 && poetry install \
 && poetry build -o /tmp/build-warm \
 && rm -rf /tmp/build-warm
RUN ln -sf /opt/mcdc_checker/docker/mcdc_checker /usr/bin/mcdc_checker

WORKDIR /code
ENTRYPOINT ["mcdc_checker"]
