ITADN

refactor level config header generation

#500Opengoatshriek 创建于 2025-05-10
help wantedbuildgood first issuerefactor
G
goatshriekcommented
Stumpless uses CMake for the build of the project, including the generation of configuration headers. One of these steps, in `tools/cmake/config_files.cmake`, generates the header files for the logging levels (alert, info, notice, etc.). This code is currently a series of copy-pasted calls to `configure_file`, which could be refactored into a single loop across a few lists with the appropriate variables. This task is to refactor this portion of the CMake build script into a loop so that it is clearer what is happening. ## General Approach There are a few details left out of the following approach, for you to fill in as you encounter them. If you find you need help, please ask here or on the [project gitter](https://gitter.im/stumpless/community) and someone can help you get past the stumbling block. You can write a loop in CMake using one of the [foreach](https://cmake.org/cmake/help/latest/command/foreach.html) commands. A straightforward solution would be to have two lists, one for the long name, and one for the shortname. The loop could iterate over the range of the list, indexing into each one to set the variables before the call to `configure_file`. The [`string`](https://cmake.org/cmake/help/latest/command/string.html) commands will also be useful, particularly `TOUPPER` and `TOLOWER` operations to build the upper and lower case names. Once you have this refactored, make sure that the library continues to build and all tests continue to pass. You may need to delete and re-create the build directory periodically, to make sure that an old version of the script has not left the build in an mixed up state.
3 条评论