From 6975cfa60e171e4773dbc822862e8613a7508233 Mon Sep 17 00:00:00 2001 From: Diego Alonso Date: Mon, 9 Dec 2024 15:21:45 +0100 Subject: [PATCH] Add workflow to test Check examples --- .github/utils/CheckExamples/CMakeLists.txt | 45 ++++++++++++++++++++ .github/workflows/compile-check-examples.yml | 19 +++++++++ 2 files changed, 64 insertions(+) create mode 100644 .github/utils/CheckExamples/CMakeLists.txt create mode 100644 .github/workflows/compile-check-examples.yml diff --git a/.github/utils/CheckExamples/CMakeLists.txt b/.github/utils/CheckExamples/CMakeLists.txt new file mode 100644 index 0000000..71188c5 --- /dev/null +++ b/.github/utils/CheckExamples/CMakeLists.txt @@ -0,0 +1,45 @@ +# This just checks that files in the Check folders are compilable to avoid +# committing incorrect examples. It's done here, separately and in bulk, so that +# no overhead is added by default when submitting a new check. You'll hopefully +# only have to know this exists if your example fails to compile + +cmake_minimum_required(VERSION 3.25) +project("Test that the check examples compile") + +enable_language(Fortran OPTIONAL) +# Build them as libraries, not executables +set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set (BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../Checks) +message(STATUS "Looking for files in '${BASE_DIR}'") + +file(GLOB check_files + ${BASE_DIR}/*/*.c + ${BASE_DIR}/*/*.cpp + ${BASE_DIR}/*/*.f + ${BASE_DIR}/*/*.f90 +) + +# PWR068: Has a module file that has to be compiled in order, and a compilation error on purpose +# PWD003, PWD006: GFortran catches the data transfer error +set (excluded_checks_regex "PWR068|PWD003|PWD006") + +list(FILTER check_files EXCLUDE REGEX ${excluded_checks_regex}) + +foreach(check_file ${check_files}) + message(STATUS "Trying to compile ${check_file}") + set (extra_flags "-fopenmp -fopenacc") + try_compile( + TRY_RESULT ${CMAKE_BINARY_DIR} + SOURCES ${check_file} + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${extra_flags} + OUTPUT_VARIABLE TRY_RESULT_OUTPUT + ) + + if (TRY_RESULT) + message(STATUS "Trying to compile ${check_file} -- Good") + else() + message(SEND_ERROR "Trying to compile ${check_file} -- Bad") + message(SEND_ERROR "${TRY_RESULT_OUTPUT}") + endif() +endforeach() diff --git a/.github/workflows/compile-check-examples.yml b/.github/workflows/compile-check-examples.yml new file mode 100644 index 0000000..4de6b42 --- /dev/null +++ b/.github/workflows/compile-check-examples.yml @@ -0,0 +1,19 @@ +name: Compile Check examples + +on: + push: + paths: + - '.github/workflows/**' + - '.github/utils/CheckExamples/**' + - 'Checks/**' + +jobs: + # Let us run this job on Ubuntu only, so we can check at the moment that + # examples compile at least on GCC && GFortran + compile-check-examples: + runs-on: ubuntu-24.04 + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Check that all check examples compile + run: cmake -B build -DCMAKE_C_COMPILER=gcc -DCMAKE_Fortran_COMPILER=gfortran -S .github/utils/CheckExamples/