build: do not allow user override PKG_VSN

We have an assertion in code, allowing user to override
will compile but not run.
This commit is contained in:
Zaiming Shi 2021-06-22 11:34:53 +02:00 committed by zhanghongtong
parent cd5431e71d
commit 871f23f047
3 changed files with 10 additions and 13 deletions

View File

@ -122,7 +122,14 @@ get_release() ->
release_in_macro();
{_, Vsn} -> %% For emqx release build
VsnStr = release_in_macro(),
1 = string:str(Vsn, VsnStr), %% assert
case string:str(Vsn, VsnStr) of
1 -> ok;
_ ->
erlang:error(#{ reason => version_mismatch
, source => VsnStr
, built_for => Vsn
})
end,
Vsn
end.

2
build
View File

@ -12,7 +12,7 @@ ARTIFACT="$2"
# ensure dir
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}"
PKG_VSN="$(./pkg-vsn.sh)"
export PKG_VSN
if [ "$(uname -s)" = 'Darwin' ]; then

View File

@ -413,18 +413,8 @@ find_conf_files(App) ->
false -> []
end.
env(Name, Default) ->
case os:getenv(Name) of
"" -> Default;
false -> Default;
Value -> Value
end.
get_vsn() ->
PkgVsn = case env("PKG_VSN", false) of
false -> os:cmd("./pkg-vsn.sh");
Vsn -> Vsn
end,
PkgVsn = os:cmd("./pkg-vsn.sh"),
re:replace(PkgVsn, "\n", "", [{return ,list}]).
maybe_dump(Config) ->