Skip to content

Commit 5257914

Browse files
committed
feat: add new build system and test infrastructure for sql_parser
1 parent 13fbd8c commit 5257914

247 files changed

Lines changed: 110701 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile.new

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
CXX = g++
2+
CXXFLAGS = -std=c++17 -Wall -Wextra -g -O2
3+
CPPFLAGS = -I./include -I./third_party/googletest/googletest/include
4+
5+
PROJECT_ROOT = .
6+
SRC_DIR = $(PROJECT_ROOT)/src/sql_parser
7+
INCLUDE_DIR = $(PROJECT_ROOT)/include/sql_parser
8+
TEST_DIR = $(PROJECT_ROOT)/tests
9+
10+
# Library sources
11+
LIB_SRCS = $(SRC_DIR)/arena.cpp $(SRC_DIR)/parser.cpp
12+
LIB_OBJS = $(LIB_SRCS:.cpp=.o)
13+
LIB_TARGET = $(PROJECT_ROOT)/libsqlparser.a
14+
15+
# Google Test library
16+
GTEST_DIR = $(PROJECT_ROOT)/third_party/googletest/googletest
17+
GTEST_SRC = $(GTEST_DIR)/src/gtest-all.cc
18+
GTEST_OBJ = $(GTEST_DIR)/src/gtest-all.o
19+
GTEST_CPPFLAGS = -I$(GTEST_DIR)/include -I$(GTEST_DIR)
20+
21+
# Test sources
22+
TEST_SRCS = $(TEST_DIR)/test_main.cpp \
23+
$(TEST_DIR)/test_arena.cpp \
24+
$(TEST_DIR)/test_tokenizer.cpp \
25+
$(TEST_DIR)/test_classifier.cpp
26+
TEST_OBJS = $(TEST_SRCS:.cpp=.o)
27+
TEST_TARGET = $(PROJECT_ROOT)/run_tests
28+
29+
.PHONY: all lib test clean
30+
31+
all: lib test
32+
33+
lib: $(LIB_TARGET)
34+
35+
$(LIB_TARGET): $(LIB_OBJS)
36+
ar rcs $@ $^
37+
@echo "Built $@"
38+
39+
$(SRC_DIR)/%.o: $(SRC_DIR)/%.cpp
40+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
41+
42+
# Google Test object
43+
$(GTEST_OBJ): $(GTEST_SRC)
44+
$(CXX) $(CXXFLAGS) $(GTEST_CPPFLAGS) -c $< -o $@
45+
46+
# Test objects
47+
$(TEST_DIR)/%.o: $(TEST_DIR)/%.cpp
48+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(GTEST_CPPFLAGS) -c $< -o $@
49+
50+
test: $(TEST_TARGET)
51+
./$(TEST_TARGET)
52+
53+
$(TEST_TARGET): $(TEST_OBJS) $(GTEST_OBJ) $(LIB_TARGET)
54+
$(CXX) $(CXXFLAGS) -o $@ $(TEST_OBJS) $(GTEST_OBJ) -L$(PROJECT_ROOT) -lsqlparser -lpthread
55+
56+
clean:
57+
rm -f $(LIB_OBJS) $(LIB_TARGET) $(TEST_OBJS) $(GTEST_OBJ) $(TEST_TARGET)
58+
@echo "Cleaned."

tests/test_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <gtest/gtest.h>
2+
3+
int main(int argc, char** argv) {
4+
::testing::InitGoogleTest(&argc, argv);
5+
return RUN_ALL_TESTS();
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Run manually to reformat a file:
2+
# clang-format -i --style=file <file>
3+
Language: Cpp
4+
BasedOnStyle: Google
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Bug Report
2+
description: Let us know that something does not work as expected.
3+
title: "[Bug]: Please title this bug report"
4+
body:
5+
- type: textarea
6+
id: what-happened
7+
attributes:
8+
label: Describe the issue
9+
description: What happened, and what did you expect to happen?
10+
validations:
11+
required: true
12+
- type: textarea
13+
id: steps
14+
attributes:
15+
label: Steps to reproduce the problem
16+
description: It is important that we are able to reproduce the problem that you are experiencing. Please provide all code and relevant steps to reproduce the problem, including your `BUILD`/`CMakeLists.txt` file and build commands. Links to a GitHub branch or [godbolt.org](https://godbolt.org/) that demonstrate the problem are also helpful.
17+
validations:
18+
required: true
19+
- type: textarea
20+
id: version
21+
attributes:
22+
label: What version of GoogleTest are you using?
23+
description: Please include the output of `git rev-parse HEAD` or the GoogleTest release version number that you are using.
24+
validations:
25+
required: true
26+
- type: textarea
27+
id: os
28+
attributes:
29+
label: What operating system and version are you using?
30+
description: If you are using a Linux distribution please include the name and version of the distribution as well.
31+
validations:
32+
required: true
33+
- type: textarea
34+
id: compiler
35+
attributes:
36+
label: What compiler and version are you using?
37+
description: Please include the output of `gcc -v` or `clang -v`, or the equivalent for your compiler.
38+
validations:
39+
required: true
40+
- type: textarea
41+
id: buildsystem
42+
attributes:
43+
label: What build system are you using?
44+
description: Please include the output of `bazel --version` or `cmake --version`, or the equivalent for your build system.
45+
validations:
46+
required: true
47+
- type: textarea
48+
id: additional
49+
attributes:
50+
label: Additional context
51+
description: Add any other context about the problem here.
52+
validations:
53+
required: false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Feature request
2+
description: Propose a new feature.
3+
title: "[FR]: Please title this feature request"
4+
labels: "enhancement"
5+
body:
6+
- type: textarea
7+
id: version
8+
attributes:
9+
label: Does the feature exist in the most recent commit?
10+
description: We recommend using the latest commit from GitHub in your projects.
11+
validations:
12+
required: true
13+
- type: textarea
14+
id: why
15+
attributes:
16+
label: Why do we need this feature?
17+
description: Ideally, explain why a combination of existing features cannot be used instead.
18+
validations:
19+
required: true
20+
- type: textarea
21+
id: proposal
22+
attributes:
23+
label: Describe the proposal.
24+
description: Include a detailed description of the feature, with usage examples.
25+
validations:
26+
required: true
27+
- type: textarea
28+
id: platform
29+
attributes:
30+
label: Is the feature specific to an operating system, compiler, or build system version?
31+
description: If it is, please specify which versions.
32+
validations:
33+
required: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Get Help
4+
url: https://github.com/google/googletest/discussions
5+
about: Please ask and answer questions here.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
env:
8+
BAZEL_CXXOPTS: -std=c++14
9+
10+
jobs:
11+
Linux:
12+
runs-on: ubuntu-latest
13+
steps:
14+
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Tests
20+
run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ...
21+
22+
macOS:
23+
runs-on: macos-latest
24+
steps:
25+
26+
- uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Tests
31+
run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ...
32+
33+
34+
Windows:
35+
runs-on: windows-latest
36+
steps:
37+
38+
- uses: actions/checkout@v3
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Tests
43+
run: bazel test --cxxopt=/std:c++14 --features=external_include_paths --test_output=errors ...

third_party/googletest/.gitignore

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Ignore CI build directory
2+
build/
3+
xcuserdata
4+
cmake-build-debug/
5+
.idea/
6+
bazel-bin
7+
bazel-genfiles
8+
bazel-googletest
9+
bazel-out
10+
bazel-testlogs
11+
# python
12+
*.pyc
13+
14+
# Visual Studio files
15+
.vs
16+
*.sdf
17+
*.opensdf
18+
*.VC.opendb
19+
*.suo
20+
*.user
21+
_ReSharper.Caches/
22+
Win32-Debug/
23+
Win32-Release/
24+
x64-Debug/
25+
x64-Release/
26+
27+
# VSCode files
28+
.cache/
29+
cmake-variants.yaml
30+
31+
# Ignore autoconf / automake files
32+
Makefile.in
33+
aclocal.m4
34+
configure
35+
build-aux/
36+
autom4te.cache/
37+
googletest/m4/libtool.m4
38+
googletest/m4/ltoptions.m4
39+
googletest/m4/ltsugar.m4
40+
googletest/m4/ltversion.m4
41+
googletest/m4/lt~obsolete.m4
42+
googlemock/m4
43+
44+
# Ignore generated directories.
45+
googlemock/fused-src/
46+
googletest/fused-src/
47+
48+
# macOS files
49+
.DS_Store
50+
googletest/.DS_Store
51+
googletest/xcode/.DS_Store
52+
53+
# Ignore cmake generated directories and files.
54+
CMakeFiles
55+
CTestTestfile.cmake
56+
Makefile
57+
cmake_install.cmake
58+
googlemock/CMakeFiles
59+
googlemock/CTestTestfile.cmake
60+
googlemock/Makefile
61+
googlemock/cmake_install.cmake
62+
googlemock/gtest
63+
/bin
64+
/googlemock/gmock.dir
65+
/googlemock/gmock_main.dir
66+
/googlemock/RUN_TESTS.vcxproj.filters
67+
/googlemock/RUN_TESTS.vcxproj
68+
/googlemock/INSTALL.vcxproj.filters
69+
/googlemock/INSTALL.vcxproj
70+
/googlemock/gmock_main.vcxproj.filters
71+
/googlemock/gmock_main.vcxproj
72+
/googlemock/gmock.vcxproj.filters
73+
/googlemock/gmock.vcxproj
74+
/googlemock/gmock.sln
75+
/googlemock/ALL_BUILD.vcxproj.filters
76+
/googlemock/ALL_BUILD.vcxproj
77+
/lib
78+
/Win32
79+
/ZERO_CHECK.vcxproj.filters
80+
/ZERO_CHECK.vcxproj
81+
/RUN_TESTS.vcxproj.filters
82+
/RUN_TESTS.vcxproj
83+
/INSTALL.vcxproj.filters
84+
/INSTALL.vcxproj
85+
/googletest-distribution.sln
86+
/CMakeCache.txt
87+
/ALL_BUILD.vcxproj.filters
88+
/ALL_BUILD.vcxproj

0 commit comments

Comments
 (0)