From cbdedc54b9f0d532cf6920a6a2a6efb89182a66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 11 May 2021 12:47:30 +0200 Subject: [PATCH 01/29] Allow cmake to generate error.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- library/CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index a5d692cbe4..a6d626b52e 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -109,6 +109,24 @@ set(src_tls ssl_tls13_generic.c ) +find_package(Perl REQUIRED) + +file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h) +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/error.c + COMMAND + ${PERL_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files + ${CMAKE_CURRENT_BINARY_DIR}/error.c + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl + ${error_headers} + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt +) + if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") endif(CMAKE_COMPILER_IS_GNUCC) From 65a72031198b846546aeae90d484200282273a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 11 May 2021 13:02:44 +0200 Subject: [PATCH 02/29] Allow cmake to generate version_features.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- library/CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index a6d626b52e..187693d563 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -127,6 +127,21 @@ add_custom_command( ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt ) +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/version_features.c + COMMAND + ${PERL_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files + ${CMAKE_CURRENT_BINARY_DIR}/version_features.c + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/mbedtls_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/version_features.fmt +) + if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") endif(CMAKE_COMPILER_IS_GNUCC) From aedca0c993bddb4996d1980b962e360d891a9c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 11 May 2021 13:45:54 +0200 Subject: [PATCH 03/29] Simplify source declarations in ssl/CMakeLists.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit query_config was added twice, and while at it let's declare all the sources in one place Signed-off-by: Manuel Pégourié-Gonnard --- programs/ssl/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index def9c7cf6c..bdce56bfcc 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -22,6 +22,7 @@ foreach(exe IN LISTS executables) set(extra_sources "") if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") list(APPEND extra_sources + ssl_test_lib.c ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c) endif() add_executable(${exe} ${exe}.c $ @@ -30,11 +31,6 @@ foreach(exe IN LISTS executables) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() -set_property(TARGET ssl_client2 APPEND PROPERTY SOURCES - ssl_test_lib.c ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c) -set_property(TARGET ssl_server2 APPEND PROPERTY SOURCES - ssl_test_lib.c ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c) - if(THREADS_FOUND) add_executable(ssl_pthread_server ssl_pthread_server.c $) target_include_directories(ssl_pthread_server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) From 3a8413d3165af9b84859ca9e935ad4a183c2622c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 14 May 2021 09:23:57 +0200 Subject: [PATCH 04/29] Allow generate_query_config.pl to take arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- scripts/generate_query_config.pl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/generate_query_config.pl b/scripts/generate_query_config.pl index e3bbaa0745..eab986afad 100755 --- a/scripts/generate_query_config.pl +++ b/scripts/generate_query_config.pl @@ -14,7 +14,8 @@ # information is used to automatically generate the body of the query_config() # function by using the template in scripts/data_files/query_config.fmt. # -# Usage: ./scripts/generate_query_config.pl without arguments +# Usage: scripts/generate_query_config.pl without arguments, or +# generate_query_config.pl config_file template_file output_file # # Copyright The Mbed TLS Contributors # SPDX-License-Identifier: Apache-2.0 @@ -33,15 +34,24 @@ use strict; -my $config_file = "./include/mbedtls/mbedtls_config.h"; +my ($config_file, $query_config_format_file, $query_config_file); -my $query_config_format_file = "./scripts/data_files/query_config.fmt"; -my $query_config_file = "./programs/test/query_config.c"; +if( @ARGV ) { + die "Invalid number of arguments" if scalar @ARGV != 3; + ($config_file, $query_config_format_file, $query_config_file) = @ARGV; -unless( -f $config_file && -f $query_config_format_file ) { - chdir '..' or die; - -f $config_file && -f $query_config_format_file - or die "Without arguments, must be run from root or a subdirectory\n"; + -f $config_file or die "No such file: $config_file"; + -f $query_config_format_file or die "No such file: $query_config_format_file"; +} else { + $config_file = "./include/mbedtls/mbedtls_config.h"; + $query_config_format_file = "./scripts/data_files/query_config.fmt"; + $query_config_file = "./programs/test/query_config.c"; + + unless( -f $config_file && -f $query_config_format_file ) { + chdir '..' or die; + -f $config_file && -f $query_config_format_file + or die "Without arguments, must be run from root or a subdirectory\n"; + } } # Excluded macros from the generated query_config.c. For example, macros that From 86cfa6c27f989bca3c18399a27a276645352100c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 14 May 2021 10:07:33 +0200 Subject: [PATCH 05/29] Allow CMake to generate query_config.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This one was trickier for two reasons: 1. It's used from another directory, see https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory 2. The C file being generated after CMake is run means CMake can't automatically scan for included headers and do its usual magic, so we need to declare the dependency and more importantly the include path. Signed-off-by: Manuel Pégourié-Gonnard --- programs/ssl/CMakeLists.txt | 17 ++++++++++++++++- programs/test/CMakeLists.txt | 27 ++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index bdce56bfcc..a14e264666 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -18,17 +18,32 @@ set(executables ssl_server2 ) +# Inform CMake the the following file will be generated as part of the build +# process, so it doesn't complain that it doesn't exist yet. Starting from +# CMake 3.20, this will no longer be necessary as CMake will automatically +# propagate this information accross the tree, for now it's only visible +# inside the same directory, so we need to propagate manually. +set_source_files_properties( + ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c + PROPERTIES GENERATED TRUE) + foreach(exe IN LISTS executables) set(extra_sources "") if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") list(APPEND extra_sources ssl_test_lib.c - ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c) + ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.h + ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c) endif() add_executable(${exe} ${exe}.c $ ${extra_sources}) target_link_libraries(${exe} ${libs}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) + if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") + add_dependencies(${exe} generate_query_config_c) + target_include_directories(${exe} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../test) + endif() endforeach() if(THREADS_FOUND) diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index a0a1b763cc..8193124e9e 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -27,15 +27,40 @@ if(TEST_CPP) target_link_libraries(cpp_dummy_build ${mbedcrypto_target}) endif() +find_package(Perl REQUIRED) + +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/query_config.c + COMMAND + ${PERL} + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt + ${CMAKE_CURRENT_BINARY_DIR}/query_config.c + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt +) +# this file will also be used in anoter directory, so create a target, see +# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory +add_custom_target(generate_query_config_c + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c) + foreach(exe IN LISTS executables_libs executables_mbedcrypto) set(extra_sources "") if(exe STREQUAL "query_compile_time_config") list(APPEND extra_sources - ${CMAKE_CURRENT_SOURCE_DIR}/query_config.c) + ${CMAKE_CURRENT_SOURCE_DIR}/query_config.h + ${CMAKE_CURRENT_BINARY_DIR}/query_config.c) endif() add_executable(${exe} ${exe}.c $ ${extra_sources}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) + if(exe STREQUAL "query_compile_time_config") + target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + endif() # This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3 list(FIND executables_libs ${exe} exe_index) From 15a42c3e2615c3e47069a63eb6e8b19551cfa2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 14 May 2021 10:33:32 +0200 Subject: [PATCH 06/29] Allow CMake to generate psa_constant_names_generated.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This one's a bit funny too as the generated file is not a source to the executable (ie, it's not passed as an argument to the compiler), so CMake's dependency resolution didn't work even though the file is in the same directory. For some reason, the following didn't work either: add_dependencies(psa_constant_names ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c) So, apply the same strategy as for cross-directory use of a generated file by creating a target and using it as a dependency. Signed-off-by: Manuel Pégourié-Gonnard --- programs/psa/CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index 23e85fea75..01bd687826 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -4,6 +4,21 @@ set(executables psa_constant_names ) +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c + COMMAND + ${PYTHON} + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/../.. + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_extra.h +) + foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) target_link_libraries(${exe} ${mbedcrypto_target}) @@ -11,6 +26,9 @@ foreach(exe IN LISTS executables) endforeach() target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +add_custom_target(generate_psa_constant_names_generated_c + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c) +add_dependencies(psa_constant_names generate_psa_constant_names_generated_c) install(TARGETS ${executables} DESTINATION "bin" From 42681f3bd0142eda32826c8012ac9143c9fc7af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 14 May 2021 10:53:43 +0200 Subject: [PATCH 07/29] Improve formatting of CMake file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - avoid very long lines - match order of command arguments and dependencies - group compiler flags together Signed-off-by: Manuel Pégourié-Gonnard --- tests/CMakeLists.txt | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fbd746e524..574b346dc7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,11 +13,6 @@ if(NOT MBEDTLS_PYTHON_EXECUTABLE) message(FATAL_ERROR "Cannot build test suites without Python 3") endif() -# Enable definition of various functions used throughout the testsuite -# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless -# on non-POSIX platforms. -add_definitions("-D_POSIX_C_SOURCE=200809L") - # 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". @@ -33,9 +28,26 @@ function(add_test_suite suite_name) endif() add_custom_command( - OUTPUT test_suite_${data_name}.c - COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py -f ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function -d ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data -t ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function -p ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function -s ${CMAKE_CURRENT_SOURCE_DIR}/suites --helpers-file ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function -o . - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py ${mbedtls_target} ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data + OUTPUT + test_suite_${data_name}.c + COMMAND + ${MBEDTLS_PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py + -f ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function + -d ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data + -t ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function + -p ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function + -s ${CMAKE_CURRENT_SOURCE_DIR}/suites + --helpers-file ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function + -o . + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py + ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function + ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data + ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function + ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function + ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function + ${mbedtls_target} ) add_executable(test_suite_${data_name} test_suite_${data_name}.c $) @@ -55,6 +67,11 @@ function(add_test_suite suite_name) endif() endfunction(add_test_suite) +# Enable definition of various functions used throughout the testsuite +# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless +# on non-POSIX platforms. +add_definitions("-D_POSIX_C_SOURCE=200809L") + if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") endif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) From a9cb8941688a886a9ba7c6f0eaedd4f89d5004ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 14 May 2021 11:37:09 +0200 Subject: [PATCH 08/29] Add --directory option to generate_psa_tests.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- tests/scripts/generate_psa_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/scripts/generate_psa_tests.py b/tests/scripts/generate_psa_tests.py index 4c8143ff09..260a4c4c99 100755 --- a/tests/scripts/generate_psa_tests.py +++ b/tests/scripts/generate_psa_tests.py @@ -699,6 +699,8 @@ def main(args): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--list', action='store_true', help='List available targets and exit') + parser.add_argument('--directory', metavar='DIR', + help='Output directory (default: tests/suites)') parser.add_argument('targets', nargs='*', metavar='TARGET', help='Target file to generate (default: all; "-": none)') options = parser.parse_args(args) From ce3ba8f030b101df116ee3634df255e3e022f6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 14 May 2021 12:03:37 +0200 Subject: [PATCH 09/29] Allow CMake to run generate_psa_tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: the test suites are actually generated in the source tree, due to the use of link_to_source(suites) This will be fixed in the next commit. Signed-off-by: Manuel Pégourié-Gonnard --- tests/CMakeLists.txt | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 574b346dc7..cddedb455e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,24 @@ if(NOT MBEDTLS_PYTHON_EXECUTABLE) message(FATAL_ERROR "Cannot build test suites without Python 3") endif() +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.current.data + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.v0.data + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/.. + COMMAND + ${MBEDTLS_PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py + --directory ${CMAKE_CURRENT_BINARY_DIR}/suites + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py + ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h + ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h +) + # 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". @@ -27,6 +45,16 @@ function(add_test_suite suite_name) set(data_name ${suite_name}) endif() + if(data_name STREQUAL "psa_crypto_not_supported.generated" OR + data_name STREQUAL "psa_crypto_storage_format.current" OR + data_name STREQUAL "psa_crypto_storage_format.v0") + set(data_file + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_${data_name}.data) + else() + set(data_file + ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data) + endif() + add_custom_command( OUTPUT test_suite_${data_name}.c @@ -34,7 +62,7 @@ function(add_test_suite suite_name) ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py -f ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function - -d ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data + -d ${data_file} -t ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function -p ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function -s ${CMAKE_CURRENT_SOURCE_DIR}/suites @@ -43,7 +71,7 @@ function(add_test_suite suite_name) DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function - ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data + ${data_file} ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function From 313bcfcde8188286874d21e8de4d19c05e0c4786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 7 Sep 2021 12:16:49 +0200 Subject: [PATCH 10/29] Stop writing to the source tree. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to the directory test/suites being linked, the files generated there where actually written to the source tree, not just the binary tree. We no longer need this directory to be linked, that was a remnant of the time where the .data files were read while running the tests; nowadays they're processed when generating the test .c file. Just create the directory, as the generating script quite reasonably assumes that the output directory passed on the command line exists. Signed-off-by: Manuel Pégourié-Gonnard --- tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cddedb455e..48716ae286 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,9 @@ if(NOT MBEDTLS_PYTHON_EXECUTABLE) message(FATAL_ERROR "Cannot build test suites without Python 3") endif() +# generated .data files will go there +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data @@ -215,5 +218,4 @@ if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) link_to_source(data_files) link_to_source(scripts) link_to_source(ssl-opt.sh) - link_to_source(suites) endif() From e90e405e15195414e50505c364183eba858763ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 8 Sep 2021 13:27:09 +0200 Subject: [PATCH 11/29] Introduce "Dev mode" option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the option is On, CMake will have rules to generate the generated files using scripts etc. When the option is Off, CMake will assume the files are available from the source tree; in that mode, it won't require any extra tools (Perl for example) compared to when we committed the files to git. The intention is that users will never need to adjust this option: - in the development branch (and features branches etc.) the option is always On (development mode); - in released tarballs, which include the generated files, we'll switch the option to Off (release mode) in the same commit that re-adds the generated files. Signed-off-by: Manuel Pégourié-Gonnard --- CMakeLists.txt | 1 + library/CMakeLists.txt | 61 +++++++++++++++++++----------------- programs/psa/CMakeLists.txt | 38 ++++++++++++---------- programs/ssl/CMakeLists.txt | 22 +++++++------ programs/test/CMakeLists.txt | 36 +++++++++++---------- tests/CMakeLists.txt | 40 +++++++++++++---------- 6 files changed, 112 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 210aba4893..2731d727c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ option(ENABLE_PROGRAMS "Build mbed TLS programs." ON) option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF) option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON) +option(DEV_MODE "Development mode: (re)generate some files as needed" ON) string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 187693d563..f3b93fbdff 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -109,38 +109,43 @@ set(src_tls ssl_tls13_generic.c ) -find_package(Perl REQUIRED) +if(DEV_MODE) + find_package(Perl REQUIRED) -file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h) -add_custom_command( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/error.c - COMMAND - ${PERL_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl - ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files + file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/error.c - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl - ${error_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt -) + COMMAND + ${PERL_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files + ${CMAKE_CURRENT_BINARY_DIR}/error.c + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_errors.pl + ${error_headers} + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/error.fmt + ) -add_custom_command( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/version_features.c - COMMAND - ${PERL_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl - ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version_features.c - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl - ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/mbedtls_config.h - ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/version_features.fmt -) + COMMAND + ${PERL_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files + ${CMAKE_CURRENT_BINARY_DIR}/version_features.c + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_features.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/mbedtls_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/version_features.fmt + ) +else() + link_to_source(error.c) + link_to_source(version_features.c) +endif() if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes") diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index 01bd687826..c5d0d28dd4 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -4,20 +4,24 @@ set(executables psa_constant_names ) -add_custom_command( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c - COMMAND - ${PYTHON} +if(DEV_MODE) + add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c + COMMAND + ${PYTHON} + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/../.. + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py - ${CMAKE_CURRENT_BINARY_DIR} - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/../.. - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py - ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_extra.h -) + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_extra.h + ) +else() + link_to_source(psa_constant_names_generated.c) +endif() foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) @@ -26,9 +30,11 @@ foreach(exe IN LISTS executables) endforeach() target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -add_custom_target(generate_psa_constant_names_generated_c - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c) -add_dependencies(psa_constant_names generate_psa_constant_names_generated_c) +if(DEV_MODE) + add_custom_target(generate_psa_constant_names_generated_c + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c) + add_dependencies(psa_constant_names generate_psa_constant_names_generated_c) +endif() install(TARGETS ${executables} DESTINATION "bin" diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index a14e264666..e8d2865d9e 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -18,14 +18,16 @@ set(executables ssl_server2 ) -# Inform CMake the the following file will be generated as part of the build -# process, so it doesn't complain that it doesn't exist yet. Starting from -# CMake 3.20, this will no longer be necessary as CMake will automatically -# propagate this information accross the tree, for now it's only visible -# inside the same directory, so we need to propagate manually. -set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c - PROPERTIES GENERATED TRUE) +if(DEV_MODE) + # Inform CMake the the following file will be generated as part of the build + # process, so it doesn't complain that it doesn't exist yet. Starting from + # CMake 3.20, this will no longer be necessary as CMake will automatically + # propagate this information accross the tree, for now it's only visible + # inside the same directory, so we need to propagate manually. + set_source_files_properties( + ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c + PROPERTIES GENERATED TRUE) +endif() foreach(exe IN LISTS executables) set(extra_sources "") @@ -40,7 +42,9 @@ foreach(exe IN LISTS executables) target_link_libraries(${exe} ${libs}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") - add_dependencies(${exe} generate_query_config_c) + if(DEV_MODE) + add_dependencies(${exe} generate_query_config_c) + endif() target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../test) endif() diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 8193124e9e..053b03c952 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -27,26 +27,30 @@ if(TEST_CPP) target_link_libraries(cpp_dummy_build ${mbedcrypto_target}) endif() -find_package(Perl REQUIRED) +if(DEV_MODE) + find_package(Perl REQUIRED) -add_custom_command( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/query_config.c - COMMAND - ${PERL} + add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/query_config.c + COMMAND + ${PERL} + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt + ${CMAKE_CURRENT_BINARY_DIR}/query_config.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt - ${CMAKE_CURRENT_BINARY_DIR}/query_config.c - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl - ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt -) -# this file will also be used in anoter directory, so create a target, see -# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory -add_custom_target(generate_query_config_c - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c) + ) + # this file will also be used in anoter directory, so create a target, see + # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory + add_custom_target(generate_query_config_c + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c) +else() + link_to_source(query_config.c) +endif() foreach(exe IN LISTS executables_libs executables_mbedcrypto) set(extra_sources "") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 48716ae286..454fe5aabd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,23 +16,29 @@ endif() # generated .data files will go there file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) -add_custom_command( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data - ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.current.data - ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.v0.data - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/.. - COMMAND - ${MBEDTLS_PYTHON_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py - --directory ${CMAKE_CURRENT_BINARY_DIR}/suites - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py - ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_config.h - ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h - ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h -) +if(DEV_MODE) + add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.current.data + ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.v0.data + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/.. + COMMAND + ${MBEDTLS_PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py + --directory ${CMAKE_CURRENT_BINARY_DIR}/suites + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py + ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h + ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h + ) +else() + link_to_source(suites/test_suite_psa_crypto_not_supported.generated.data) + link_to_source(suites/test_suite_psa_crypto_storage_format.current.data) + link_to_source(suites/test_suite_psa_crypto_storage_format.v0.data) +endif() # 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 389150d4dbb6a8ee0666cd5ccf78d6fdb8b349f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 9 Sep 2021 10:51:16 +0200 Subject: [PATCH 12/29] Cleanup: remove *.datax files with CMake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unrelated to other commits in this PR, except when running manual tests I kept noticing these files where left over. Signed-off-by: Manuel Pégourié-Gonnard --- tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 454fe5aabd..6d54d7c576 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -85,6 +85,8 @@ function(add_test_suite suite_name) ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function ${mbedtls_target} + BYPRODUCTS + test_suite_${data_name}.datax ) add_executable(test_suite_${data_name} test_suite_${data_name}.c $) From bfe54d703d2709ae9b24780d4382bf801e11a54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 9 Sep 2021 11:11:44 +0200 Subject: [PATCH 13/29] Cleanup: rm all files generated by cmake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Again, unrelated, except I kept noticing. Signed-off-by: Manuel Pégourié-Gonnard --- tests/scripts/all.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 099174372e..27a83a23b4 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -292,7 +292,8 @@ cleanup() -iname CMakeFiles -exec rm -rf {} \+ -o \ \( -iname cmake_install.cmake -o \ -iname CTestTestfile.cmake -o \ - -iname CMakeCache.txt \) -exec rm -f {} \+ + -iname CMakeCache.txt -o \ + -path './cmake/*.cmake' \) -exec rm -f {} \+ # Recover files overwritten by in-tree CMake builds rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile From 9327fb33a6fa32daa42926d5bc500df08b54c51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 9 Sep 2021 11:46:25 +0200 Subject: [PATCH 14/29] Fix test_ref_config component of all.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- tests/scripts/all.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 27a83a23b4..d3fba17877 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -999,7 +999,16 @@ component_test_psa_crypto_rsa_no_genprime() { component_test_ref_configs () { msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s - CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake + # want to re-generate generated files that depend on it, quite correctly. + # However this doesn't work as the generation script expects a specific + # format for mbedtls_config.h, which the other files don't follow. Also, + # cmake can't know this, but re-generation is actually not necessary as + # the generated files only depend on the list of availabe options, not + # whether they're on or off. So, disable cmake's (over-sensitive here) + # dependency resolution for generated files and just rely on them being + # present (thanks for pre_generate_files) by turning DEV_MODE off. + CC=gcc cmake -D DEV_MODE=Off -D CMAKE_BUILD_TYPE:String=Asan . tests/scripts/test-ref-configs.pl } From e12e7f47de986686c257e549841de557f9851f77 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 15 Oct 2021 19:10:15 +0100 Subject: [PATCH 15/29] Get generated data file list from script Use the generate_psa_tests.py script to generate the list of test data files used as output files by cmake. Do this by introducing a new option --list-for-cmake that prints a semicolon-separated list of the data files with no terminating newline (since this is how a cmake list is represented). Replace the hard-coded output file list with a variable generated by the script using this option. Signed-off-by: David Horstmann --- tests/CMakeLists.txt | 13 ++++++++++--- tests/scripts/generate_psa_tests.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6d54d7c576..ef41f2996e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,11 +17,18 @@ endif() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) if(DEV_MODE) + execute_process( + COMMAND + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py + --list-for-cmake + --directory ${CMAKE_CURRENT_BINARY_DIR}/suites + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/.. + OUTPUT_VARIABLE + TEST_SUITE_DATA_FILES) add_custom_command( OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_not_supported.generated.data - ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.current.data - ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_psa_crypto_storage_format.v0.data + ${TEST_SUITE_DATA_FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. COMMAND diff --git a/tests/scripts/generate_psa_tests.py b/tests/scripts/generate_psa_tests.py index 260a4c4c99..16e27ee6bb 100755 --- a/tests/scripts/generate_psa_tests.py +++ b/tests/scripts/generate_psa_tests.py @@ -699,6 +699,8 @@ def main(args): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--list', action='store_true', help='List available targets and exit') + parser.add_argument('--list-for-cmake', action='store_true', + help='Print \';\'-separated list of available targets and exit') parser.add_argument('--directory', metavar='DIR', help='Output directory (default: tests/suites)') parser.add_argument('targets', nargs='*', metavar='TARGET', @@ -710,6 +712,15 @@ def main(args): for name in sorted(generator.TARGETS): print(generator.filename_for(name)) return + # List in a cmake list format (i.e. ';'-separated) + if options.list_for_cmake: + filenames = [] + for name in sorted(generator.TARGETS): + if ';' in generator.filename_for(name): + raise ValueError('Cannot pass filename containing \';\' to cmake: ' + name) + filenames.append(generator.filename_for(name)) + print(';'.join(filenames), end='') + return if options.targets: # Allow "-" as a special case so you can run # ``generate_psa_tests.py - $targets`` and it works uniformly whether From 7b78ec88a4b6dff9345ff534541aa80f8f92b4dc Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 19 Oct 2021 14:43:54 +0100 Subject: [PATCH 16/29] Change variable name to lowercase This seems more correct for variables that are only used in a small area of the cmake file. Signed-off-by: David Horstmann --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ef41f2996e..ef484f68e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,10 +25,10 @@ if(DEV_MODE) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. OUTPUT_VARIABLE - TEST_SUITE_DATA_FILES) + test_suite_data_files) add_custom_command( OUTPUT - ${TEST_SUITE_DATA_FILES} + ${test_suite_data_files} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. COMMAND From 1732b5d6ee51aa6bb7c7b61bf265864c79ebbdab Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 19 Oct 2021 16:43:53 +0100 Subject: [PATCH 17/29] Move test link_to_source() calls into a foreach This removes a hardcoded list of generated test names Signed-off-by: David Horstmann --- tests/CMakeLists.txt | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ef484f68e2..4e44f88211 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,16 +16,17 @@ endif() # generated .data files will go there file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) +execute_process( + COMMAND + ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py + --list-for-cmake + --directory ${CMAKE_CURRENT_BINARY_DIR}/suites + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/.. + OUTPUT_VARIABLE + test_suite_data_files) + if(DEV_MODE) - execute_process( - COMMAND - ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py - --list-for-cmake - --directory ${CMAKE_CURRENT_BINARY_DIR}/suites - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/.. - OUTPUT_VARIABLE - test_suite_data_files) add_custom_command( OUTPUT ${test_suite_data_files} @@ -42,9 +43,9 @@ if(DEV_MODE) ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h ) else() - link_to_source(suites/test_suite_psa_crypto_not_supported.generated.data) - link_to_source(suites/test_suite_psa_crypto_storage_format.current.data) - link_to_source(suites/test_suite_psa_crypto_storage_format.v0.data) + foreach(file ${test_suite_data_files}) + link_to_source(${file}) + endforeach() endif() # Test suites caught by SKIP_TEST_SUITES are built but not executed. From b3a5424a4e6e1c09d9b38ed1aa2b9cc1644bf3ce Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 19 Oct 2021 18:37:04 +0100 Subject: [PATCH 18/29] Add function to remove last filename extension Add a new function that takes a string and removes the portion following the last '.' character, usually a file extension. This would transform: * "a.b.c" into "a.b" * "name." into "name" * ".name" into "" * "no_dot" into "no_dot" (i.e. no change) CMake's existing file-extension-removal command removes the largest possible extension which would make "a.b.c" into "a", which is incorrect for handling tests that have '.'s within their names. The desired behaviour was added in CMake 3.14, but we support CMake >= 3.5.1 (for 3.0) and >= 2.8.12.2 (for 2.x) at the time of writing. Signed-off-by: David Horstmann --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2731d727c4..9c34da9228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,22 @@ function(link_to_source base_name) endif() endfunction(link_to_source) +# Get the filename without the final extension (i.e. convert "a.b.c" to "a.b") +function(get_name_without_last_ext dest_var full_name) + # Split into a list on '.' (but a cmake list is just a ';'-separated string) + string(REPLACE "." ";" ext_parts "${full_name}") + # Remove the last item if there are more than one + list(LENGTH ext_parts ext_parts_len) + if (${ext_parts_len} GREATER "1") + math(EXPR ext_parts_last_item "${ext_parts_len} - 1") + list(REMOVE_AT ext_parts ${ext_parts_last_item}) + endif() + # Convert back to a string by replacing separators with '.' + string(REPLACE ";" "." no_ext_name "${ext_parts}") + # Copy into the desired variable + set(${dest_var} ${no_ext_name} PARENT_SCOPE) +endfunction(get_name_without_last_ext) + string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") include(CheckCCompilerFlag) From ae7bd3513cf1c47740cbdeccc105728f07025086 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 19 Oct 2021 19:05:42 +0100 Subject: [PATCH 19/29] Select test data directory using generated list Remove a hardcoded list of tests that use generated ".data" files, and instead derive this list from the existing list of test files (created using generate_psa_tests.py). This reduces the maintenance burden as only the list in generate_psa_tests.py needs to be updated. Signed-off-by: David Horstmann --- tests/CMakeLists.txt | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4e44f88211..d25f77239c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,12 +24,12 @@ execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. OUTPUT_VARIABLE - test_suite_data_files) + generated_data_files) if(DEV_MODE) add_custom_command( OUTPUT - ${test_suite_data_files} + ${generated_data_files} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. COMMAND @@ -43,7 +43,7 @@ if(DEV_MODE) ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h ) else() - foreach(file ${test_suite_data_files}) + foreach(file ${generated_data_files}) link_to_source(${file}) endforeach() endif() @@ -62,9 +62,20 @@ function(add_test_suite suite_name) set(data_name ${suite_name}) endif() - if(data_name STREQUAL "psa_crypto_not_supported.generated" OR - data_name STREQUAL "psa_crypto_storage_format.current" OR - data_name STREQUAL "psa_crypto_storage_format.v0") + # Get the test names of the tests with generated .data files + # from the generated_data_files list in parent scope. + set(generated_data_names "") + foreach(generated_data_file ${generated_data_files}) + # Get the plain filename + get_filename_component(generated_data_name ${generated_data_file} NAME) + # Remove the ".data" extension + get_name_without_last_ext(generated_data_name ${generated_data_name}) + # Remove leading "test_suite_" + string(SUBSTRING ${generated_data_name} 11 -1 generated_data_name) + list(APPEND generated_data_names ${generated_data_name}) + endforeach() + + if(";${generated_data_names};" MATCHES ";${data_name};") set(data_file ${CMAKE_CURRENT_BINARY_DIR}/suites/test_suite_${data_name}.data) else() From d64f4b249c62954da87648bbb7e26f1980a6615c Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Oct 2021 12:29:47 +0100 Subject: [PATCH 20/29] Fix assorted spelling and wording issues Signed-off-by: David Horstmann --- programs/ssl/CMakeLists.txt | 4 ++-- programs/test/CMakeLists.txt | 2 +- scripts/generate_query_config.pl | 2 +- tests/scripts/all.sh | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index e8d2865d9e..066940e91b 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -19,10 +19,10 @@ set(executables ) if(DEV_MODE) - # Inform CMake the the following file will be generated as part of the build + # Inform CMake that the following file will be generated as part of the build # process, so it doesn't complain that it doesn't exist yet. Starting from # CMake 3.20, this will no longer be necessary as CMake will automatically - # propagate this information accross the tree, for now it's only visible + # propagate this information across the tree, for now it's only visible # inside the same directory, so we need to propagate manually. set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/../test/query_config.c diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 053b03c952..94331b8c7b 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -44,7 +44,7 @@ if(DEV_MODE) ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt ) - # this file will also be used in anoter directory, so create a target, see + # this file will also be used in another directory, so create a target, see # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-add-a-dependency-to-a-source-file-which-is-generated-in-a-subdirectory add_custom_target(generate_query_config_c DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/query_config.c) diff --git a/scripts/generate_query_config.pl b/scripts/generate_query_config.pl index eab986afad..b565024719 100755 --- a/scripts/generate_query_config.pl +++ b/scripts/generate_query_config.pl @@ -50,7 +50,7 @@ if( @ARGV ) { unless( -f $config_file && -f $query_config_format_file ) { chdir '..' or die; -f $config_file && -f $query_config_format_file - or die "Without arguments, must be run from root or a subdirectory\n"; + or die "No arguments supplied, must be run from project root or a first-level subdirectory\n"; } } diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index d3fba17877..f0e9a7d6c0 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1004,10 +1004,10 @@ component_test_ref_configs () { # However this doesn't work as the generation script expects a specific # format for mbedtls_config.h, which the other files don't follow. Also, # cmake can't know this, but re-generation is actually not necessary as - # the generated files only depend on the list of availabe options, not + # the generated files only depend on the list of available options, not # whether they're on or off. So, disable cmake's (over-sensitive here) # dependency resolution for generated files and just rely on them being - # present (thanks for pre_generate_files) by turning DEV_MODE off. + # present (thanks to pre_generate_files) by turning DEV_MODE off. CC=gcc cmake -D DEV_MODE=Off -D CMAKE_BUILD_TYPE:String=Asan . tests/scripts/test-ref-configs.pl } From ff0a3b3aa6d1c55f0beec9b59ff7284a97e50f6d Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Oct 2021 14:04:02 +0100 Subject: [PATCH 21/29] Improve error message in generate_query_config.pl Add usage information to the ARGV-incorrect-length error message in generate_query_config.pl. A plain usage message looks a bit incongruous when raised as an error, but the error message alone is unhelpful. Signed-off-by: David Horstmann --- scripts/generate_query_config.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_query_config.pl b/scripts/generate_query_config.pl index b565024719..7855c7caa4 100755 --- a/scripts/generate_query_config.pl +++ b/scripts/generate_query_config.pl @@ -37,7 +37,7 @@ use strict; my ($config_file, $query_config_format_file, $query_config_file); if( @ARGV ) { - die "Invalid number of arguments" if scalar @ARGV != 3; + die "Invalid number of arguments - usage: $0 [CONFIG_FILE TEMPLATE_FILE OUTPUT_FILE]" if scalar @ARGV != 3; ($config_file, $query_config_format_file, $query_config_file) = @ARGV; -f $config_file or die "No such file: $config_file"; From 7570d24d3d9336aa57373b4b71cadfae9074e422 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Oct 2021 16:27:24 +0100 Subject: [PATCH 22/29] Fix issue with DEV_MODE=OFF case When DEV_MODE=OFF, link_to_source() was being called with a full path in the build directory, rather than just a base name starting at "suites/" as was intended. Fix this by generating a list of base names and using that for link_to_source(), then deriving full paths afterwards. Signed-off-by: David Horstmann --- tests/CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d25f77239c..53692465b7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,15 +16,22 @@ endif() # generated .data files will go there file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) +# Get base names for generated files (starting at "suites/") execute_process( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py --list-for-cmake - --directory ${CMAKE_CURRENT_BINARY_DIR}/suites + --directory suites WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. OUTPUT_VARIABLE - generated_data_files) + base_generated_data_files) + +# Derive generated file paths in the build directory +set(generated_data_files "") +foreach(file ${base_generated_data_files}) + list(APPEND generated_data_files ${CMAKE_CURRENT_BINARY_DIR}/${file}) +endforeach() if(DEV_MODE) add_custom_command( @@ -43,7 +50,7 @@ if(DEV_MODE) ${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h ) else() - foreach(file ${generated_data_files}) + foreach(file ${base_generated_data_files}) link_to_source(${file}) endforeach() endif() From f602eb19bacaa5d411b1ccf000db361ca3b1c468 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Oct 2021 16:40:56 +0100 Subject: [PATCH 23/29] Add comment explaining generate_psa_code.py Explain that the output filename is derived from the -d argument, so that it's obvious why the CMakefile code does what it does. Signed-off-by: David Horstmann --- tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 53692465b7..c884769682 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -92,6 +92,8 @@ function(add_test_suite suite_name) add_custom_command( OUTPUT + # The output filename of generate_test_code.py is derived from the -d + # input argument. test_suite_${data_name}.c COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} From 3e30ad9b0d8ec230f490088ddd7273e7d592abcf Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Oct 2021 16:53:58 +0100 Subject: [PATCH 24/29] Use MBEDTLS_PYTHON_EXECUTABLE Change one occurrence of ${PYTHON} to ${MBEDTLS_PYTHON_EXECUTABLE} and add implied ${MBEDTLS_PYTHON_EXECUTABLE} to the start of a different command. Signed-off-by: David Horstmann --- programs/psa/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index c5d0d28dd4..fd8eeea783 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -9,7 +9,7 @@ if(DEV_MODE) OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c COMMAND - ${PYTHON} + ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c884769682..0bd94baa27 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites) # Get base names for generated files (starting at "suites/") execute_process( COMMAND + ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py --list-for-cmake --directory suites From a8d14061073055ce619b2e254cb8f5e5e827ac0d Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Oct 2021 17:14:23 +0100 Subject: [PATCH 25/29] Rename DEV_MODE to GEN_FILES GEN_FILES is a bit clearer as it describes what the setting does more precisely. Signed-off-by: David Horstmann --- CMakeLists.txt | 2 +- library/CMakeLists.txt | 2 +- programs/psa/CMakeLists.txt | 4 ++-- programs/ssl/CMakeLists.txt | 4 ++-- programs/test/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- tests/scripts/all.sh | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c34da9228..b0ece2a0ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ option(ENABLE_PROGRAMS "Build mbed TLS programs." ON) option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF) option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON) -option(DEV_MODE "Development mode: (re)generate some files as needed" ON) +option(GEN_FILES "Generate the auto-generated files as needed" ON) string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index f3b93fbdff..18aff5af39 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -109,7 +109,7 @@ set(src_tls ssl_tls13_generic.c ) -if(DEV_MODE) +if(GEN_FILES) find_package(Perl REQUIRED) file(GLOB error_headers ${CMAKE_CURRENT_SOURCE_DIR}/../include/mbedtls/*.h) diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index fd8eeea783..26ca73c185 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -4,7 +4,7 @@ set(executables psa_constant_names ) -if(DEV_MODE) +if(GEN_FILES) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c @@ -30,7 +30,7 @@ foreach(exe IN LISTS executables) endforeach() target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -if(DEV_MODE) +if(GEN_FILES) add_custom_target(generate_psa_constant_names_generated_c DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c) add_dependencies(psa_constant_names generate_psa_constant_names_generated_c) diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 066940e91b..280bbcf3d2 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -18,7 +18,7 @@ set(executables ssl_server2 ) -if(DEV_MODE) +if(GEN_FILES) # Inform CMake that the following file will be generated as part of the build # process, so it doesn't complain that it doesn't exist yet. Starting from # CMake 3.20, this will no longer be necessary as CMake will automatically @@ -42,7 +42,7 @@ foreach(exe IN LISTS executables) target_link_libraries(${exe} ${libs}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") - if(DEV_MODE) + if(GEN_FILES) add_dependencies(${exe} generate_query_config_c) endif() target_include_directories(${exe} diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 94331b8c7b..142a831667 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -27,7 +27,7 @@ if(TEST_CPP) target_link_libraries(cpp_dummy_build ${mbedcrypto_target}) endif() -if(DEV_MODE) +if(GEN_FILES) find_package(Perl REQUIRED) add_custom_command( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0bd94baa27..41dceed939 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,7 +34,7 @@ foreach(file ${base_generated_data_files}) list(APPEND generated_data_files ${CMAKE_CURRENT_BINARY_DIR}/${file}) endforeach() -if(DEV_MODE) +if(GEN_FILES) add_custom_command( OUTPUT ${generated_data_files} diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index f0e9a7d6c0..595b1baf91 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1007,8 +1007,8 @@ component_test_ref_configs () { # the generated files only depend on the list of available options, not # whether they're on or off. So, disable cmake's (over-sensitive here) # dependency resolution for generated files and just rely on them being - # present (thanks to pre_generate_files) by turning DEV_MODE off. - CC=gcc cmake -D DEV_MODE=Off -D CMAKE_BUILD_TYPE:String=Asan . + # present (thanks to pre_generate_files) by turning GEN_FILES off. + CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan . tests/scripts/test-ref-configs.pl } From 65d8c69e80734454204c9dcc1a3c11a4a8cbf63d Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 21 Oct 2021 16:09:51 +0100 Subject: [PATCH 26/29] Remove unnecessary check for ';' in filenames The Makefiles already assume that filenames don't contain special characters anyway, so we don't need to check this in generate_psa_tests.py. Signed-off-by: David Horstmann --- tests/scripts/generate_psa_tests.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/scripts/generate_psa_tests.py b/tests/scripts/generate_psa_tests.py index 16e27ee6bb..1e5d2041b5 100755 --- a/tests/scripts/generate_psa_tests.py +++ b/tests/scripts/generate_psa_tests.py @@ -715,11 +715,8 @@ def main(args): # List in a cmake list format (i.e. ';'-separated) if options.list_for_cmake: filenames = [] - for name in sorted(generator.TARGETS): - if ';' in generator.filename_for(name): - raise ValueError('Cannot pass filename containing \';\' to cmake: ' + name) - filenames.append(generator.filename_for(name)) - print(';'.join(filenames), end='') + print(';'.join(generator.filename_for(name) + for name in sorted(generator.TARGETS)), end='') return if options.targets: # Allow "-" as a special case so you can run From 774965188a1012e57730e8f18e095eb837b9d94a Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 21 Oct 2021 19:45:52 +0100 Subject: [PATCH 27/29] Turn GEN_FILES off by default on windows If on windows, turn off GEN_FILES as it does not currently work (for reasons unknown). Note: The WIN32 variable is "True on windows systems, including win64", as one would expect. Signed-off-by: David Horstmann --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0ece2a0ea..cd990abe88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,11 @@ option(ENABLE_PROGRAMS "Build mbed TLS programs." ON) option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF) option(MBEDTLS_FATAL_WARNINGS "Compiler warnings treated as errors" ON) -option(GEN_FILES "Generate the auto-generated files as needed" ON) +if(WIN32) + option(GEN_FILES "Generate the auto-generated files as needed" OFF) +else() + option(GEN_FILES "Generate the auto-generated files as needed" ON) +endif() string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}") string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}") From 48a05536841b15b22f2d8c54892a5bb75a24304b Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 22 Oct 2021 15:10:46 +0100 Subject: [PATCH 28/29] Document the CMake generated files capability Add a line in the README explaining that CMake will generate the files it needs automatically on non-Windows systems when not cross-compiling. Signed-off-by: David Horstmann --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dbe6a2325e..e6924cbe1d 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ If you are cross-compiling, you must set the `CC` environment variable to a C co Any of the following methods are available to generate the configuration-independent files: * If not cross-compiling, running `make` with any target, or just `make`, will automatically generate required files. +* On non-Windows systems, when not cross-compiling, CMake will generate the required files automatically. * Run `make generated_files` to generate all the configuration-independent files. * On Unix/POSIX systems, run `tests/scripts/check-generated-files.sh -u` to generate all the configuration-independent files. * On Windows, run `scripts\make_generated_files.bat` to generate all the configuration-independent files. From 3ee10e841e1ff1398ae9ecebd85c4ad5455d9e14 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 22 Oct 2021 18:22:11 +0100 Subject: [PATCH 29/29] Fix unused variable in generate_psa_tests.py Remove the newly-unused variable that became unused in a previous commit. Signed-off-by: David Horstmann --- tests/scripts/generate_psa_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/scripts/generate_psa_tests.py b/tests/scripts/generate_psa_tests.py index 1e5d2041b5..39fb210278 100755 --- a/tests/scripts/generate_psa_tests.py +++ b/tests/scripts/generate_psa_tests.py @@ -714,7 +714,6 @@ def main(args): return # List in a cmake list format (i.e. ';'-separated) if options.list_for_cmake: - filenames = [] print(';'.join(generator.filename_for(name) for name in sorted(generator.TARGETS)), end='') return