From 89e7654fc99b9afa3b1f3947b4a7582ef666fb67 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Thu, 13 Jan 2022 16:45:33 +0800 Subject: [PATCH 1/5] fix parallel build fail of test_cmake_out_source Signed-off-by: Jerry Yu --- tests/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2431e4069..2f5426469 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,6 +50,12 @@ if(GEN_FILES) ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h ) + # CMake generate sub-makefile for each target and call it in subprocess. Without + # this command, cmake will generate ruler in each sub makefile. As a result, + # they will conflict under parllel build. + # With this line, only 4 sub-makefiles include above command, that reduces + # conflict risk. + add_custom_target(test_suite_generated_data DEPENDS ${generated_data_files}) else() foreach(file ${base_generated_data_files}) link_to_source(${file}) From 80bc860aab44e951c6c75a8ed58dd3fd9c335ada Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Mon, 17 Jan 2022 18:26:52 +0800 Subject: [PATCH 2/5] add depends to avoid file not found Signed-off-by: Jerry Yu --- tests/CMakeLists.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2f5426469..c87623c67 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,18 +50,18 @@ if(GEN_FILES) ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h ) - # CMake generate sub-makefile for each target and call it in subprocess. Without - # this command, cmake will generate ruler in each sub makefile. As a result, - # they will conflict under parllel build. - # With this line, only 4 sub-makefiles include above command, that reduces - # conflict risk. - add_custom_target(test_suite_generated_data DEPENDS ${generated_data_files}) + else() foreach(file ${base_generated_data_files}) link_to_source(${file}) endforeach() endif() - +# CMake generate sub-makefile for each target and call it in subprocess. Without +# this command, cmake will generate ruler in each sub makefile. As a result, +# they will conflict under parllel build. +# With this line, only 4 sub-makefiles include above command, that reduces +# conflict risk. +add_custom_target(test_suite_generated_data DEPENDS ${generated_data_files}) # Test suites caught by SKIP_TEST_SUITES are built but not executed. # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" # but not "test_suite_foobar". @@ -125,6 +125,7 @@ function(add_test_suite suite_name) ) add_executable(test_suite_${data_name} test_suite_${data_name}.c $) + add_dependencies(test_suite_${data_name} test_suite_generated_data) target_link_libraries(test_suite_${data_name} ${libs}) # Include test-specific header files from ./include and private header # files (used by some invasive tests) from ../library. Public header From 3b86d1b3c64b899b45a87293a8c6cb304e73580f Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Wed, 2 Mar 2022 10:40:41 +0800 Subject: [PATCH 3/5] fix comments grammar issues Signed-off-by: Jerry Yu --- tests/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c87623c67..c1c9052e1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,11 +56,11 @@ else() link_to_source(${file}) endforeach() endif() -# CMake generate sub-makefile for each target and call it in subprocess. Without -# this command, cmake will generate ruler in each sub makefile. As a result, -# they will conflict under parllel build. -# With this line, only 4 sub-makefiles include above command, that reduces -# conflict risk. +# CMake generates sub-makefiles for each target and calls them in subprocesses. +# Without this command, cmake will generate rules in each sub-makefile. As a result, +# they can cause race conditions in parallel builds. +# With this line, only 4 sub-makefiles include the above command, that reduces +# the risk of a race. add_custom_target(test_suite_generated_data DEPENDS ${generated_data_files}) # Test suites caught by SKIP_TEST_SUITES are built but not executed. # "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" From 6dd2e348488a0345385ea2f018ae5830d19785ed Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Tue, 8 Mar 2022 14:13:59 +0800 Subject: [PATCH 4/5] Add changelog entry Signed-off-by: Jerry Yu --- ChangeLog.d/fix-parllel-cmake-build-fail.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 ChangeLog.d/fix-parllel-cmake-build-fail.txt diff --git a/ChangeLog.d/fix-parllel-cmake-build-fail.txt b/ChangeLog.d/fix-parllel-cmake-build-fail.txt new file mode 100644 index 000000000..b892eb6f0 --- /dev/null +++ b/ChangeLog.d/fix-parllel-cmake-build-fail.txt @@ -0,0 +1,6 @@ +Bugfix + * Fix a build bug : when parallel out-of-box build with cmake, it raise file + not found error. That's due to same target is included in different sub- + makefiles. And cmake will call the targets in different forked `make` + process. As a result, the dependancy will be broken. This fix remove the + targets in sub-makefiles and create a global target for it. From 7599f3109a5b26f473847b8d06890bcb80cf597f Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Fri, 11 Mar 2022 16:28:10 +0800 Subject: [PATCH 5/5] Update changelog entry Remove internal details. Add the condition of the bug. Signed-off-by: Jerry Yu --- ChangeLog.d/fix-parllel-cmake-build-fail.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ChangeLog.d/fix-parllel-cmake-build-fail.txt b/ChangeLog.d/fix-parllel-cmake-build-fail.txt index b892eb6f0..4746c7b08 100644 --- a/ChangeLog.d/fix-parllel-cmake-build-fail.txt +++ b/ChangeLog.d/fix-parllel-cmake-build-fail.txt @@ -1,6 +1,3 @@ Bugfix - * Fix a build bug : when parallel out-of-box build with cmake, it raise file - not found error. That's due to same target is included in different sub- - makefiles. And cmake will call the targets in different forked `make` - process. As a result, the dependancy will be broken. This fix remove the - targets in sub-makefiles and create a global target for it. + * Fix a race condition in out-of-source builds with CMake when generated data + files are already present. Fixes #5374