Skip to content

Commit

Permalink
fix BUILD_DATE generation
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rubio committed Feb 25, 2017
1 parent 30c90dc commit 9bf5633
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -7,6 +7,7 @@ clean-devel: clean
-rm -rf _build

clean:
-rm -f .build_date
./rebar3 clean

compile:
Expand All @@ -16,14 +17,17 @@ test:
./rebar3 xref
./rebar3 eunit
./rebar3 cover
./covertool -cover _build/test/cover/eunit.coverdata -appname ephp -output cobertura.xml
./covertool \
-cover _build/test/cover/eunit.coverdata \
-appname ephp \
-output cobertura.xml

ephp: compile
./rebar3 escriptize
cp -f _build/default/bin/ephp .
-rm -f .build_date

shell:
./rebar3 shell

.PHONY: doc test compile all shell

21 changes: 12 additions & 9 deletions rebar.config.script
@@ -1,9 +1,12 @@
ErlOpts = proplists:get_value(erl_opts, CONFIG),
case lists:filter(fun({d, 'BUILD_DATE', _}) -> true; (_) -> false end, ErlOpts) of
[] ->
OldErlOpts = [{erl_opts, ErlOpts}],
NewErlOpts = [{erl_opts, [{d, 'BUILD_DATE', {date(), time()}}|ErlOpts]}],
(CONFIG -- OldErlOpts) ++ NewErlOpts;
[_] ->
CONFIG
end.
case filelib:is_regular(".build_date") of
true -> ok;
false -> os:cmd("LANG=POSIX date '+%b %d %Y %T' > .build_date")
end,
BuildDate = binary_to_list(element(2,file:read_file(".build_date"))),
ErlOpts = lists:filter(fun
({d, 'BUILD_DATE', _}) -> false;
(_) -> true
end, proplists:get_value(erl_opts, CONFIG)),
OldErlOpts = [{erl_opts, ErlOpts}],
NewErlOpts = [{erl_opts, [{d, 'BUILD_DATE', BuildDate}|ErlOpts]}],
(CONFIG -- OldErlOpts) ++ NewErlOpts.
12 changes: 1 addition & 11 deletions src/ephp_lib_info.erl
Expand Up @@ -93,14 +93,4 @@ get_vsn() ->
-spec get_build_date() -> binary().

get_build_date() ->
{{Y,M,D},{H,I,S}} = ?BUILD_DATE,
Month = ephp_datetime:get_abbr_month(M),
Day = ephp_data:pad_to_bin(D,2),
Year = integer_to_binary(Y),
Hour = ephp_data:pad_to_bin(H,2),
Min = ephp_data:pad_to_bin(I,2),
Sec = ephp_data:pad_to_bin(S,2),
<<
Month/binary, " ", Day/binary, " ", Year/binary, " ",
Hour/binary, ":", Min/binary, ":", Sec/binary
>>.
list_to_binary(?BUILD_DATE).

0 comments on commit 9bf5633

Please sign in to comment.