# 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; the tool needs Clang 19 or newer, which the
# rolling repository carries together with Python 3.14.
FROM archlinux

# 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.
ENV POETRY_CACHE_DIR=/opt/cache/pypoetry
RUN pacman -Syu --noconfirm --needed \
    base-devel \
    clang \
    python \
    python-pip \
 && python -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 \
 && yes | pacman -Scc
# 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"]
