Skip to content

Commit

Permalink
optimization of build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanallen committed Sep 24, 2024
1 parent 4c5b032 commit 6344c2a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.xmake
build
.vscode
work
output
.gdb_history
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,38 @@ A distributed storage system.

## Build

- Config your project with debug mode.

```py
./pain.py config -m debug
```
./build.py config -m debug

- Build

```py
# build and install to ${PROJECT_DIR}/output
./build.py build --install
./pain.py build -i/--install
```

# only build
./build.py build
- More commands

```
# build without install
./pain.py build
# only build sad target
./build.py build sad
./pain.py build sad
# format your project and it's useful before pulling a request
./pain.py format
```

Using `./build.py -h` for more information.
Using `./pain.py -h` for more information.

## Trace

Pain supports opentelemetry. You can install jaeger using follow command.

```
docker run --rm \
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
Expand All @@ -41,17 +56,17 @@ docker run --rm \
## SDK Examples

```c++
#include "pain/pain.h"
#include "spdlog/spdlog.h"
#include <pain/pain.h>

int main() {
spdlog::set_level(spdlog::level::debug);
auto fs = pain::FileSystem::create("list://192.168.10.1:8001,192.168.10.2:8001,192.168.10.3:8001");
auto file = fs->open("/tmp/hello.txt", O_CREAT | O_WRONLY);
pain::core::FileService::Stub stub(file.get());
pain::Controller cntl;
pain::core::AppendRequest request;
pain::core::AppendResponse response;

request.set_direct_io(true);
cntl.request_attachment().append("hello world");
stub.append(&cntl, &request, &response, nullptr);
if (cntl.Failed()) {
Expand Down
32 changes: 19 additions & 13 deletions build.py → pain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,43 @@ def build_project(args):
run_in_shell('xmake install -o output')
pass

def format_project():
def format_project(args):
run_in_shell('xmake format -f "src/**.h:src/**.cc:protocols/**.proto:include/**.h"')
run_in_shell('git --no-pager diff')

def line_project():
def line_project(args):
run_in_shell('find include src -iname "*.h" -o -iname "*.cc" | xargs wc -l')

def main(args):
if args.subparser_name == 'format':
format_project()
elif args.subparser_name == 'build':
build_project(args)
elif args.subparser_name == 'line':
line_project()
def install_project(args):
if not args.rest:
run_in_shell('xmake install -o output')
return
for target in args.rest:
run_in_shell('xmake install -o output {}'.format(target))


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Description of your program')
parser.add_argument('-g', '--global')
subparsers = parser.add_subparsers(dest="subparser_name", required=True)
format_parser = subparsers.add_parser('format')
format_parser = subparsers.add_parser('format', aliases=['f'])
format_parser.set_defaults(func=format_project)

config_parser = subparsers.add_parser('config')
config_parser.set_defaults(func=config_project)
config_parser.add_argument('-c', '--clean', action='store_true')
config_parser.add_argument('-m', '--mode', default='debug', choices=['debug', 'releasedbg'])

build_parser = subparsers.add_parser('build')
build_parser = subparsers.add_parser('build', aliases=['b'])
build_parser.set_defaults(func=build_project)
build_parser.add_argument('-i', '--install', action='store_true')
build_parser.add_argument('rest', nargs=argparse.REMAINDER)

line_parser = subparsers.add_parser('line')
line_parser.set_defaults(func=line_project)

install_parser = subparsers.add_parser('install')
install_parser.set_defaults(func=install_project)
install_parser.add_argument('rest', nargs=argparse.REMAINDER)

args = parser.parse_args()
main(args)
args.func(args)
3 changes: 3 additions & 0 deletions protocols/pain/core/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ target("core")
add_files("*.proto", {proto_rootdir = "protocols", proto_public = true})
add_rules("protobuf.cpp")
add_packages("protobuf-cpp", {public = true})
on_load(function (target)
target:add("headerfiles", path.join(target:autogendir(), "rules/protobuf/protocols/(pain/core/*.pb.h)"))
end)
2 changes: 2 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ add_includedirs("src")

includes("src")
includes("protocols/pain/core")

add_headerfiles("include/(pain/*.h)")

0 comments on commit 6344c2a

Please sign in to comment.