From fd7d236508be6527bec53cd300732a92a43328d6 Mon Sep 17 00:00:00 2001 From: Marcus Burghardt Date: Mon, 27 May 2024 16:34:19 +0200 Subject: [PATCH] Fix issue with python executable The set(Python_ADDITIONAL_VERSIONS 3 2) line was accidentaly moved after find_package(PythonInterp REQUIRED), impacting in the value of PYTHON_EXECUTABLE variable. It was noticed in a CI test for CentOS Stream8 where the "/usr/bin/python3" was still poiting to "/usr/bin/python3.6" while "/usr/bin/python3.11" was already present and this impacted the detection of installed Python modules. Few other improvements in readability were made in this commit. --- CMakeLists.txt | 52 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24e47b02902..11037cb8505 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,20 +58,6 @@ set(SSG_SHARED_REFS "${SSG_SHARED}/references") set(SSG_SHARED_TRANSFORMS "${SSG_SHARED}/transforms") set(SSG_UTILS_SCRIPTS "${CMAKE_SOURCE_DIR}/utils") -if(SSG_JINJA2_CACHE_ENABLED) - file(MAKE_DIRECTORY "${SSG_JINJA2_CACHE_DIR}") - if(NOT EXISTS "${SSG_JINJA2_CACHE_DIR}") - message(FATAL_ERROR "jinja2 cache dir was set to '${SSG_JINJA2_CACHE_DIR}'. This directory doesn't seem to exist and attempt to create it has failed.") - endif() - set(SSG_JINJA2_CACHE_ENABLED_BOOL "true") -else() - set(SSG_JINJA2_CACHE_ENABLED_BOOL "false") -endif() - -message(STATUS "SCAP Security Guide ${SSG_VERSION}") -message(STATUS "(see ${CMAKE_SOURCE_DIR}/docs/manual/developer_guide.adoc for build instructions)") -message(STATUS "") - # Content Generation Opetions option(SSG_ANSIBLE_PLAYBOOKS_ENABLED "If enabled, Ansible Playbooks for each profile will be built and installed." TRUE) option(SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED "If enabled, Ansible Playbooks for each rule will be built and installed." FALSE) @@ -139,7 +125,11 @@ if("$ENV{PYTHONPATH}" STREQUAL "") else() set(ENV{PYTHONPATH} "${PROJECT_SOURCE_DIR}:$ENV{PYTHONPATH}") endif() +message(STATUS "PYTHONPATH: $ENV{PYTHONPATH}") +# Setting Python_ADDITIONAL_VERSIONS before calling PythonInterp can influence the priority of +# python executables in a scenario where multiple versions are present. +set(Python_ADDITIONAL_VERSIONS 3 2) # Required Packages find_package(PythonInterp REQUIRED) find_package(OpenSCAP REQUIRED) @@ -150,7 +140,6 @@ find_program(BATS_EXECUTABLE NAMES bats) find_program(GIT_EXECUTABLE NAMES git) find_program(GREP_EXECUTABLE NAMES grep) find_program(LINKCHECKER_EXECUTABLE NAMES linkchecker) -find_program(PYTHON3_EXECUTABLE NAMES python3) find_program(SED_EXECUTABLE NAMES sed REQUIRED) find_program(SHELLCHECK_EXECUTABLE NAMES shellcheck) find_program(XMLLINT_EXECUTABLE NAMES xmllint REQUIRED) @@ -158,8 +147,11 @@ find_program(XSLTPROC_EXECUTABLE NAMES xsltproc REQUIRED) find_program(YAMLLINT_EXECUTABLE NAMES yamllint) message(STATUS "") -message(STATUS "Find Python Modules:") -set(Python_ADDITIONAL_VERSIONS 3 2) +message(STATUS "SCAP Security Guide ${SSG_VERSION}") +message(STATUS "(see ${CMAKE_SOURCE_DIR}/docs/manual/developer_guide.adoc for build instructions)") + +message(STATUS "") +message(STATUS "Finding Python Modules:") find_python_module(jinja2 REQUIRED) find_python_module(yaml REQUIRED) find_python_module(cmakelint) @@ -219,10 +211,20 @@ if(NOT SSG_THIN_DS) set(SSG_THIN_DS_RULE_ID "off") endif() +if(SSG_JINJA2_CACHE_ENABLED) + file(MAKE_DIRECTORY "${SSG_JINJA2_CACHE_DIR}") + if(NOT EXISTS "${SSG_JINJA2_CACHE_DIR}") + message(FATAL_ERROR "jinja2 cache dir was set to '${SSG_JINJA2_CACHE_DIR}'. This directory doesn't seem to exist and attempt to create it has failed.") + endif() + set(SSG_JINJA2_CACHE_ENABLED_BOOL "true") +else() + set(SSG_JINJA2_CACHE_ENABLED_BOOL "false") +endif() + configure_file("${CMAKE_SOURCE_DIR}/build_config.yml.in" "${CMAKE_BINARY_DIR}/build_config.yml" @ONLY) message(STATUS " ") -message(STATUS "Python Tools and Modules:") +message(STATUS "Summary of Python Tools and Modules:") # Required Python Tools message(STATUS "python: ${PYTHON_EXECUTABLE} (version: ${PYTHON_VERSION_STRING})") message(STATUS "python yaml module: ${PY_YAML}") @@ -246,7 +248,7 @@ message(STATUS "python sphinx module (optional): ${PY_SPHINX}") message(STATUS "python sphinxcontrib.autojinja module (optional): ${PY_SPHINXCONTRIB.AUTOJINJA}") message(STATUS "python sphinx_rtd_theme module (optional): ${PY_SPHINX_RTD_THEME}") message(STATUS " ") -message(STATUS "System Tools:") +message(STATUS "Summary of System Tools:") # Required System Tools message(STATUS "oscap: ${OPENSCAP_OSCAP_EXECUTABLE} (version: ${OSCAP_VERSION})") message(STATUS "sed: ${SED_EXECUTABLE}") @@ -257,35 +259,35 @@ message(STATUS "ansible-lint module (optional): ${ANSIBLE_LINT_EXECUTABLE}") message(STATUS "ansible-playbook module (optional): ${ANSIBLE_PLAYBOOK_EXECUTABLE}") message(STATUS "BATS framework (optional): ${BATS_EXECUTABLE}") message(STATUS "grep (optional): ${GREP_EXECUTABLE}") -message(STATUS "shellcheck (optional): ${SHELLCHECK_EXECUTABLE}") message(STATUS "linkchecker (optional): ${LINKCHECKER_EXECUTABLE}") +message(STATUS "shellcheck (optional): ${SHELLCHECK_EXECUTABLE}") message(STATUS "yamllint module (optional): ${YAMLLINT_EXECUTABLE}") message(STATUS " ") message(STATUS "CMake Settings:") message(STATUS "build type: ${CMAKE_BUILD_TYPE}") +message(STATUS "build directory: ${CMAKE_BINARY_DIR}") message(STATUS "generator: ${CMAKE_GENERATOR}") message(STATUS "source directory: ${CMAKE_SOURCE_DIR}") -message(STATUS "build directory: ${CMAKE_BINARY_DIR}") -message(STATUS "Logging: ${SSG_LOG}") message(STATUS " ") message(STATUS "Build options:") message(STATUS "SSG vendor string: ${SSG_VENDOR}") message(STATUS "Target OVAL version: ${SSG_TARGET_OVAL_VERSION}") +message(STATUS "Logging: ${SSG_LOG}") message(STATUS "Ansible Playbooks: ${SSG_ANSIBLE_PLAYBOOKS_ENABLED}") message(STATUS "Ansible Playbooks Per Rule: ${SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED}") message(STATUS "Bash scripts: ${SSG_BASH_SCRIPTS_ENABLED}") -message(STATUS "STIG Delta Taloring files: ${SSG_BUILD_DISA_DELTA_FILES}") +message(STATUS "Build SCE Content: ${SSG_SCE_ENABLED}") +message(STATUS "Build SRG XLSX Export: ${SSG_SRG_XLSX_EXPORT}") if(SSG_JINJA2_CACHE_ENABLED) message(STATUS "jinja2 cache: enabled") message(STATUS "jinja2 cache dir: ${SSG_JINJA2_CACHE_DIR}") else() message(STATUS "jinja2 cache: disabled") endif() -message(STATUS "Build SCE Content: ${SSG_SCE_ENABLED}") -message(STATUS "Build SRG XLSX Export: ${SSG_SRG_XLSX_EXPORT}") message(STATUS "Separate SCAP files: ${SSG_SEPARATE_SCAP_FILES_ENABLED}") +message(STATUS "STIG Delta Taloring files: ${SSG_BUILD_DISA_DELTA_FILES}") message(STATUS "Thin data streams: ${SSG_THIN_DS}") message(STATUS " ")