From de966cdf90843819e2f7287e22ddcb5f95491b18 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 24 Oct 2016 16:06:09 +0100 Subject: [PATCH] Error if format_test can't be executed. This ensures that on Travis, format_test will always be executed, or the build fails. --- CMakeLists.txt | 4 ++++ cmake/ApiDsl.cmake | 19 +++++++++++++++++-- other/astyle/format-source | 1 + other/travis/env-linux.sh | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0d10c20..b4e18274 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,8 @@ target_link_modules(toxencryptsave toxcore) set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified") +option(FORMAT_TEST "Require the format_test to be executed; fail cmake if it can't" OFF) + if(APIDSL AND ASTYLE) add_test( NAME format_test @@ -271,6 +273,8 @@ if(APIDSL AND ASTYLE) "${APIDSL}" "${ASTYLE}") set_tests_properties(format_test PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") +elseif(FORMAT_TEST) + message(FATAL_ERROR "format_test can not be run, because either APIDSL (${APIDSL}) or ASTYLE (${ASTYLE}) could not be found") endif() function(auto_test target) diff --git a/cmake/ApiDsl.cmake b/cmake/ApiDsl.cmake index 777714ab..759f7f05 100644 --- a/cmake/ApiDsl.cmake +++ b/cmake/ApiDsl.cmake @@ -10,14 +10,29 @@ find_program(APIDSL NAMES apidsl.byte ${CMAKE_SOURCE_DIR}/../apidsl/apigen.native) find_program(ASTYLE NAMES - astyle) + astyle + $ENV{ASTYLE}) function(apidsl) if(APIDSL AND ASTYLE) foreach(in_file ${ARGN}) - get_filename_component(dirname ${in_file} DIRECTORY) + # Get the directory component of the input file name. + if(CMAKE_VERSION VERSION_LESS 3.0) + execute_process( + COMMAND dirname ${in_file} + OUTPUT_VARIABLE dirname + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + get_filename_component(dirname ${in_file} DIRECTORY) + endif() + + # Get the name without extension (i.e. without ".api.h"). get_filename_component(filename ${in_file} NAME_WE) + + # Put them together, with the new extension that is ".h". set(out_file ${CMAKE_SOURCE_DIR}/${dirname}/${filename}.h) + + # Run apidsl. add_custom_command( OUTPUT ${out_file} COMMAND "${APIDSL}" "${CMAKE_SOURCE_DIR}/${in_file}" diff --git a/other/astyle/format-source b/other/astyle/format-source index 624864ab..d623926d 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source @@ -27,6 +27,7 @@ if ! which "$APIDSL"; then APIDSL=../apidsl/apigen.native else APIDSL=apidsl_curl + fi fi apidsl_curl() { diff --git a/other/travis/env-linux.sh b/other/travis/env-linux.sh index 16dbb8cc..a8b1d5ae 100644 --- a/other/travis/env-linux.sh +++ b/other/travis/env-linux.sh @@ -1,7 +1,7 @@ #!/bin/sh CMAKE=cmake -CMAKE_EXTRA_FLAGS="" +CMAKE_EXTRA_FLAGS="-DFORMAT_TEST=ON" NPROC=`nproc` CURDIR=$PWD