From 7a880d4c5f9c94b1a12ae4ce7e16a339c016cc00 Mon Sep 17 00:00:00 2001 From: molingyu Date: Thu, 5 Sep 2024 19:06:04 +0800 Subject: [PATCH] ci: fix gh action and build script --- .github/workflows/build.yaml | 3 --- build.bat | 3 +++ build.sh | 3 +++ gen/gen.py | 12 +++++++----- src/CMakeLists.txt | 26 ++------------------------ src/{gen => }/word2number.h | 0 test/test_word2number.c | 2 +- 7 files changed, 16 insertions(+), 33 deletions(-) rename src/{gen => }/word2number.h (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c7b50e7..0c2517b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -95,9 +95,6 @@ jobs: - name: Configure CMake run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - name: echo dir - run: echo ${{github.workspace}} - - name: Build working-directory: ${{github.workspace}} run: cmake --build ./build --config ${{env.BUILD_TYPE}} diff --git a/build.bat b/build.bat index 0354f19..991e390 100644 --- a/build.bat +++ b/build.bat @@ -1,5 +1,8 @@ rmdir /s /q build mkdir build +rmdir /s /q src/gen +mkdir src/gen +python .\gen\gen.py cd build cmake .. cmake --build . diff --git a/build.sh b/build.sh index 1458f97..65caead 100644 --- a/build.sh +++ b/build.sh @@ -2,6 +2,9 @@ rm -rf build mkdir build +rmdir -rf src/gen +mkdir src/gen +python .\gen\gen.py cd build cmake -i18n_format_DOCS=OFF .. cmake --build . \ No newline at end of file diff --git a/gen/gen.py b/gen/gen.py index 659a374..13e9a70 100644 --- a/gen/gen.py +++ b/gen/gen.py @@ -2,7 +2,7 @@ from jinja2 import Environment, FileSystemLoader -TemplateLoader = FileSystemLoader(os.path.abspath("../gen/template")) +TemplateLoader = FileSystemLoader(os.path.abspath("./gen/template")) env = Environment(loader=TemplateLoader) @@ -18,7 +18,7 @@ def word2number_gen(include_list): word2numberf_table = '' number2wordf_table = '' for path in include_list: - include += f'#include "./locale/{path}/word2number_{path}.h"\n' + include += f'#include "../locale/{path}/word2number_{path}.h"\n' word2number_table += f'{{ "{path}", & word2number_{path} }},\n' number2word_table += f'{{ "{path}", & number2word_{path} }},\n' word2numberf_table += f'{{ "{path}", & word2numberf_{path} }},\n' @@ -36,11 +36,13 @@ def word2number_gen(include_list): def code_gen(template_name): print(f'generator {template_name}.c') template = env.get_template(f'{template_name}.c.j2') - f = open(f'./gen/{template_name}.c', 'w+') - dir_list = os.listdir(os.path.abspath('./locale')) + if not os.path.exists('./src/gen'): + os.mkdir('./src/gen') + f = open(f'./src/gen/{template_name}.c', 'w+') + dir_list = os.listdir(os.path.abspath('./src/locale')) include_list = [] for path in dir_list: - if os.path.exists(os.path.join('./locale', path, f'{template_name}_{path}.h')): + if os.path.exists(os.path.join('./src/locale', path, f'{template_name}_{path}.h')): include_list.append(path) f.write(template.render(globals()[f'{template_name}_gen'](include_list))) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 85f5e16..08f1901 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ find_package(Python3 REQUIRED) set(SOURCE_FILES core.h + word2number.h ) set(API_FILES @@ -17,32 +18,9 @@ set(GEN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gen") file(GLOB LOCALE_H "./locale/**/*.h") file(GLOB LOCALE "./locale/**/*.c") -file(GLOB GEN_SOURCES_H "${GEN_DIR}/*.h") file(GLOB GEN_SOURCES "${GEN_DIR}/*.c") -add_custom_target(codeGenClean - COMMAND rm -f ${GEN_DIR}/*.c - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Clean code generation scripts" -) - -add_custom_target(codeGen - COMMAND ${Python3_EXECUTABLE} ../gen/gen.py - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Running code generation script" - BYPRODUCTS ${GEN_DIR}/*.c -) - -add_dependencies(codeGen codeGenClean) - -add_library(i18n_format ${SOURCE_FILES} ${LOCALE_H} ${GEN_SOURCES_H} ${LOCALE} ${API_FILES}) - -add_dependencies(i18n_format codeGen) - -target_sources(i18n_format PRIVATE - ${GEN_SOURCES_H} - ${GEN_SOURCES} -) +add_library(i18n_format ${SOURCE_FILES} ${GEN_SOURCES} ${LOCALE_H} ${LOCALE} ${API_FILES}) target_include_directories(i18n_format PUBLIC diff --git a/src/gen/word2number.h b/src/word2number.h similarity index 100% rename from src/gen/word2number.h rename to src/word2number.h diff --git a/test/test_word2number.c b/test/test_word2number.c index dfad72c..e5a942d 100644 --- a/test/test_word2number.c +++ b/test/test_word2number.c @@ -166,7 +166,7 @@ #include "test_macros.h" -#include "gen/word2number.h" +#include "word2number.h" int Word2NumberTest( void ) { const int num = word2number("δΈ€", "zh_CN");