Skip to content

Commit

Permalink
ci: fix gh action and build script
Browse files Browse the repository at this point in the history
  • Loading branch information
molingyu committed Sep 5, 2024
1 parent 268dd4c commit 7a880d4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 33 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
3 changes: 3 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -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 .
Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
12 changes: 7 additions & 5 deletions gen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'
Expand All @@ -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)))
Expand Down
26 changes: 2 additions & 24 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ find_package(Python3 REQUIRED)

set(SOURCE_FILES
core.h
word2number.h
)

set(API_FILES
Expand All @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/test_word2number.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

#include "test_macros.h"

#include "gen/word2number.h"
#include "word2number.h"

int Word2NumberTest( void ) {
const int num = word2number("一", "zh_CN");
Expand Down

0 comments on commit 7a880d4

Please sign in to comment.