From dc8465212beef70e13d1ec78776b4ea5510cef35 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sun, 28 Apr 2024 16:53:28 -0400 Subject: [PATCH] Require gperf at build-time Rather than allowing the build to continue without gperf, we should fail with an error so that the colour behaviour does not change in a backward incompatible manner. The old colour behaviour should continue to work going forward. This resolves #1868. --- cmake/Conky.cmake | 4 ++++ src/CMakeLists.txt | 25 ++++++++++--------------- src/colour-names-stub.hh | 22 ---------------------- 3 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 src/colour-names-stub.hh diff --git a/cmake/Conky.cmake b/cmake/Conky.cmake index 53f517cda..f49a19633 100644 --- a/cmake/Conky.cmake +++ b/cmake/Conky.cmake @@ -155,6 +155,10 @@ endif(NOT APP_UNAME) find_program(APP_GPERF gperf) +if(NOT APP_GPERF) + message(FATAL_ERROR "Unable to find program 'gperf' (required at build-time as of Conky v1.20.2)") +endif(NOT APP_GPERF) + if(NOT RELEASE) find_program(APP_GIT git) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe3e24709..d36f4dbc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,21 +51,16 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h) endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/defconfig.h) # Generate colour-names.hh with gperf -if(APP_GPERF) - execute_process( - INPUT_FILE "${CMAKE_SOURCE_DIR}/data/color-names.yml" - OUTPUT_FILE "${CMAKE_BINARY_DIR}/data/color-names.gperf" - COMMAND sh "${CMAKE_SOURCE_DIR}/bin/format-colors.sh" - ) - execute_process( - INPUT_FILE "${CMAKE_BINARY_DIR}/data/color-names.gperf" - OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/colour-names.hh" - COMMAND ${APP_GPERF} --ignore-case -LC++ -Zcolor_name_hash -t -7 -m1 -C -E - ) -else(APP_GPERF) - message(WARNING "'gperf' program not found, using stub colour-names.hh; colors names will not be parsed") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/colour-names-stub.hh" "${CMAKE_CURRENT_BINARY_DIR}/colour-names.hh" COPYONLY) -endif(APP_GPERF) +execute_process( + INPUT_FILE "${CMAKE_SOURCE_DIR}/data/color-names.yml" + OUTPUT_FILE "${CMAKE_BINARY_DIR}/data/color-names.gperf" + COMMAND sh "${CMAKE_SOURCE_DIR}/bin/format-colors.sh" +) +execute_process( + INPUT_FILE "${CMAKE_BINARY_DIR}/data/color-names.gperf" + OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/colour-names.hh" + COMMAND ${APP_GPERF} --ignore-case -LC++ -Zcolor_name_hash -t -7 -m1 -C -E +) set(conky_sources ${conky_sources} diff --git a/src/colour-names-stub.hh b/src/colour-names-stub.hh deleted file mode 100644 index 29f64fffd..000000000 --- a/src/colour-names-stub.hh +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To generate colour-names.hh, you must have gperf installed during build. - * This is a dummy implementation for builds without gperf. - * Color name matching will always return null (i.e. no match). - */ - -struct rgb { - const char *name; - uint8_t red; - uint8_t green; - uint8_t blue; -}; - -class color_name_hash { - public: - static const struct rgb *in_word_set(const char *str, size_t len); -}; - -const struct rgb *color_name_hash::in_word_set(const char *str, size_t len) { - DBGP("color parsing not supported"); - return nullptr; -}