Packages
gpb
4.21.7
5.0.0
4.21.7
4.21.6
4.21.5
4.21.4
4.21.3
4.21.2
4.21.1
4.21.0
4.20.0
4.19.9
4.19.8
4.19.7
4.19.6
4.19.5
4.19.4
4.19.3
4.19.2
4.19.1
4.19.0
4.18.0
4.17.7
4.17.6
4.17.5
4.17.3
4.17.2
4.17.1
4.17.0
4.16.2
4.16.1
4.16.0
4.15.2
4.15.1
4.14.2
4.14.1
4.14.0
4.13.0
4.12.0
4.11.2
4.11.1
4.11.0
4.10.6
4.10.5
4.10.4
4.10.3
4.10.2
4.10.1
4.10.0
4.9.3
4.9.2
4.9.1
4.9.0
4.8.0
4.7.3
4.7.2
4.7.1
4.7.0
4.6.0
4.5.1
4.5.0
4.4.1
4.4.0
4.3.3
4.3.2
4.3.1
4.3.0
4.2.3
4.2.2
4.2.1
4.2.0
4.1.9
4.1.8
4.1.7
4.1.6
4.1.5
4.1.4
4.1.3
4.1.2
4.1.1
4.1.0
4.0.2
4.0.1
4.0.0
3.28.1
3.28.0
3.27.7
3.27.6
3.27.5
3.27.4
3.27.3
3.27.2
3.27.1
3.27.0
3.26.8
3.26.7
3.26.6
3.26.5
3.26.4
3.26.3
3.26.2
3.26.1
3.26.0
3.25.2
3.25.1
3.25.0
3.24.4
3.24.3
3.24.2
3.24.1
3.24.0
3.23.2
3.23.1
3.23.0
3.22.5
3.22.4
3.22.3
3.22.2
3.22.1
3.22.0
3.21.3
3.21.2
3.21.1
3.21.0
3.20.3
3.20.2
3.20.0
3.19.0
3.18.10
3.18.9
3.18.8
3.18.7
3.18.6
3.18.5
3.18.4
3.18.3
3.18.2
3.18.1
3.18.0
3.17.13
3.17.12
3.17.11
3.17.10
3.17.9
3.17.8
3.17.5
3.17.4
3.17.3
3.17.2
3.17.1
3.17.0
3.16.0
3.15.0
3.14.0
3.13.0
3.12.2
3.12.1
3.12.0
3.11.0
A compiler for Google protocol buffer definitions files for Erlang.
Current section
Files
Jump to
Current section
Files
build/compile_descriptor
#!/usr/bin/env escript
%% -*- erlang -*-
-include_lib("kernel/include/file.hrl").
is_up_to_date(Target, Deps) ->
case file:read_file_info(Target) of
{ok, #file_info{mtime = TargetMTime}} ->
lists:all(fun(Dep) ->
case file:read_file_info(Dep) of
{ok, #file_info{mtime = MTime}} ->
MTime =< TargetMTime;
_ ->
false
end
end, Deps);
_ ->
false
end.
make_target(Target, Deps, CmdFun) ->
case is_up_to_date(Target, Deps) of
true ->
ok;
_ ->
io:format("Compiling ~s...~n", [filename:basename(hd(Deps))]),
CmdFun()
end.
make(Makescript) ->
lists:foreach(
fun({Target, Deps, CmdFun}) -> make_target(Target, Deps, CmdFun) end,
Makescript).
gpb_compile_file_cmd(Proto, Opts) ->
fun() ->
check_ok_or_halt(gpb_compile:file(Proto, Opts))
end.
compile_file_cmd(Erl, Opts) ->
fun() ->
check_ok_or_halt(compile:file(Erl, Opts))
end.
check_ok_or_halt(Res) ->
if Res =:= ok -> ok;
element(1, Res) =:= ok -> ok;
true -> halt(1)
end.
deps_dir() ->
case os:getenv("REBAR_DEPS_DIR") of
false ->
%% Elixir 1.12+
os:getenv("REBAR_BARE_COMPILER_OUTPUT_DIR");
DepsDir ->
DepsDir
end.
checkouts_out_dir() ->
os:getenv("REBAR_CHECKOUTS_OUT_DIR").
gpb_exists_via_env(DirEnvValue) ->
if DirEnvValue == false ->
false;
is_list(DirEnvValue) ->
filelib:is_dir(filename:join(DirEnvValue, "gpb"))
end.
main(_) ->
REBAR_CHECKOUTS_OUT_DIR = checkouts_out_dir(),
REBAR_DEPS_DIR = deps_dir(),
GpbExistsInCheckoutsOutDir = gpb_exists_via_env(REBAR_CHECKOUTS_OUT_DIR),
GpbExistsInDepsDir = gpb_exists_via_env(REBAR_DEPS_DIR),
{EbinPath, TestPath} =
if GpbExistsInCheckoutsOutDir ->
%% With _checkouts and rebar3 3.14 or later
{filename:join([REBAR_CHECKOUTS_OUT_DIR, "gpb", "ebin"]),
filename:join([REBAR_CHECKOUTS_OUT_DIR, "gpb", "test"])};
GpbExistsInDepsDir ->
{filename:join([REBAR_DEPS_DIR, "gpb", "ebin"]),
filename:join([REBAR_DEPS_DIR, "gpb", "test"])};
true ->
%% rebar2 (or make)
{"./ebin", "./test"}
end,
filelib:ensure_dir(filename:join(EbinPath, ".dummy")),
GpbcOpts = [{i, "priv/proto3/google/protobuf"},
{o, "descr_src"}, {module_name_prefix, "gpb_"},
report],
ErlcOpts = [{i, "descr_src"}, {i,"include"},
{outdir, EbinPath}, debug_info,
report],
code:add_patha(EbinPath),
MakeScript =
[{"descr_src/gpb_descriptor.erl",
["priv/proto3/google/protobuf/descriptor.proto"],
gpb_compile_file_cmd("descriptor.proto", GpbcOpts)},
{filename:join(EbinPath, "gpb_descriptor.beam"),
["descr_src/gpb_descriptor.erl"],
compile_file_cmd("descr_src/gpb_descriptor.erl", ErlcOpts)},
{filename:join(EbinPath, "gpb_compile_descr.beam"),
["descr_src/gpb_compile_descr.erl",
"descr_src/gpb_descriptor.hrl"],
compile_file_cmd("descr_src/gpb_compile_descr.erl", ErlcOpts)},
{filename:join(EbinPath, "gpb_parse_descr.beam"),
["descr_src/gpb_parse_descr.erl",
"descr_src/gpb_descriptor.hrl"],
compile_file_cmd("descr_src/gpb_parse_descr.erl", ErlcOpts)}],
make(MakeScript),
case filelib:is_dir(TestPath) of
true ->
%% eg: "rebar3 eunit" or "rebar2 eunit"
%% but not "rebar3 compile"
%% and not when compiling gpb as a dependency, since
%% the test directory does not exist in the hex package.
ErlcTestOpts = [{i, "descr_src"}, {i, "include"},
{outdir, TestPath}, debug_info],
TestMakeScript =
[{filename:join(TestPath, "gpb_compile_descr_tests.beam"),
["descr_src/gpb_compile_descr_tests.erl",
"descr_src/gpb_compile_descr.erl",
"descr_src/gpb_descriptor.hrl"],
compile_file_cmd("descr_src/gpb_compile_descr_tests.erl",
ErlcTestOpts)},
{filename:join(TestPath, "gpb_parse_descr_tests.beam"),
["descr_src/gpb_parse_descr_tests.erl",
"descr_src/gpb_parse_descr.erl",
"descr_src/gpb_descriptor.hrl"],
compile_file_cmd("descr_src/gpb_parse_descr_tests.erl",
ErlcTestOpts)}],
make(TestMakeScript);
_ ->
next
end.