From 635f53a8044fe2b607865b56236eb0b8f4805ff3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 16 Jun 2020 17:36:59 +0200 Subject: [PATCH] CI: add a BUILD_SCHEMA_TESTING - ON by default, so if tests are built and the script works, those tests will run as well. - Check that the script works by invoking it once. --- CMakeLists.txt | 19 +++++++++++++++++++ ci/configvalidator.py | 12 ++++++++++++ src/modules/CMakeLists.txt | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4506e9f6c..9795da8ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ # - PYTHONQT # TODO:3.3: remove # BUILD_ : choose additional things to build # - TESTING (standard CMake option) +# - SCHEMA_TESTING (requires Python, see ci/configvalidator.py) # DEBUG_ : special developer flags for debugging # # Example usage: @@ -63,6 +64,10 @@ option( WITH_KF5DBus "Use DBus service for unique-application." OFF ) # TODO:3. option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON ) option( WITH_PYTHONQT "Enable Python view modules API (deprecated, requires PythonQt)." OFF ) # TODO:3.3: remove option( WITH_QML "Enable QML UI options." ON ) +# +# Additional parts to build +option( BUILD_SCHEMA_TESTING "Enable schema-validation-tests" ON ) + # Possible debugging flags are: # - DEBUG_TIMEZONES draws latitude and longitude lines on the timezone @@ -337,6 +342,20 @@ set_package_properties( ) if ( PYTHONINTERP_FOUND ) message(STATUS "Found Python 3 interpreter ${PYTHON_EXECUTABLE}") + if ( BUILD_SCHEMA_TESTING ) + # The configuration validator script has some dependencies, + # and if they are not installed, don't run. If errors out + # with exit(1) on missing dependencies. + exec_program( ${PYTHON_EXECUTABLE} ARGS "${CMAKE_SOURCE_DIR}/ci/configvalidator.py" -x RETURN_VALUE _validator_deps ) + # It should never succeed, but only returns 1 when the imports fail + if ( _validator_deps EQUAL 1 ) + message(STATUS "BUILD_SCHEMA_TESTING dependencies are missing." ) + set( BUILD_SCHEMA_TESTING OFF ) + endif() + endif() +else() + # Can't run schema tests without Python3. + set( BUILD_SCHEMA_TESTING OFF ) endif() find_package( PythonLibs ${PYTHONLIBS_VERSION} ) set_package_properties( diff --git a/ci/configvalidator.py b/ci/configvalidator.py index 858c53224..9d1bc21a5 100644 --- a/ci/configvalidator.py +++ b/ci/configvalidator.py @@ -14,6 +14,15 @@ JSON-representable, anyway. Usage: configvalidator.py ... + configvalidator.py -x + +Exits with value 0 on success, otherwise: + 1 on missing dependencies + 2 on invalid command-line arguments + 3 on missing files + 4 if files have invalid syntax + 5 if files fail to validate +Use -x as only command-line argument to check the imports only. """ # The schemata originally lived outside the Calamares repository, @@ -50,6 +59,9 @@ import sys # # if len(sys.argv) < 3: + # Special-case: called with -x to just test the imports + if len(sys.argv) == 2 and sys.argv[1] == "-x": + exit(0) print(usage) exit(ERR_USAGE) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 0b81c4b3f..08e5a8520 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -68,7 +68,7 @@ include( CalamaresAddTranslations ) add_calamares_python_translations( ${CALAMARES_TRANSLATION_LANGUAGES} ) # TODO:3.3: Use FindPython3 -if ( BUILD_TESTING AND PYTHONINTERP_FOUND AND PYTHON_EXECUTABLE ) +if ( BUILD_TESTING AND BUILD_SCHEMA_TESTING AND PYTHONINTERP_FOUND AND PYTHON_EXECUTABLE ) # The tests for each config file are independent of whether the # module is enabled or not: the config file should match its schema # regardless.