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 46 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
17 changes: 11 additions & 6 deletions .github/workflows/brgen-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
path: /tmp/brgen
- name: Install Dependencies
run: sudo apt-get install jq libc++-dev ninja-build -y
- name: Run Brgen and Test
- name: Run Brgen
run: |
chmod -R +x /tmp/brgen
cd /tmp/brgen
Expand All @@ -35,9 +35,14 @@ jobs:
ldd /tmp/brgen/tool/libfutils.so
/tmp/brgen/tool/src2json --version
/tmp/brgen/tool/brgen -debug
- name: Clone Utils
run: |
cd /tmp/brgen
git clone https://github.com/on-keyday/utils.git
cd utils
. build shared Debug futils
cd ..
export FUTILS_DIR=/tmp/brgen/utils
# ./make_cpp_tests.sh ./ignore/example/test_info.json run
mkdir utils/lib
cp tool/libfutils.so utils/lib
- name: Test
run: |
cd /tmp/brgen
. ./link_path.sh
FUTILS_DIR=/tmp/brgen/utils tool/cmptest -f ignore/example/test_info.json -c testkit/cmptest.json
21 changes: 19 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,30 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Ninja
uses: seanmiddleditch/gha-setup-ninja@8b297075da4cd2a5f1fd21fe011b499edf06e9d2 # master
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ">=1.20"
- name: Install Homebrew Clang
run: |
brew install llvm

- name: Check Code
run: |
PREFIX=$(brew --prefix llvm)
# from https://github.com/llvm/llvm-project/issues/77786
LIBCPP=$PREFIX/lib/c++
ls $LIBCPP
echo "libc++"
nm $LIBCPP/libc++.1.dylib | c++filt
echo "libc++abi"
nm $LIBCPP/libc++abi.1.dylib | c++filt
- name: Build
run: |
export FUTILS_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++
export FUTILS_C_COMPILER=/usr/local/opt/llvm/bin/clang
PREFIX=$(brew --prefix llvm)
export FUTILS_CXX_COMPILER=$PREFIX/bin/clang++
export FUTILS_C_COMPILER=$PREFIX/bin/clang
export LDFLAGS="-L$PREFIX/lib/c++ -Wl,-rpath,$PREFIX/lib/c++"
. build.sh native Release
./tool/src2json --version
- name: Pack artifacts
Expand Down
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/
15 changes: 3 additions & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,10 @@
"name": "Debug json2cpp",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/tool/json2cpp2",
"program": "${workspaceRoot}/tool/json2ts",
"args": [
"<",
"ignore/request.bin",
">",
"ignore/response.bin",
//"ignore/sample.json",
//"-f",
/*"-r",
"--call", "Test2.decode",
"--binary","example/vm_test/varint.dat",
"--hex",
*/
"-f",
"./ignore/sample.json",
],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
Expand Down
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",
".\\src\\tool\\cmptest\\Cargo.toml",
],
"brgen-lsp.src2json" :"./tool/src2json.exe",
//"go.buildTags": "linux",
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
endif()
endif()




set(CMAKE_CXX_STANDARD 20)


Expand Down
98 changes: 91 additions & 7 deletions ast2go/request/response.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
package request

import "io"
import (
"fmt"
"io"
"runtime/debug"
)

type RequestStream struct {
r io.Reader
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 +38,77 @@ func (rs *RequestStream) Receive() (*GenerateSource, error) {
return src, nil
}

func (rs *RequestStream) Respond(src *SourceCode) error {
enc, err := src.Encode()
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,
}
resp.SetEnd(EndOfCode{ID: id})
enc := resp.MustEncode()
_, err := rs.w.Write(enc)
return err
}

type IDStream struct {
rs *RequestStream
id uint64
}

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

func (rs *IDStream) RespondError(err string) error {
return rs.rs.RespondError(rs.id, err)
}

func Run(r io.Reader, w io.Writer, cb func(s *IDStream, req *GenerateSource)) error {
stream, err := NewRequestStream(r, w)
if err != nil {
return err
}
_, err = rs.w.Write(enc)
return err
for {
req, err := stream.Receive()
if err != nil {
break
}
go func() {
defer stream.RespondEnd(req.ID)
defer func() {
if r := recover(); r != nil {
trace := debug.Stack()
stream.RespondError(req.ID, fmt.Sprintf("%v\n%s", r, trace))
}
}()
cb(&IDStream{
stream,
req.ID,
}, req)
}()
}
return nil
}
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
20 changes: 13 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash
# TODO(on-keyday): on macos, S2J_LIB=1 is not work well, so not set S2J_LIB
if [ "$(uname)" != "Darwin" ]; then
export S2J_LIB=1
if [ "$(uname)" == "Darwin" ]; then
export S2J_LIB=0
else
export S2J_LIB=1
fi


export BRGEN_RUST_ENABLED=1

BUILD_MODE=$1
BUILD_TYPE=$2

Expand Down Expand Up @@ -48,16 +53,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 +73,4 @@ fi
unset FUTILS_DIR
unset BUILD_MODE
unset S2J_LIB
unset BRGEN_RUST_ENABLED
20 changes: 20 additions & 0 deletions example/fs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,24 @@ enum Type {
// others are reserved
experimental_1 = 253,
experimental_2 = 255,
};

enum OS {
fat = 0,
amiga = 1,
vms = 2,
unix_ = 3,
vm_cms = 4,
atari = 5,
hpfs = 6,
machintosh = 7,
z_system = 8,
cp_m = 9,
tops_20 = 10,
ntfs = 11,
qdos = 12,
acorn_risc_os = 13,
vfat = 14,
mvs = 15,
beos = 16,
};
60 changes: 60 additions & 0 deletions example/gzip.bgn
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
config.url = "https://www.rfc-editor.org/rfc/rfc1952"
input.endian = config.endian.little
input.bit_order = config.bit_order.lsb

format GZipHeader:
magic :"\x1f\x8b"
method :CompressionMethod
flags :GZipFlag
mtime :u32
xfl :u8
os :OS
if flags.extra ==1:
extra :GZipExtra
if flags.fname ==1:
fname :CString
if flags.fcomment ==1:
fcomment :CString
if flags.crc ==1:
crc16 :u16

format GZipExtra:
xlen :u16
data :[xlen]u8

format CString:
data :[..]u8
:"\x00"

format GZipFlag:
text :u1
crc :u1
extra :u1
fname :u1
fcomment :u1
reserved :u3
reserved == 0

enum CompressionMethod:
:u8
deflate = 8

enum OS:
:u8
fat = 0
amiga = 1
vms = 2
unix_ = 3
vm_cms = 4
atari = 5
hpfs = 6
machintosh = 7
z_system = 8
cp_m = 9
tops_20 = 10
ntfs = 11
qdos = 12
acorn_risc_os = 13
vfat = 14
mvs = 15
beos = 16
Loading
Loading