Skip to content

Commit

Permalink
Do not reformat XCCDF if not needed
Browse files Browse the repository at this point in the history
If we have Python 3.9 or newer, we use the ElementTree.indent method
which formats the output which means the output doesn't have to be
reformatted.
jan-cerny committed Mar 1, 2024
1 parent cdd25bc commit f4b4c43
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions cmake/SSGCommon.cmake
Original file line number Diff line number Diff line change
@@ -409,20 +409,30 @@ macro(ssg_build_cpe_dictionary PRODUCT)
endif()
endmacro()

# Apply a final xmllint pass over the XCCDF document to pretty-format the output
# XCCDF document for the product. Then, generate XCCDF 1.2 version as well.
# If built with Python older than 3.9, apply a final xmllint pass over the
# XCCDF document to pretty-format the output XCCDF document for the product.
# If Python 3.9 or newer is used for the build, the output XCCDF is already
# generated pretty and doesn't need to be reformatted.
macro(ssg_build_xccdf_final PRODUCT)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
COMMAND "${XMLLINT_EXECUTABLE}" --nsclean --format --output "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
DEPENDS generate-${PRODUCT}-xccdf-oval-ocil "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-oval.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-ocil.xml"
COMMENT "[${PRODUCT}-content] generating ssg-${PRODUCT}-xccdf.xml"
)
if (PYTHON_VERSION_MAJOR LESS 3 OR PYTHON_VERSION_MINOR LESS 9)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
COMMAND "${XMLLINT_EXECUTABLE}" --nsclean --format --output "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
DEPENDS generate-${PRODUCT}-xccdf-oval-ocil "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-oval.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-ocil.xml"
COMMENT "[${PRODUCT}-content] generating ssg-${PRODUCT}-xccdf.xml"
)
else()
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml" "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
DEPENDS generate-${PRODUCT}-xccdf-oval-ocil "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-oval.xml" "${CMAKE_CURRENT_BINARY_DIR}/ssg-${PRODUCT}-ocil.xml"
COMMENT "[${PRODUCT}-content] generating ssg-${PRODUCT}-xccdf.xml"
)
endif()
add_custom_target(
generate-ssg-${PRODUCT}-xccdf.xml
DEPENDS "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-xccdf.xml"
)

endmacro()

# If built with Python older than 3.9, apply a final xmllint pass over the

0 comments on commit f4b4c43

Please sign in to comment.