-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OTP-21 support #134
Comments
I would suggest making the decision of implementation at compile time instead of generation time. Otherwise you need to maintain multiple sets of generated files depending on which version you target. |
Ah right, generated erl module are often committed to the repo. |
Is there a preprocessor-only way to check for for OTP version? I can't think of any, not without the help of the build system, but that would mean gpb would need to also generate rebar config scripts, Makefiles etc. I see the point about a compile-time check, but I fear it has wider implications. I have locally a branch with generation time support for the OTP-21 stacktraces. Perhaps worth knowing is that there are already a few other OTP compatibility decisions at generation time in gpb, so the problem is not entirely new. For these decisions, it is possible to specify a target OTP version, and it defaults to the current at generation time. |
Yeah unfortunately there are no macros for it yet. You can check for the default macros with a fake empty module and the following undocumented code:
nothing shows up regarding the compiler version. The only way I can think of to do it is to load a parse transform to check versions with system_info calls, but by that time, the macro branching will already have taken place I think. |
What about adding the compile attribute to not emit warnings for
The problem is that this, in turn, will issue warnings in OTP < 20.1 because the function is not deprecated. It really seems there's no good way out of this. |
i'm curious as to the need of keeping generated protobuf marshaling stubs in the repo, is it to reduce build time? |
In a specific use case we have, it's to talk with Hex APIs when bootstrapping rebar3, to go fetch the initial packages (such as a gpb compiler). We have to work from a dependency-free initial state. |
Thansk all for valuable input and insights! I'll push a version with generation time support, to start with. For the use case of storing generated files, I was also thinking whether it would be possible to generate code that someone could more easily be integrated with a build system. For example if the code generated by gpb could use a |
I pushed 4.1.5 which contains generation time support for the new stacktrace syntax. |
One macro that got recommended to us by okeuday was either form of: -define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason:Stacktrace ->).
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason -> Stacktrace = erlang:get_stacktrace(), ).
%% Usage
try
...
catch
error:badarg ->
whatever;
?STACKTRACE(E, R, Stack)
{error, {E,R, Stack}}
end Put them at the top of every file in a -ifdef(PATTERN_STACK).
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason:Stacktrace ->).
-else.
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason -> Stacktrace = erlang:get_stacktrace(), ).
-endif. If targetting OTP21 or above do: -ifdef(FUNCTION_STACK).
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason -> Stacktrace = erlang:get_stacktrace(), ).
-else.
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason:Stacktrace ->).
-endif. That way the default is the correct targeted version, but build tools can override things. The only downside is that it won't support guards unless you have an alternative macro forms (and even then you can't use -ifdef(FUNCTION_STACK).
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason -> Stacktrace = erlang:get_stacktrace(), ).
-define(G_STACKTRACE(Type, Reason, Stacktrace, Guards), Type:Reason Guards -> Stacktrace = erlang:get_stacktrace(), ).
-else.
-define(STACKTRACE(Type, Reason, Stacktrace), Type:Reason:Stacktrace ->).
-define(G_STACKTRACE(Type, Reason, Stacktrace, Guards), Type:Reason:Stacktrace Guards ->).
-endif.
%% usage
try
...
catch
?G_STACKTRACE(error, R, Stack, when R == error orelse R == badarg)
{handled, Stack};
?STACKTRACE(E, R, Stack)
{error, {E,R, Stack}}
end I haven't tried the guarded variant, but it should work fine. |
Yes, that ought to do it. I don't need guards in the |
I've just pushed 4.1.6, which addresses this, as far as is currently possible. It adapts the generated code to the target otp release like in the previous 4.1.5, and now it is also possible to override when compiling the generated code. When targeting Erlang 21 or later, gpb generates code that uses (by default) the new stacktrace syntax, but if the user defines Similarly, when targeting Erlang 20 or earlier, gpb generates code that calls |
I'm closing this ticket since 4.1.6 is out containing the proposed stacktrace support. Please feel free to just reopen, if there's anything more to take care of! |
I'm reopening this. Now that erlang/otp#1810 was merged, it is possible to do better using the |
I've pushed 4.1.8, which generates code that checks whether Since current latest official release or rc, Erlang 21.0-rc1, has deprecated So to be clear, in 4.1.8, it generates code like when on Erlang 21 (also when on Erlang 21.0-rc1)
When on Erlang 20 or earlier the And when Erlang 21 gets released, I plan to change generation so that the inner So I'm closing this again. Just re-open if there's anything more. |
@tomas-abrahamsson hm, not sure if I'm just missing something or do we need to currently add the |
@tsloughter What versions of things? I just tried with Erlang 21-rc2 from the git repo (cabbb94eab) and also with 20.3.7+dfsg-1 (and gpb 597c91b) and then compiled a simple proto file, which compiles cleanly with erlc with no particular options, with both Erlang setups. |
My bad... after cleaning everything out I'm now getting a different result from the gpb plugin, one that works :). No idea what I was doing last night, I must not have had it actually recompiling the proto files. Sorry for the noise, it is working great :) |
No problems, glad things sorted themselves out! |
* add OTP check for 21 This will need improvement once we're using 22+ but for now will suffice. Doing version string matching in BASH is a pain * add stacktrace macros based on a comment from ferd tomas-abrahamsson/gpb#134 (comment) * duh regexp * auto-conversion to stacktrace macro * document the code usage of the stacktrace macro * add targets for checking stacktrace usage * update files to use stacktrace macros * use stacktrace macro everywhere * fixed unused variables * check for bare atoms too * more stacktrace updates * we have to live with this formatting i guess? * move clause to aid auto-fix * remove in favor of mine :) * add kz_types header to this escript file * deprecate * oh gawd, do we have live with this fmt? * add 21.3 test * a little docs update * don't need to macro after all, predefined in OTP 21+ * list available installtions on travis ci * proper macro name * tickie * play with not recompiling test modules every time * cleanup and clarify content type handling a bit * fix specs * cowboy doesn't like 2-tuples * ensure setting values with nested binaries are converted to UTF8 * change targeted version * add spec and cleanup whitespace * broked whitespace remover * remove IRC reporting * match new function strings * cleanup property tests of kz_cache * normalize value before setting * logging failures * less confusion around timeout periods * add reference to root erlang.mk file * split tests into separate unit test * update dep apps of kazoo_events * add some 5.0 announcements * remove unused var * ignore include for now (until breakening) * eval deps, updating / removing as necessary * fix some dialyzer complaints * handle empty list of objects * change from non-exported type * fix type used * fix type name * cleanup types * remove unneeded type * fix type * fix the type * type updates * fix more types * fix api_objects * use proper module for type * more invalid types fixed * more invalid types fixed * type updates * remove dep for now * remove DTH app from core kazoo apps * re-add eflame for now * d'oh, add eflame back to deps * remove dth * ci fixes * specs types formatting * kz_config usage * more spec, type, and kz_config usage * fix module usage * add meta back to mix * remove log and format bigcouch sections * make sure couch conns are pulled in from config * sleep between cleanups * add edoc * remove unused var * fix unused var * convert to new atoms if necessary * tags as binaries * ignore parallel tests for now * pool names are expected to be atoms * connect options follow gen_tcp connect options * fix dialyzer errors and warns * fix dialyzer round 2 * round 3 * address some more dialyzer complaints
* add OTP check for 21 This will need improvement once we're using 22+ but for now will suffice. Doing version string matching in BASH is a pain * add stacktrace macros based on a comment from ferd tomas-abrahamsson/gpb#134 (comment) * duh regexp * auto-conversion to stacktrace macro * document the code usage of the stacktrace macro * add targets for checking stacktrace usage * update files to use stacktrace macros * use stacktrace macro everywhere * fixed unused variables * check for bare atoms too * more stacktrace updates * we have to live with this formatting i guess? * move clause to aid auto-fix * remove in favor of mine :) * add kz_types header to this escript file * deprecate * oh gawd, do we have live with this fmt? * add 21.3 test * a little docs update * don't need to macro after all, predefined in OTP 21+ * list available installtions on travis ci * proper macro name * tickie * play with not recompiling test modules every time * cleanup and clarify content type handling a bit * fix specs * cowboy doesn't like 2-tuples * ensure setting values with nested binaries are converted to UTF8 * change targeted version * add spec and cleanup whitespace * broked whitespace remover * remove IRC reporting * match new function strings * cleanup property tests of kz_cache * normalize value before setting * logging failures * less confusion around timeout periods * add reference to root erlang.mk file * split tests into separate unit test * update dep apps of kazoo_events * add some 5.0 announcements * remove unused var * ignore include for now (until breakening) * eval deps, updating / removing as necessary * fix some dialyzer complaints * handle empty list of objects * change from non-exported type * fix type used * fix type name * cleanup types * remove unneeded type * fix type * fix the type * type updates * fix more types * fix api_objects * use proper module for type * more invalid types fixed * more invalid types fixed * type updates * remove dep for now * remove DTH app from core kazoo apps * re-add eflame for now * d'oh, add eflame back to deps * remove dth * ci fixes * specs types formatting * kz_config usage * more spec, type, and kz_config usage * fix module usage * add meta back to mix * remove log and format bigcouch sections * make sure couch conns are pulled in from config * sleep between cleanups * add edoc * remove unused var * fix unused var * convert to new atoms if necessary * tags as binaries * ignore parallel tests for now * pool names are expected to be atoms * connect options follow gen_tcp connect options * fix dialyzer errors and warns * fix dialyzer round 2 * round 3 * address some more dialyzer complaints
* add OTP check for 21 This will need improvement once we're using 22+ but for now will suffice. Doing version string matching in BASH is a pain * add stacktrace macros based on a comment from ferd tomas-abrahamsson/gpb#134 (comment) * duh regexp * auto-conversion to stacktrace macro * document the code usage of the stacktrace macro * add targets for checking stacktrace usage * update files to use stacktrace macros * use stacktrace macro everywhere * fixed unused variables * check for bare atoms too * more stacktrace updates * we have to live with this formatting i guess? * move clause to aid auto-fix * remove in favor of mine :) * add kz_types header to this escript file * deprecate * oh gawd, do we have live with this fmt? * add 21.3 test * a little docs update * don't need to macro after all, predefined in OTP 21+ * list available installtions on travis ci * proper macro name * tickie * play with not recompiling test modules every time * cleanup and clarify content type handling a bit * fix specs * cowboy doesn't like 2-tuples * ensure setting values with nested binaries are converted to UTF8 * change targeted version * add spec and cleanup whitespace * broked whitespace remover * remove IRC reporting * match new function strings * cleanup property tests of kz_cache * normalize value before setting * logging failures * less confusion around timeout periods * add reference to root erlang.mk file * split tests into separate unit test * update dep apps of kazoo_events * add some 5.0 announcements * remove unused var * ignore include for now (until breakening) * eval deps, updating / removing as necessary * fix some dialyzer complaints * handle empty list of objects * change from non-exported type * fix type used * fix type name * cleanup types * remove unneeded type * fix type * fix the type * type updates * fix more types * fix api_objects * use proper module for type * more invalid types fixed * more invalid types fixed * type updates * remove dep for now * remove DTH app from core kazoo apps * re-add eflame for now * d'oh, add eflame back to deps * remove dth * ci fixes * specs types formatting * kz_config usage * more spec, type, and kz_config usage * fix module usage * add meta back to mix * remove log and format bigcouch sections * make sure couch conns are pulled in from config * sleep between cleanups * add edoc * remove unused var * fix unused var * convert to new atoms if necessary * tags as binaries * ignore parallel tests for now * pool names are expected to be atoms * connect options follow gen_tcp connect options * fix dialyzer errors and warns * fix dialyzer round 2 * round 3 * address some more dialyzer complaints
* add OTP check for 21 This will need improvement once we're using 22+ but for now will suffice. Doing version string matching in BASH is a pain * add stacktrace macros based on a comment from ferd tomas-abrahamsson/gpb#134 (comment) * duh regexp * auto-conversion to stacktrace macro * document the code usage of the stacktrace macro * add targets for checking stacktrace usage * update files to use stacktrace macros * use stacktrace macro everywhere * fixed unused variables * check for bare atoms too * more stacktrace updates * we have to live with this formatting i guess? * move clause to aid auto-fix * remove in favor of mine :) * add kz_types header to this escript file * deprecate * oh gawd, do we have live with this fmt? * add 21.3 test * a little docs update * don't need to macro after all, predefined in OTP 21+ * list available installtions on travis ci * proper macro name * tickie * play with not recompiling test modules every time * cleanup and clarify content type handling a bit * fix specs * cowboy doesn't like 2-tuples * ensure setting values with nested binaries are converted to UTF8 * change targeted version * add spec and cleanup whitespace * broked whitespace remover * remove IRC reporting * match new function strings * cleanup property tests of kz_cache * normalize value before setting * logging failures * less confusion around timeout periods * add reference to root erlang.mk file * split tests into separate unit test * update dep apps of kazoo_events * add some 5.0 announcements * remove unused var * ignore include for now (until breakening) * eval deps, updating / removing as necessary * fix some dialyzer complaints * handle empty list of objects * change from non-exported type * fix type used * fix type name * cleanup types * remove unneeded type * fix type * fix the type * type updates * fix more types * fix api_objects * use proper module for type * more invalid types fixed * more invalid types fixed * type updates * remove dep for now * remove DTH app from core kazoo apps * re-add eflame for now * d'oh, add eflame back to deps * remove dth * ci fixes * specs types formatting * kz_config usage * more spec, type, and kz_config usage * fix module usage * add meta back to mix * remove log and format bigcouch sections * make sure couch conns are pulled in from config * sleep between cleanups * add edoc * remove unused var * fix unused var * convert to new atoms if necessary * tags as binaries * ignore parallel tests for now * pool names are expected to be atoms * connect options follow gen_tcp connect options * fix dialyzer errors and warns * fix dialyzer round 2 * round 3 * address some more dialyzer complaints
* add OTP check for 21 This will need improvement once we're using 22+ but for now will suffice. Doing version string matching in BASH is a pain * add stacktrace macros based on a comment from ferd tomas-abrahamsson/gpb#134 (comment) * duh regexp * auto-conversion to stacktrace macro * document the code usage of the stacktrace macro * add targets for checking stacktrace usage * update files to use stacktrace macros * use stacktrace macro everywhere * fixed unused variables * check for bare atoms too * more stacktrace updates * we have to live with this formatting i guess? * move clause to aid auto-fix * remove in favor of mine :) * add kz_types header to this escript file * deprecate * oh gawd, do we have live with this fmt? * add 21.3 test * a little docs update * don't need to macro after all, predefined in OTP 21+ * list available installtions on travis ci * proper macro name * tickie * play with not recompiling test modules every time * cleanup and clarify content type handling a bit * fix specs * cowboy doesn't like 2-tuples * ensure setting values with nested binaries are converted to UTF8 * change targeted version * add spec and cleanup whitespace * broked whitespace remover * remove IRC reporting * match new function strings * cleanup property tests of kz_cache * normalize value before setting * logging failures * less confusion around timeout periods * add reference to root erlang.mk file * split tests into separate unit test * update dep apps of kazoo_events * add some 5.0 announcements * remove unused var * ignore include for now (until breakening) * eval deps, updating / removing as necessary * fix some dialyzer complaints * handle empty list of objects * change from non-exported type * fix type used * fix type name * cleanup types * remove unneeded type * fix type * fix the type * type updates * fix more types * fix api_objects * use proper module for type * more invalid types fixed * more invalid types fixed * type updates * remove dep for now * remove DTH app from core kazoo apps * re-add eflame for now * d'oh, add eflame back to deps * remove dth * ci fixes * specs types formatting * kz_config usage * more spec, type, and kz_config usage * fix module usage * add meta back to mix * remove log and format bigcouch sections * make sure couch conns are pulled in from config * sleep between cleanups * add edoc * remove unused var * fix unused var * convert to new atoms if necessary * tags as binaries * ignore parallel tests for now * pool names are expected to be atoms * connect options follow gen_tcp connect options * fix dialyzer errors and warns * fix dialyzer round 2 * round 3 * address some more dialyzer complaints
* add OTP check for 21 This will need improvement once we're using 22+ but for now will suffice. Doing version string matching in BASH is a pain * add stacktrace macros based on a comment from ferd tomas-abrahamsson/gpb#134 (comment) * duh regexp * auto-conversion to stacktrace macro * document the code usage of the stacktrace macro * add targets for checking stacktrace usage * update files to use stacktrace macros * use stacktrace macro everywhere * fixed unused variables * check for bare atoms too * more stacktrace updates * we have to live with this formatting i guess? * move clause to aid auto-fix * remove in favor of mine :) * add kz_types header to this escript file * deprecate * oh gawd, do we have live with this fmt? * add 21.3 test * a little docs update * don't need to macro after all, predefined in OTP 21+ * list available installtions on travis ci * proper macro name * tickie * play with not recompiling test modules every time * cleanup and clarify content type handling a bit * fix specs * cowboy doesn't like 2-tuples * ensure setting values with nested binaries are converted to UTF8 * change targeted version * add spec and cleanup whitespace * broked whitespace remover * remove IRC reporting * match new function strings * cleanup property tests of kz_cache * normalize value before setting * logging failures * less confusion around timeout periods * add reference to root erlang.mk file * split tests into separate unit test * update dep apps of kazoo_events * add some 5.0 announcements * remove unused var * ignore include for now (until breakening) * eval deps, updating / removing as necessary * fix some dialyzer complaints * handle empty list of objects * change from non-exported type * fix type used * fix type name * cleanup types * remove unneeded type * fix type * fix the type * type updates * fix more types * fix api_objects * use proper module for type * more invalid types fixed * more invalid types fixed * type updates * remove dep for now * remove DTH app from core kazoo apps * re-add eflame for now * d'oh, add eflame back to deps * remove dth * ci fixes * specs types formatting * kz_config usage * more spec, type, and kz_config usage * fix module usage * add meta back to mix * remove log and format bigcouch sections * make sure couch conns are pulled in from config * sleep between cleanups * add edoc * remove unused var * fix unused var * convert to new atoms if necessary * tags as binaries * ignore parallel tests for now * pool names are expected to be atoms * connect options follow gen_tcp connect options * fix dialyzer errors and warns * fix dialyzer round 2 * round 3 * address some more dialyzer complaints
Stacktraces are moving to a value matched in
catch
in OTP-21 andget_stacktrace()
is deprecated.It is a pretty simple fix in
decode_msg
to support 21, but supporting both will be kind of ugly.Not sure if the best solution is generating different code for a 21 switch or generate 2
decode_msg
functions with macros around them so the compilation of the erl files themselves can decide which to use.The text was updated successfully, but these errors were encountered: