Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成コードテスト用ツールの作成とCIへの組み込み #81

Merged
merged 52 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
4f47a83
adding test utility
on-keyday Apr 24, 2024
1bc0578
adding schema
on-keyday Apr 24, 2024
bfc8e01
adding testutil
on-keyday Apr 24, 2024
764310d
adding
on-keyday Apr 24, 2024
f8b8c6d
add test util
on-keyday Apr 25, 2024
428035b
fix typo
on-keyday Apr 25, 2024
979e812
add golang stdin_stream
on-keyday Apr 25, 2024
5f5f3ba
fix
on-keyday Apr 25, 2024
1145d65
fix json2mermaid lib
on-keyday Apr 25, 2024
aae2b07
move into tool
on-keyday Apr 25, 2024
53226cd
add gzip
on-keyday Apr 25, 2024
c03f2ae
try fuse-ld=lld
on-keyday Apr 25, 2024
9b0246a
fix macos-latest install path for latest update
on-keyday Apr 25, 2024
6681a5d
setup go for mac
on-keyday Apr 25, 2024
61a8ccb
try again
on-keyday Apr 25, 2024
5117c21
how to fix?
on-keyday Apr 26, 2024
38b35c0
fix
on-keyday Apr 26, 2024
ec14c4e
add LDFLAGS for mac
on-keyday Apr 26, 2024
c1c31be
adding typeinfo inspection
on-keyday Apr 26, 2024
d77cbeb
fix?
on-keyday Apr 26, 2024
84b1344
fixing
on-keyday Apr 26, 2024
4a06467
fix?
on-keyday Apr 26, 2024
8fc606e
add cmptest util schema
on-keyday Apr 26, 2024
c06054a
add cmptest.json
on-keyday Apr 26, 2024
824225e
fixing test
on-keyday Apr 26, 2024
a64dfa2
c++filt
on-keyday Apr 26, 2024
0fc3715
testing
on-keyday Apr 26, 2024
be214b6
echo
on-keyday Apr 26, 2024
edbe94b
fix
on-keyday Apr 26, 2024
00fc5f3
fix
on-keyday Apr 26, 2024
45c328a
fix!
on-keyday Apr 26, 2024
47afa93
fix!
on-keyday Apr 26, 2024
f5a2b6f
generate config
on-keyday Apr 28, 2024
4c5c6e3
remove needless suffix
on-keyday Apr 28, 2024
e5e2726
can build on windows test
on-keyday Apr 28, 2024
2f78928
add cmptest
on-keyday Apr 28, 2024
b12866d
fix forgotten env
on-keyday Apr 28, 2024
dafdbde
fix
on-keyday Apr 28, 2024
9acfd1c
fix
on-keyday Apr 28, 2024
958fd6b
remove needless linker
on-keyday Apr 28, 2024
207cff8
use libc++ for test
on-keyday Apr 29, 2024
8fef25f
fix parser bug
on-keyday Apr 29, 2024
6bf9f98
fix ts generation
on-keyday Apr 29, 2024
9b744c7
add formats
on-keyday Apr 29, 2024
6fd5e13
add ts string convertion of enum
on-keyday Apr 29, 2024
c3ddf09
fix
on-keyday Apr 29, 2024
5289e91
fix
on-keyday Apr 29, 2024
18f6437
fix
on-keyday Apr 29, 2024
f91c098
fix
on-keyday Apr 29, 2024
40debff
Merge branch 'main' into test/test_enhancement
on-keyday Apr 29, 2024
1e26439
fix
on-keyday Apr 29, 2024
a4e2e19
Merge branch 'test/test_enhancement' of github.com:on-keyday/brgen in…
on-keyday Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ go_dump_env.bat
license_cache
pkg/
stats.json
zig-cache/
zig-out/
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
".\\ast2rust\\Cargo.toml",
".\\src\\tool\\json2rust\\Cargo.toml",
".\\src\\tool\\json2llvm\\Cargo.toml",
".\\testutil\\Cargo.toml",
],
"brgen-lsp.src2json" :"./tool/src2json.exe",
//"go.buildTags": "linux",
Expand Down
54 changes: 47 additions & 7 deletions ast2go/request/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ type RequestStream struct {
w io.Writer
}

func NewRequestStream(r io.Reader, w io.Writer) *RequestStream {
return &RequestStream{r: r, w: w}
func NewRequestStream(r io.Reader, w io.Writer) (*RequestStream, error) {
h := &RequestStream{r: r, w: w}
if err := h.handshake(); err != nil {
return nil, err
}
return h, nil
}

func (rs *RequestStream) handshake() error {
resp := &GeneratorResponseHeader{Version: 1}
enc := resp.MustEncode()
if _, err := rs.w.Write(enc); err != nil {
return err
}
hdr := &GeneratorRequestHeader{}
return hdr.Read(rs.r)
}

func (rs *RequestStream) Receive() (*GenerateSource, error) {
Expand All @@ -20,11 +34,37 @@ func (rs *RequestStream) Receive() (*GenerateSource, error) {
return src, nil
}

func (rs *RequestStream) Respond(src *SourceCode) error {
enc, err := src.Encode()
if err != nil {
return err
func (rs *RequestStream) respond(id uint64, status ResponseStatus, name string, code []byte, warn string) error {
src := &SourceCode{
ID: id,
Status: status,
}
src.SetName([]byte(name))
src.SetCode(code)
src.SetErrorMessage([]byte(warn))
resp := &Response{
Type: ResponseType_Code,
}
resp.SetSource(*src)
enc := resp.MustEncode()
_, err := rs.w.Write(enc)
return err
}

func (rs *RequestStream) RespondSource(id uint64, name string, code []byte, warn string) error {
return rs.respond(id, ResponseStatus_Ok, name, code, warn)
}

func (rs *RequestStream) RespondError(id uint64, err string) error {
return rs.respond(id, ResponseStatus_Error, "", nil, err)
}

func (rs *RequestStream) RespondEnd(id uint64) error {
resp := &Response{
Type: ResponseType_EndOfCode,
}
_, err = rs.w.Write(enc)
resp.SetEnd(EndOfCode{ID: id})
enc := resp.MustEncode()
_, err := rs.w.Write(enc)
return err
}
2 changes: 1 addition & 1 deletion brgen.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"args": ["-as-code-block", "-format"]
},
{
"generator": "./src/tool/json2rust/target/debug/json2rust",
"generator": "./tool/json2rust",
"output_dir": "./ignore/example/rust/",
"ignore_missing": true
},
Expand Down
9 changes: 5 additions & 4 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@echo off
setlocal
set S2J_LIB=1
set BRGEN_RUST_ENABLED=1
set BUILD_MODE=%1
set BUILD_TYPE=%2
set FUTILS_DIR=%3
Expand Down Expand Up @@ -41,10 +42,10 @@ rem ninja -C ./built/%BUILD_MODE%/%BUILD_TYPE%
ninja -C ./built/%BUILD_MODE%/%BUILD_TYPE% install

if "%BUILD_MODE%" == "wasm-em" (
cd ./src/tool/json2rust
wasm-pack build --target web
copy ..\..\..\LICENSE .\pkg\LICENSE
cd ../../../
rem cd ./src/tool/json2rust
rem wasm-pack build --target web
rem copy ..\..\..\LICENSE .\pkg\LICENSE
rem cd ../../../
cd ./web/dev
call tsc
call webpack
Expand Down
13 changes: 8 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if [ "$(uname)" != "Darwin" ]; then
export S2J_LIB=1
fi

export BRGEN_RUST_ENABLED=1

BUILD_MODE=$1
BUILD_TYPE=$2

Expand Down Expand Up @@ -48,16 +50,16 @@ if [ $BUILD_MODE = "wasm-em" ];then
else
cmake -D CMAKE_CXX_COMPILER=$CXX_COMPILER -D CMAKE_C_COMPILER=$C_COMPILER -G Ninja -D CMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -D CMAKE_BUILD_TYPE=$BUILD_TYPE -S . -B ./built/$BUILD_MODE/$BUILD_TYPE
fi
ninja -C ./built/$BUILD_MODE/$BUILD_TYPE
#ninja -C ./built/$BUILD_MODE/$BUILD_TYPE
ninja -C ./built/$BUILD_MODE/$BUILD_TYPE install

if [ $BUILD_MODE = "wasm-em" ]; then
unset GOOS
unset GOARCH
cd ./src/tool/json2rust
wasm-pack build --target web
cp ../../../LICENSE ./pkg
cd ../../..
#cd ./src/tool/json2rust
#wasm-pack build --target web
#cp ../../../LICENSE ./pkg
#cd ../../..
cd ./web/dev
tsc
webpack
Expand All @@ -68,3 +70,4 @@ fi
unset FUTILS_DIR
unset BUILD_MODE
unset S2J_LIB
unset BRGEN_RUST_ENABLED
62 changes: 62 additions & 0 deletions spec/brgen_genrated_mapping_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "brgen(BinaRy encoder/decoder GENerator driver) generated file information",
"properties": {
"structs": {
"type": "array",
"description": "List of structs",
"item": {
"type": "string",
"description": "Struct name"
}
},
"line_map": {
"type": "array",
"description": "Line number mappings",
"item": {
"type": "object",
"description": "Line number mapping",
"item": {
"line": {
"type": "integer",
"description": "Line number of generated file"
},
"loc": {
"type": "object",
"description": "Location of source file",
"item": {
"file": {
"type": "integer",
"description": "File index"
},
"line": {
"type": "integer",
"description": "Line number of source file"
},
"col": {
"type": "integer",
"description": "Column number of source file"
},
"pos": {
"type": "object",
"description": "Position of source file",
"item": {
"begin": {
"type": "integer",
"description": "Begin position of source file"
},
"end": {
"type": "integer",
"description": "End position of source file"
}
}
}
}
}
}
}
}
},
"additionalProperties": false
}
2 changes: 1 addition & 1 deletion spec/brgen_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"test_info_output": {
"type": "string",
"description": "Path to the test info output file (default: no output)"
"description": "Path to the test info output file (default: no output). schema is defined in brgen_test_info_schema.json"
},
"warnings": {
"type": "object",
Expand Down
41 changes: 41 additions & 0 deletions spec/brgen_test_info_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "brgen(BinaRy encoder/decoder GENerator driver) output information file schema",
"properties": {
"total_count": {
"type": "integer",
"description": "Total count of output files"
},
"error_count": {
"type": "integer",
"description": "Count of output files with errors"
},
"time": {
"type": "string",
"description": "Time taken to generate output files"
},
"generated_files": {
"type": "array",
"description": "List of generated output files",
"items": {
"type": "object",
"properties": {
"dir": {
"type": "string",
"description": "Directory containing the output file"
},
"base": {
"type": "string",
"description": "Output file name without extension"
},
"suffix": {
"type": "string",
"description": "Output file extension"
}
}
}
}
},
"additionalProperties": false
}
Loading
Loading