Skip to content

Commit

Permalink
Renamed brod to brod_cli, then created a new shell script named brod.
Browse files Browse the repository at this point in the history
Made it to lookup erts in parent dir, so a user without erts in PATH
can execut `./brod/bin/brod <command> <opts..>` directly instead of
`/brod/bin/erts-*/bin/escript /brod/bin/brod <command> <opts...>`
  • Loading branch information
zmstone committed Nov 22, 2017
1 parent 0acbf85 commit 36af6bb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ cover/
test/*.beam
test/ct.cover.spec
brod.d
scripts/brod
scripts/brod_cli
.brod.plt
.erlang.mk
*.coverdata
ct.coverdata
sys.config
xrefr
brod
brod.plt
_build/
_rel/
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ dep_supervisor3_commit = 1.1.5
dep_kafka_protocol_commit = 1.1.0
dep_docopt = git https://github.com/zmstone/docopt-erl.git 0.1.3

ESCRIPT_FILE = scripts/brod
ERTS_VSN = $(shell erl -noshell -eval 'io:put_chars(erlang:system_info(version)), halt()')
ESCRIPT_FILE = scripts/brod_cli
ESCRIPT_EMU_ARGS = -sname brod_cli

COVER = true
Expand Down Expand Up @@ -44,8 +45,10 @@ app::
include erlang.mk

rel:: escript
cp $(ESCRIPT_FILE) _rel/brod/bin/brod
tar -pczf _rel/brod.tar.gz -C _rel brod
@cp scripts/brod _rel/brod/bin/brod
@cp $(ESCRIPT_FILE) _rel/brod/bin/brod_cli
@ln -sf erts-$(ERTS_VSN) _rel/brod/erts
@tar -pczf _rel/brod.tar.gz -C _rel brod

test-env:
./scripts/setup-test-env.sh
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
- Make group coordinator restart on heartbeat timeout
* 3.3.1
* Fix brod-cli commits command redandunt socket usage.
* 3.?.?
* Enhancements
- Add sh script to wrap brod-cli escript for erts dir auto discover

1 change: 0 additions & 1 deletion scripts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
*.srl
*.p12
*.jks
brod.escript
22 changes: 22 additions & 0 deletions scripts/brod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh -e

# can not readlink -f because mac version readlink does not support -f
LINK="$(readlink "$0")" || true
if [ -z $LINK ]; then
# not a symlink
BINDIR="$(dirname "$0")"
else
# get the link target's dir
BINDIR="$(dirname "$LINK")"
fi

ERTS_BIN="$BINDIR/../erts/bin"

if [ -d "$ERTS_BIN" ]; then
# this is a release, try to use erts in release
exec $ERTS_BIN/escript $BINDIR/brod_cli "$@"
else
# hoping the user has erts in PATH
exec $BINDIR/brod_cli "$@"
fi

9 changes: 0 additions & 9 deletions src/brod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@
, fetch_committed_offsets/3
]).

%% escript
-ifdef(BROD_CLI).
-export([main/1]).
-endif.

-export_type([ call_ref/0
, cg/0
, cg_protocol_type/0
Expand Down Expand Up @@ -692,10 +687,6 @@ fetch_committed_offsets(BootstrapEndpoints, SockOpts, GroupId) ->
fetch_committed_offsets(Client, GroupId) ->
brod_utils:fetch_committed_offsets(Client, GroupId, []).

-ifdef(BROD_CLI).
main(Args) -> brod_cli:main(Args, halt).
-endif.

%%%_* Emacs ====================================================================
%%% Local Variables:
%%% allout-layout: t
Expand Down
4 changes: 3 additions & 1 deletion src/brod_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

-ifdef(BROD_CLI).

-export([main/2]).
-export([main/1, main/2]).

-include("brod_int.hrl").

Expand Down Expand Up @@ -296,6 +296,8 @@ options:

-type command() :: string().

main(Args) -> main(Args, halt).

main(["-h" | _], _Stop) ->
print(?MAIN_DOC);
main(["--help" | _], _Stop) ->
Expand Down

0 comments on commit 36af6bb

Please sign in to comment.