Skip to content

Commit

Permalink
auto generate sql parser files (#473)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Issue Number: close #305

Problem:
当语法文件flex_sql.l和yacc_sql.y变更时,必须手动执行 gen_parser.sh 生成C++代码文件,比较麻烦。

### What is changed and how it works?
cmake中增加 add_custom_command,在 flex_sql.l 和
yacc_sql.y文件变更时自动重新生成相关的C++代码文件。
当然在这些文件不存在时,也会执行gen_parser.sh生成代码。

### Other information
将生成的代码文件加入了.gitignore,后续不需要再提交这些文件
  • Loading branch information
hnwyllmm authored Nov 6, 2024
1 parent e1aa56d commit 5557f1a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5,889 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ jobs:
runs-on: macos-latest

steps:
- name: Init environment
shell: bash
run: |
brew install bison
- name: Checkout repository and submodules
uses: actions/checkout@v2

- name: Build
shell: bash
run: |
export ASAN_OPTIONS=detect_container_overflow=0
export PATH="/opt/homebrew/opt/bison/bin:$PATH"
sudo bash build.sh init
bash build.sh release --make -j4
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ GPATH
GTAGS
docs/book
#*#

# ignore generated files
src/observer/sql/parser/lex_sql.cpp
src/observer/sql/parser/lex_sql.h
src/observer/sql/parser/yacc_sql.cpp
src/observer/sql/parser/yacc_sql.hpp
12 changes: 12 additions & 0 deletions src/observer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ MESSAGE(STATUS "This is CMAKE_CURRENT_SOURCE_DIR dir " ${CMAKE_CURRENT_SOURCE_DI

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET (PARSER_WORKDIR ${CMAKE_CURRENT_SOURCE_DIR}/sql/parser)
SET (PARSER_SOURCES ${PARSER_WORKDIR}/lex_sql.cpp ${PARSER_WORKDIR}/yacc_sql.cpp)
SET (PARSER_HEADERS ${PARSER_WORKDIR}/lex_sql.h ${PARSER_WORKDIR}/yacc_sql.hpp)
ADD_CUSTOM_COMMAND(
OUTPUT ${PARSER_SOURCES} ${PARSER_HEADERS}
COMMAND bash gen_parser.sh
DEPENDS ${PARSER_WORKDIR}/lex_sql.l ${PARSER_WORKDIR}/yacc_sql.y
WORKING_DIRECTORY ${PARSER_WORKDIR}
COMMENT "generating lex and yacc files"
)

FILE(GLOB_RECURSE ALL_SRC *.cpp *.c)
SET(MAIN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
MESSAGE("MAIN SRC: " ${MAIN_SRC})
SET(LIB_SRC ${LIB_SRC} ${PARSER_SOURCES})
FOREACH (F ${ALL_SRC})

IF (NOT ${F} STREQUAL ${MAIN_SRC})
Expand Down
Loading

0 comments on commit 5557f1a

Please sign in to comment.