From 11d20290c91cac49c4f16c7a5fb59f758851aa33 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Wed, 16 Feb 2022 17:21:09 -0800 Subject: [PATCH 1/3] Always skip update command for git based external projects I noticed that some external projects were being reconfigured/built with every make, even though no files in the external project had been updated. With some debugging I noticed that git based external projects were re-running their "update" step every time, and that in turn caused the configure/build/install steps to re-run as well. (Generally the build step is a no-op as the Makefile/etc. in the external project is well formed and doesn't do anything, but the configure/install steps still run). It seems related to this cmake bug: https://gitlab.kitware.com/cmake/cmake/-/issues/19703. In short, the git update step for an external project does not create any "done" file that denotes that the files are still up-to-date. Without that "done" file, the update step is always run, and that in turn causes the other steps for the external project to re-run as well. The best way to fix this seems to be to skip the update step by defining an empty UPDATE_COMMAND. As long as the downloaded code for a given hash/tag/etc does not change, the update step is unnecessary. And if we *really* wanted to ensure unchanged dependencies, we would download our own copies anyway. Making this change significantly cleans up the falco build to avoid rebuilding git based external dependencies. Signed-off-by: Mark Stemm --- cmake/modules/DownloadStringViewLite.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/modules/DownloadStringViewLite.cmake b/cmake/modules/DownloadStringViewLite.cmake index 26f409fc90e..872da0b766f 100644 --- a/cmake/modules/DownloadStringViewLite.cmake +++ b/cmake/modules/DownloadStringViewLite.cmake @@ -24,6 +24,7 @@ ExternalProject_Add( GIT_TAG "v1.4.0" CONFIGURE_COMMAND "" BUILD_COMMAND "" + UPDATE_COMMAND "" INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${STRING_VIEW_LITE_PREFIX}/src/string-view-lite/include/nonstd/string_view.hpp ${STRING_VIEW_LITE_INCLUDE}/nonstd/string_view.hpp) From a1443ef9182e75aaccdeceee808a5dc58925928b Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Wed, 16 Feb 2022 17:32:54 -0800 Subject: [PATCH 2/3] Cmake function to copy files from source to build dir, as a target Define a cmake function copy_files_to_build_dir(source_files, targetsuffix) that defines a single custom target and single custom command to copy the set of source files to CMAKE_CURRENT_BINARY_DIR. All of the real work is done via cmake -E copy_if_different. This function will replace the nearly identical cmake code in several other directories. This function has the advantage of being a single target for the set of source files instead of a target per-file. Signed-off-by: Mark Stemm --- cmake/modules/copy_files_to_build_dir.cmake | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cmake/modules/copy_files_to_build_dir.cmake diff --git a/cmake/modules/copy_files_to_build_dir.cmake b/cmake/modules/copy_files_to_build_dir.cmake new file mode 100644 index 00000000000..efa49a218c0 --- /dev/null +++ b/cmake/modules/copy_files_to_build_dir.cmake @@ -0,0 +1,30 @@ +# +# Copyright (C) 2022 The Falco Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +function(copy_files_to_build_dir source_files targetsuffix) + + set(build_files) + + foreach(file_path ${source_files}) + get_filename_component(trace_file ${file_path} NAME) + list(APPEND build_files ${CMAKE_CURRENT_BINARY_DIR}/${trace_file}) + endforeach() + + add_custom_target(copy-files-${targetsuffix} ALL + DEPENDS ${build_files}) + + add_custom_command(OUTPUT ${build_files} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${source_files} ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${source_files}) + +endfunction() From 517ff1b1743b00373c7ca90b2ccb5d1af7b95614 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Wed, 16 Feb 2022 17:35:36 -0800 Subject: [PATCH 3/3] Use cmake function to copy files, as a single target Replace nearly-identical blocks of code that defined individual custom targets/custom commands to copy files from source to build dir with the copy_files_to_build_dir function. This reduces the number of build targets and speeds up/cleans up the make output. Signed-off-by: Mark Stemm --- docker/local/rules/CMakeLists.txt | 12 +++--------- docker/local/traces/CMakeLists.txt | 12 +++--------- test/CMakeLists.txt | 3 --- test/trace_files/CMakeLists.txt | 14 +++----------- test/trace_files/k8s_audit/CMakeLists.txt | 15 +++------------ test/trace_files/plugins/CMakeLists.txt | 15 +++------------ test/trace_files/psp/CMakeLists.txt | 15 +++------------ 7 files changed, 18 insertions(+), 68 deletions(-) diff --git a/docker/local/rules/CMakeLists.txt b/docker/local/rules/CMakeLists.txt index f6b934c155c..fdb84ffc803 100644 --- a/docker/local/rules/CMakeLists.txt +++ b/docker/local/rules/CMakeLists.txt @@ -1,13 +1,7 @@ +include(copy_files_to_build_dir) + # Note: list of rules is created at cmake time, not build time file(GLOB test_rule_files "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/rules/*.yaml") -foreach(rule_file_path ${test_rule_files}) - get_filename_component(rule_file ${rule_file_path} NAME) - add_custom_target(docker-local-rule-${rule_file} ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${rule_file}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${rule_file} - COMMAND ${CMAKE_COMMAND} -E copy ${rule_file_path} ${CMAKE_CURRENT_BINARY_DIR}/${rule_file} - DEPENDS ${rule_file_path}) -endforeach() - +copy_files_to_build_dir("${test_rule_files}" docker-local-rules) diff --git a/docker/local/traces/CMakeLists.txt b/docker/local/traces/CMakeLists.txt index 87cd3356501..95519bcb8e9 100644 --- a/docker/local/traces/CMakeLists.txt +++ b/docker/local/traces/CMakeLists.txt @@ -1,13 +1,7 @@ +include(copy_files_to_build_dir) + # Note: list of traces is created at cmake time, not build time file(GLOB test_trace_files "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/trace_files/*.scap") -foreach(trace_file_path ${test_trace_files}) - get_filename_component(trace_file ${trace_file_path} NAME) - add_custom_target(docker-local-trace-${trace_file} ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${trace_file}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - COMMAND ${CMAKE_COMMAND} -E copy ${trace_file_path} ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - DEPENDS ${trace_file_path}) -endforeach() - +copy_files_to_build_dir("${test_trace_files}" docker-local-traces) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f01777f46b2..bfc5c268755 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,4 @@ add_subdirectory(trace_files) -add_custom_target(test-trace-files ALL) -add_dependencies(test-trace-files trace-files-base-scap trace-files-psp trace-files-k8s-audit trace-files-plugins) - add_subdirectory(plugins) add_subdirectory(confs/plugins) diff --git a/test/trace_files/CMakeLists.txt b/test/trace_files/CMakeLists.txt index fe5dedf97d4..032bb7b9a4d 100644 --- a/test/trace_files/CMakeLists.txt +++ b/test/trace_files/CMakeLists.txt @@ -2,19 +2,11 @@ add_subdirectory(k8s_audit) add_subdirectory(psp) add_subdirectory(plugins) +include(copy_files_to_build_dir) + # Note: list of traces is created at cmake time, not build time file(GLOB test_trace_files "${CMAKE_CURRENT_SOURCE_DIR}/*.scap") -foreach(trace_file_path ${test_trace_files}) - get_filename_component(trace_file ${trace_file_path} NAME) - add_custom_target(test-trace-${trace_file} ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${trace_file}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - COMMAND ${CMAKE_COMMAND} -E copy ${trace_file_path} ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - DEPENDS ${trace_file_path}) - list(APPEND BASE_SCAP_TRACE_FILES_TARGETS test-trace-${trace_file}) -endforeach() +copy_files_to_build_dir("${test_trace_files}" base-scap) -add_custom_target(trace-files-base-scap ALL) -add_dependencies(trace-files-base-scap ${BASE_SCAP_TRACE_FILES_TARGETS}) diff --git a/test/trace_files/k8s_audit/CMakeLists.txt b/test/trace_files/k8s_audit/CMakeLists.txt index 0a482806468..2408bb884d4 100644 --- a/test/trace_files/k8s_audit/CMakeLists.txt +++ b/test/trace_files/k8s_audit/CMakeLists.txt @@ -1,16 +1,7 @@ +include(copy_files_to_build_dir) + # Note: list of traces is created at cmake time, not build time file(GLOB test_trace_files "${CMAKE_CURRENT_SOURCE_DIR}/*.json") -foreach(trace_file_path ${test_trace_files}) - get_filename_component(trace_file ${trace_file_path} NAME) - add_custom_target(test-trace-${trace_file} ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${trace_file}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - COMMAND ${CMAKE_COMMAND} -E copy ${trace_file_path} ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - DEPENDS ${trace_file_path}) - list(APPEND K8S_AUDIT_TRACE_FILES_TARGETS test-trace-${trace_file}) -endforeach() - -add_custom_target(trace-files-k8s-audit ALL) -add_dependencies(trace-files-k8s-audit ${K8S_AUDIT_TRACE_FILES_TARGETS}) \ No newline at end of file +copy_files_to_build_dir("${test_trace_files}" k8s-audit) diff --git a/test/trace_files/plugins/CMakeLists.txt b/test/trace_files/plugins/CMakeLists.txt index 67af5f85362..36b34a582e8 100644 --- a/test/trace_files/plugins/CMakeLists.txt +++ b/test/trace_files/plugins/CMakeLists.txt @@ -1,16 +1,7 @@ +include(copy_files_to_build_dir) + # Note: list of traces is created at cmake time, not build time file(GLOB test_trace_files "${CMAKE_CURRENT_SOURCE_DIR}/*.json") -foreach(trace_file_path ${test_trace_files}) - get_filename_component(trace_file ${trace_file_path} NAME) - add_custom_target(test-trace-${trace_file} ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${trace_file}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - COMMAND ${CMAKE_COMMAND} -E copy ${trace_file_path} ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - DEPENDS ${trace_file_path}) - list(APPEND PLUGINS_TRACE_FILES_TARGETS test-trace-${trace_file}) -endforeach() - -add_custom_target(trace-files-plugins ALL) -add_dependencies(trace-files-plugins ${PLUGINS_TRACE_FILES_TARGETS}) +copy_files_to_build_dir("${test_trace_files}" plugins) diff --git a/test/trace_files/psp/CMakeLists.txt b/test/trace_files/psp/CMakeLists.txt index cf6a0cd1404..4c050b0994d 100644 --- a/test/trace_files/psp/CMakeLists.txt +++ b/test/trace_files/psp/CMakeLists.txt @@ -1,17 +1,8 @@ +include(copy_files_to_build_dir) + # Note: list of traces is created at cmake time, not build time file(GLOB test_trace_files "${CMAKE_CURRENT_SOURCE_DIR}/*.json" "${CMAKE_CURRENT_SOURCE_DIR}/*.scap") -foreach(trace_file_path ${test_trace_files}) - get_filename_component(trace_file ${trace_file_path} NAME) - add_custom_target(test-trace-${trace_file} ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${trace_file}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - COMMAND ${CMAKE_COMMAND} -E copy ${trace_file_path} ${CMAKE_CURRENT_BINARY_DIR}/${trace_file} - DEPENDS ${trace_file_path}) - list(APPEND PSP_TRACE_FILES_TARGETS test-trace-${trace_file}) -endforeach() - -add_custom_target(trace-files-psp ALL) -add_dependencies(trace-files-psp ${PSP_TRACE_FILES_TARGETS}) \ No newline at end of file +copy_files_to_build_dir("${test_trace_files}" psp)