From aaa8291090c963388ed4dfd430359fe477e11862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Wed, 23 Jul 2025 17:47:30 +0200 Subject: [PATCH] Docker: Migrate manual test to CMake --- CMakeLists.txt | 4 +++- src/CMakeLists.txt | 2 +- tools/docker/Dockerfile.test_manual | 23 ++++++++++++----------- tools/docker/generate_dockerfiles.py | 4 ++-- tools/docker/scripts/test_manual.sh | 19 ++----------------- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31c6e4c6ff..de9d1a1cb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,9 +356,11 @@ if(NOT Python_EXECUTABLE) endif() # get the git hash Get the latest abbreviated commit hash of the working branch +# As a fall back, e.g. in a container, try reading a file named "REVISION". execute_process( - COMMAND git log -1 --format=%h + COMMAND bash -c "git log -1 --format=%h || cat REVISION" WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + ERROR_QUIET OUTPUT_VARIABLE CP2K_GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1334bb6da5..9ecdfdc59f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1632,7 +1632,7 @@ add_fypp_sources(CP2K_SRCS ${CP2K_SRCS_F}) # set the __SHORT_FILE__ per file for CP2K sources foreach(cp2k_src ${CP2K_SRCS}) # add_fypp_sources returns a path in the current binary dir - get_filename_component(short_file "${cp2k_src}" NAME) + file(RELATIVE_PATH short_file "${CMAKE_BINARY_DIR}/src" "${cp2k_src}") set_source_files_properties( ${cp2k_src} PROPERTIES COMPILE_DEFINITIONS __SHORT_FILE__="${short_file}") endforeach() diff --git a/tools/docker/Dockerfile.test_manual b/tools/docker/Dockerfile.test_manual index d2a0e40599..74a65c4605 100644 --- a/tools/docker/Dockerfile.test_manual +++ b/tools/docker/Dockerfile.test_manual @@ -23,7 +23,7 @@ COPY ./tools/toolchain/install_cp2k_toolchain.sh . RUN ./install_cp2k_toolchain.sh \ --install-all \ --mpi-mode=mpich \ - --with-dbcsr=no \ + --with-dbcsr \ --with-gcc=system \ --dry-run @@ -64,20 +64,21 @@ COPY ./tools/toolchain/scripts/arch_base.tmpl \ ./scripts/ RUN ./scripts/generate_arch_files.sh && rm -rf ./build -# Install CP2K using local.psmp. -WORKDIR /opt/cp2k ARG GIT_COMMIT_SHA -COPY ./Makefile . +ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} + +# Install CP2K sources. +WORKDIR /opt/cp2k COPY ./src ./src -COPY ./exts ./exts -COPY ./tools/build_utils ./tools/build_utils -RUN /bin/bash -c " \ - if [ -n "${GIT_COMMIT_SHA}" ] ; then echo "git:\${GIT_COMMIT_SHA::7}" > REVISION; fi && \ - mkdir -p arch && \ - ln -vs /opt/cp2k-toolchain/install/arch/local.psmp ./arch/" COPY ./data ./data COPY ./tests ./tests -COPY ./tools/regtesting ./tools/regtesting +COPY ./tools/build_utils ./tools/build_utils +COPY ./cmake ./cmake +COPY ./CMakeLists.txt . + +# Compile CP2K. +COPY ./tools/docker/scripts/build_cp2k_cmake.sh . +RUN ./build_cp2k_cmake.sh toolchain_all psmp # Generate manual. COPY ./docs ./docs diff --git a/tools/docker/generate_dockerfiles.py b/tools/docker/generate_dockerfiles.py index 3ba7b60611..e90604143a 100755 --- a/tools/docker/generate_dockerfiles.py +++ b/tools/docker/generate_dockerfiles.py @@ -112,7 +112,7 @@ def main() -> None: f.write(conventions()) with OutputFile(f"Dockerfile.test_manual", args.check) as f: - f.write(install_deps_toolchain()) + f.write(install_deps_toolchain(with_dbcsr="")) f.write(manual()) with OutputFile(f"Dockerfile.test_precommit", args.check) as f: @@ -255,7 +255,7 @@ RUN /bin/bash -ec " \ # ====================================================================================== def manual() -> str: return ( - install_cp2k(version="psmp", arch="local", revision=True) + install_cp2k_cmake(profile="toolchain_all", version="psmp", revision=True) + rf""" # Generate manual. COPY ./docs ./docs diff --git a/tools/docker/scripts/test_manual.sh b/tools/docker/scripts/test_manual.sh index 18126a0131..f1de8892b3 100755 --- a/tools/docker/scripts/test_manual.sh +++ b/tools/docker/scripts/test_manual.sh @@ -5,21 +5,6 @@ # shellcheck disable=SC1091 source /opt/cp2k-toolchain/install/setup -echo -e "\n========== Compiling CP2K ==========" -cd /opt/cp2k -echo -n "Compiling cp2k... " -if make -j VERSION=psmp &> make.out; then - echo "done." -else - echo -e "failed.\n\n" - tail -n 100 make.out - mkdir -p /workspace/artifacts/ - cp make.out /workspace/artifacts/ - echo -e "\nSummary: Compilation failed." - echo -e "Status: FAILED\n" - exit 0 -fi - echo -e "\n========== Installing Dependencies ==========" apt-get update -qq apt-get install -qq --no-install-recommends \ @@ -42,8 +27,8 @@ echo -e "\n========== Generating Manual ==========" mkdir -p /workspace/artifacts/manual cd /workspace/artifacts/manual -/opt/cp2k/exe/local/cp2k.psmp --version -/opt/cp2k/exe/local/cp2k.psmp --xml +/opt/cp2k/build/bin/cp2k.psmp --version +/opt/cp2k/build/bin/cp2k.psmp --xml set +e # disable error trapping for remainder of script (