Skip to content

Commit

Permalink
Merge branch 'no-unnecessary-overwrite-of-same-gpb_version.hrl'
Browse files Browse the repository at this point in the history
* Avoid unnecessary update of gpb_version.hrl
  when the contents will be the same. This should avoid unnecessary
  recompilations in some setups.
  • Loading branch information
tomas-abrahamsson committed Aug 6, 2023
2 parents a3430a9 + 457dba9 commit 564fea7
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions build/mk_version_hrl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ main(Argv) ->
{<<"@vsn@">>, Vsn},
{<<"@vsn-source@">>, VsnSource},
{<<"is expected to be">>, <<"was">>},
{<<"%% The version below">>, [<<"%% DO NOT EDIT -- generated ">>,
<<"from gpb_version.hrl.in\n%% The version below">>]},
{<<"%% The version below">>,
[<<"%% DO NOT EDIT -- generated from gpb_version.hrl.in\n">>,
<<"%% The version below">>]},
{<<"%% NB: The build.mk_version_hrl depends.*">>, <<"">>}
],
VersionStr = lists:foldl(fun({Patten, Replacement}, Acc) ->
re:replace(Acc, Patten, Replacement, [{return, binary}])
end, BaseStr, SedList),
case file:write_file(OutFile, VersionStr) of
ok ->
Content =
iolist_to_binary(
lists:foldl(
fun({Patten, Replacement}, Acc) ->
re:replace(Acc, Patten, Replacement, [{return, binary}])
end, BaseStr, SedList)),
case file:read_file(OutFile) of
{ok, Content} ->
%% Don't overwrite the file with identical data.
%% This can cause build systems to rebuild unnecessarily.
ok;
{error, Reason2} ->
file_err(write_file, OutFile, Reason2)
_ ->
case file:write_file(OutFile, Content) of
ok ->
ok;
{error, Reason2} ->
file_err(write_file, OutFile, Reason2)
end
end.

parse_opts(["--override-version="++Vsn | Rest], Opts, Args) ->
Expand Down

0 comments on commit 564fea7

Please sign in to comment.