Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 16d7321

Browse files
committed
switch to a new codegen executable
1 parent 4b9639b commit 16d7321

Some content is hidden

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

43 files changed

+470
-498
lines changed

.depend

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,71 @@ api.o: api.cpp api.hpp parser_options.hpp string.hpp decoder.hpp \
55
bytes.hpp token_rewriter.hpp token.hpp loc.hpp decoded_input.hpp \
66
source_line.hpp token_ids.hpp shared_byte_list.hpp parser_result.hpp \
77
nodes.hpp diagnostic.hpp messages.hpp comment.hpp magic_comment.hpp \
8-
utils.hpp test_helper.hpp
8+
utils.hpp
99

10-
bytes.o: bytes.cpp bytes.hpp utils.hpp test_helper.hpp
10+
bytes.o: bytes.cpp bytes.hpp utils.hpp
1111

1212
comment.o: comment.cpp utils.hpp comment.hpp loc.hpp decoded_input.hpp \
13-
string.hpp source_line.hpp bytes.hpp test_helper.hpp
13+
string.hpp source_line.hpp bytes.hpp
1414

1515
decoded_input.o: decoded_input.cpp utils.hpp decoded_input.hpp string.hpp \
16-
source_line.hpp bytes.hpp test_helper.hpp
16+
source_line.hpp bytes.hpp
1717

18-
decoder.o: decoder.cpp decoder.hpp string.hpp bytes.hpp utils.hpp \
19-
test_helper.hpp
18+
decoder.o: decoder.cpp decoder.hpp string.hpp bytes.hpp utils.hpp
2019

2120
diagnostic.o: diagnostic.cpp diagnostic.hpp messages.hpp string.hpp \
22-
loc.hpp decoded_input.hpp source_line.hpp bytes.hpp utils.hpp \
23-
test_helper.hpp
21+
loc.hpp decoded_input.hpp source_line.hpp bytes.hpp utils.hpp
2422

2523
loc.o: loc.cpp utils.hpp loc.hpp decoded_input.hpp string.hpp \
26-
source_line.hpp bytes.hpp test_helper.hpp
24+
source_line.hpp bytes.hpp
2725

2826
magic_comment.o: magic_comment.cpp magic_comment.hpp loc.hpp \
29-
decoded_input.hpp string.hpp source_line.hpp bytes.hpp utils.hpp \
30-
test_helper.hpp
27+
decoded_input.hpp string.hpp source_line.hpp bytes.hpp utils.hpp
3128

32-
messages.o: messages.cpp messages.hpp string.hpp utils.hpp \
33-
test_helper.hpp
29+
messages.o: messages.cpp messages.hpp string.hpp utils.hpp
3430

3531
nodes.o: nodes.cpp nodes.hpp string.hpp loc.hpp decoded_input.hpp \
36-
source_line.hpp bytes.hpp utils.hpp test_helper.hpp
32+
source_line.hpp bytes.hpp utils.hpp
3733

3834
parser_options.o: parser_options.cpp parser_options.hpp string.hpp \
3935
decoder.hpp bytes.hpp token_rewriter.hpp token.hpp loc.hpp \
4036
decoded_input.hpp source_line.hpp token_ids.hpp shared_byte_list.hpp \
41-
utils.hpp test_helper.hpp
37+
utils.hpp
4238

4339
parser_result.o: parser_result.cpp parser_result.hpp nodes.hpp string.hpp \
4440
loc.hpp decoded_input.hpp source_line.hpp bytes.hpp token.hpp \
4541
token_ids.hpp diagnostic.hpp messages.hpp comment.hpp \
46-
magic_comment.hpp utils.hpp test_helper.hpp
42+
magic_comment.hpp utils.hpp
4743

48-
shared_byte_list.o: shared_byte_list.cpp shared_byte_list.hpp \
49-
test_helper.hpp
44+
shared_byte_list.o: shared_byte_list.cpp shared_byte_list.hpp
5045

51-
source_line.o: source_line.cpp source_line.hpp utils.hpp test_helper.hpp
46+
source_line.o: source_line.cpp source_line.hpp utils.hpp
5247

53-
string.o: string.cpp string.hpp utils.hpp test_helper.hpp
54-
55-
test_helper.o: test_helper.cpp test_helper.hpp
48+
string.o: string.cpp string.hpp utils.hpp
5649

5750
token.o: token.cpp token.hpp bytes.hpp loc.hpp decoded_input.hpp \
58-
string.hpp source_line.hpp token_ids.hpp utils.hpp test_helper.hpp
51+
string.hpp source_line.hpp token_ids.hpp utils.hpp
5952

6053
token_rewriter.o: token_rewriter.cpp token_rewriter.hpp token.hpp \
6154
bytes.hpp loc.hpp decoded_input.hpp string.hpp source_line.hpp \
62-
token_ids.hpp shared_byte_list.hpp utils.hpp test_helper.hpp
63-
64-
tests/runner: tests/test.cpp tests/../test_helper.hpp tests/../bytes.hpp \
65-
tests/../comment.hpp tests/../loc.hpp tests/../decoded_input.hpp \
66-
tests/../string.hpp tests/../source_line.hpp tests/../decoder.hpp \
67-
tests/../diagnostic.hpp tests/../messages.hpp \
68-
tests/../magic_comment.hpp tests/../nodes.hpp \
69-
tests/../parser_options.hpp tests/../token_rewriter.hpp \
70-
tests/../token.hpp tests/../token_ids.hpp \
71-
tests/../shared_byte_list.hpp tests/../parser_result.hpp \
72-
tests/../api.hpp
55+
token_ids.hpp shared_byte_list.hpp utils.hpp
56+
57+
tests/runner: tests/runner.cpp tests/test_helper.hpp \
58+
tests/test_helper.cpp tests/bytes_test.cpp bytes.hpp \
59+
utils.hpp tests/comment_test.cpp comment.hpp \
60+
loc.hpp decoded_input.hpp string.hpp \
61+
source_line.hpp tests/decoded_input_test.cpp \
62+
tests/decoder_test.cpp decoder.hpp tests/diagnostic_test.cpp \
63+
diagnostic.hpp messages.hpp tests/loc_test.cpp \
64+
tests/magic_comment_test.cpp magic_comment.hpp \
65+
tests/messages_test.cpp tests/nodes_test.cpp nodes.hpp \
66+
tests/parser_options_test.cpp parser_options.hpp \
67+
token_rewriter.hpp token.hpp token_ids.hpp \
68+
shared_byte_list.hpp tests/parser_result_test.cpp \
69+
parser_result.hpp tests/shared_byte_list_test.cpp \
70+
tests/source_line_test.cpp tests/string_test.cpp \
71+
tests/token_rewriter_test.cpp tests/token_test.cpp tests/api_test.cpp \
72+
api.hpp
7373

7474
benchmark/cpp-parser: benchmark/benchmark.cpp benchmark/rb_filelist.hpp \
7575
benchmark/../lib-ruby-parser.hpp

.github/workflows/release.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ jobs:
5757
uses: actions/checkout@v2
5858

5959
- name: codegen
60-
env:
61-
RUSTFLAGS: ""
62-
run: |
63-
make do-codegen
64-
make token_ids.hpp
60+
run: make do-codegen
6561

6662
- name: make lib file
6763
run: |

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ jobs:
8787
uses: actions/checkout@v2
8888

8989
- name: codegen
90-
env:
91-
RUSTFLAGS: ""
92-
run: |
93-
make do-codegen
94-
make token_ids.hpp
90+
run: make do-codegen
9591

9692
- name: run tests
9793
run: ${{ matrix.build.run }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ messages.cpp
99
nodes.hpp
1010
nodes.cpp
1111
token_ids.hpp
12+
tests/messages_test.cpp
13+
tests/nodes_test.cpp
1214
target
1315
*.o
1416
*.a
@@ -23,3 +25,5 @@ benchmark/filelist
2325
benchmark/stats
2426
*.benchmark-out
2527
docs/
28+
codegen/codegen
29+
codegen/merge-headers

Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ SOURCES = \
1919
shared_byte_list \
2020
source_line \
2121
string \
22-
token \
23-
token_rewriter
24-
25-
ifeq ($(BUILD_ENV), debug)
26-
SOURCES += test_helper
27-
endif
22+
token_rewriter \
23+
token
2824

2925
CPP_FILES = $(foreach source,$(SOURCES),$(source).cpp)
3026
HPP_FILES = $(foreach source,$(SOURCES),$(source).hpp)
27+
HPP_FILES += token_ids.hpp
3128
O_FILES = $(foreach source,$(SOURCES),$(source).$(O))
3229
STATIC_LIB = libruby_parser_cpp.$(A)
3330

@@ -64,6 +61,6 @@ clean:
6461
rm -f *.$(A)
6562
rm -rf *.dSYM
6663

67-
doxygen: messages.hpp nodes.hpp token_ids.hpp
64+
doxygen: $(CODEGEN_FILES)
6865
rm -rf docs
6966
doxygen

codegen/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

codegen/build.mk

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,85 @@
1-
CODEGEN_DEPS = $(wildcard codegen/codegen/*.rs)
2-
CODEGEN_DEPS += codegen/Cargo.toml
3-
CODEGEN_DEPS += codegen/build.rs
1+
define download_file
2+
URL="$(1)" SAVE_AS="$(2)" ruby scripts/download_file.rb
3+
endef
44

5-
DO_CODEGEN = cd codegen && touch build.rs && cargo build
5+
CODEGEN_EXE = codegen/codegen$(EXE)
6+
$(CODEGEN_EXE):
7+
$(call download_file, https://github.com/lib-ruby-parser/lib-ruby-parser/releases/download/v4.0.2+ruby-3.1.1/codegen-$(TARGET)$(EXE), $@)
8+
chmod +x $(CODEGEN_EXE)
9+
CLEAN += $(CODEGEN_EXE)
610

711
# Codegen deps
8-
messages.cpp: $(CODEGEN_DEPS)
9-
$(DO_CODEGEN)
10-
CLEAN += messages.cpp
12+
tests/messages_test.cpp: codegen/messages_test.cpp.liquid $(CODEGEN_EXE)
13+
$(CODEGEN_EXE) --template $< --write-to $@
14+
CLEAN += tests/messages_test.cpp
15+
CODEGEN_FILES += tests/messages_test.cpp
1116

12-
messages.hpp: $(CODEGEN_DEPS)
13-
$(DO_CODEGEN)
17+
messages.hpp: codegen/messages.hpp.liquid $(CODEGEN_EXE)
18+
$(CODEGEN_EXE) --template $< --write-to $@
1419
CLEAN += messages.hpp
20+
CODEGEN_FILES += messages.hpp
1521

16-
nodes.cpp: $(CODEGEN_DEPS)
17-
$(DO_CODEGEN)
18-
CLEAN += nodes.cpp
22+
messages.cpp: codegen/messages.cpp.liquid $(CODEGEN_EXE)
23+
$(CODEGEN_EXE) --template $< --write-to $@
24+
CLEAN += messages.cpp
25+
CODEGEN_FILES += messages.cpp
1926

20-
nodes.hpp: $(CODEGEN_DEPS)
21-
$(DO_CODEGEN)
27+
tests/nodes_test.cpp: codegen/nodes_test.cpp.liquid $(CODEGEN_EXE)
28+
$(CODEGEN_EXE) --template $< --write-to $@
29+
CLEAN += tests/nodes_test.cpp
30+
CODEGEN_FILES += tests/nodes_test.cpp
31+
32+
nodes.hpp: codegen/nodes.hpp.liquid $(CODEGEN_EXE)
33+
$(CODEGEN_EXE) --template $< --write-to $@
2234
CLEAN += nodes.hpp
35+
CODEGEN_FILES += nodes.hpp
36+
37+
nodes.cpp: codegen/nodes.cpp.liquid $(CODEGEN_EXE)
38+
$(CODEGEN_EXE) --template $< --write-to $@
39+
CLEAN += nodes.cpp
40+
CODEGEN_FILES += nodes.cpp
2341

24-
ruby-parser-cpp/src/node.rs: $(CODEGEN_DEPS)
25-
$(DO_CODEGEN)
42+
ruby-parser-cpp/src/node.rs: codegen/nodes.rs.liquid $(CODEGEN_EXE)
43+
$(CODEGEN_EXE) --template $< --write-to $@
2644
CLEAN += ruby-parser-cpp/src/node.rs
45+
CODEGEN_FILES += ruby-parser-cpp/src/node.rs
2746

28-
ruby-parser-cpp/src/message.rs: $(CODEGEN_DEPS)
29-
$(DO_CODEGEN)
47+
ruby-parser-cpp/src/message.rs: codegen/messages.rs.liquid $(CODEGEN_EXE)
48+
$(CODEGEN_EXE) --template $< --write-to $@
3049
CLEAN += ruby-parser-cpp/src/message.rs
50+
CODEGEN_FILES += ruby-parser-cpp/src/message.rs
3151

32-
# token_id.hpp codegen
33-
DO_CODEGEN_TOKEN_IDS = cargo run --example build_token_ids --manifest-path codegen/Cargo.toml
34-
35-
token_ids.hpp: codegen/examples/build_token_ids.rs
36-
$(DO_CODEGEN_TOKEN_IDS)
52+
token_ids.hpp: codegen/token_ids.hpp.liquid $(CODEGEN_EXE)
53+
$(CODEGEN_EXE) --template $< --write-to $@
3754
CLEAN += token_ids.hpp
38-
update-depend: token_ids.hpp
55+
CODEGEN_FILES += token_ids.hpp
56+
57+
codegen/merge-headers:
58+
wget -q https://github.com/iliabylich/merge_headers/releases/download/v1.0.0/merge-headers-$(TARGET) -O codegen/merge-headers
59+
chmod +x codegen/merge-headers
60+
CLEAN += codegen/merge-headers
61+
62+
# A literal space.
63+
space :=
64+
space +=
65+
66+
# Joins elements of the list in arg 2 with the given separator.
67+
# 1. Element separator.
68+
# 2. The list.
69+
join-with = $(subst $(space),$1,$(strip $2))
3970

4071
# lib-ruby-parser.hpp codegen
41-
lib-ruby-parser.hpp: codegen/examples/merge_headers.rs $(HPP_FILES) token_ids.hpp
42-
cargo run --example merge_headers --manifest-path codegen/Cargo.toml
72+
lib-ruby-parser.hpp: codegen/merge-headers $(HPP_FILES)
73+
./codegen/merge-headers \
74+
--cc $(CXX) \
75+
--headers "$(call join-with,;,$(HPP_FILES))" \
76+
--write-to lib-ruby-parser.hpp \
77+
--include-guard-prefix LIB_RUBY_PARSER_ \
78+
--output-guard LIB_RUBY_PARSER_H
79+
4380
CLEAN += lib-ruby-parser.hpp
4481
update-depend: lib-ruby-parser.hpp
4582

46-
# manual codegen task
47-
do-codegen:
48-
$(DO_CODEGEN)
83+
do-codegen: $(CODEGEN_FILES)
84+
85+
.PHONY: do-codegen

codegen/build.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

codegen/codegen/mod.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)