-
Notifications
You must be signed in to change notification settings - Fork 524
Return manifest macros as objects #2962
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
Conversation
|
@eproxus The CT failure seems unrelated, maybe re-push this one to get a green CI? |
| to_macros(Macros) -> | ||
| maps:from_list([to_macro(M) || M <- Macros]). | ||
|
|
||
| -spec to_macro(atom() | {atom() | any()}) -> {macro_key(), macro_value()}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -spec looks incorrect now. The input Value in the first clause can be any(), but the Value in output is a macro_value(), which is a binary().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and the old type can contain just a key without a value too... will fix this if you think the overall PR make sense.
|
Just to clarify and confirm this fixes the integration issue:
|
0774f64 to
7685638
Compare
Yes, using version [build_info]
file = "manifest.json"ELP (via Zed) spits out this error: Where the manifest is: {
"deps": [
{
"name": "crc32cer",
"dir": "/path/to/project/_build/default/lib/crc32cer",
"macros": [], // Line 6
% ^ column 22
"extra_src_dirs": [],
...Generating a manifest with this patch stops ELP from complaining. |
| -spec to_macro(atom() | {atom() | any()}) -> macro(). | ||
| -spec to_macros(proplists:proplist()) -> macros(). | ||
| to_macros(Macros) -> | ||
| maps:from_list([to_macro(M) || M <- Macros]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but, since there is already happens a loop over a list it can be make sense to simply it like
to_macros(Macros) ->
to_macro(Macros, #{}).
to_macro([], Acc) ->
Acc;
to_macro([{Key, Value} | T], Acc) when is_atom(Key) ->
to_macro(T, Acc#{Key => Value});
to_macro([K | T], Acc) when is_atom(Key) ->
to_macro(T, Acc#{Key => <<"true">>}).and get rid of the function call maps:from_list/1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep it as is right now since it is fairly readable. We might consider using lists:foldl or a custom recursive functions, but maps:from_list is a NIF so I'd like to see some benchmark first that this really makes a difference for any practical case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, plus a list maybe will not a big it self. As I wrote above - it not a big deal, but by some reason I was think that the one list loop it always a faster then two 🙃 - but as you mention is used a NIF.
|
@eproxus Oh, I see. Are you going through the If it makes sense, you could just drop the Said that, yes, we should also fix this format. I also see that macros are broken in many ways with the rebar integration (we don't use it internally, so I'm not surprised). For example, the following in a Would cause (with the current rebar3): And (with your version): |
|
We were using it manually as a stop gap to get it to work (probably because of the problem fixed by #2963) and discovered this. It just felt like a bug. @robertoaloi Ok, so this PR improves the situation slightly but not completely. Would you like it merged as is, and then you can fix the other problems later if needed? Since we don't really use the JSON manifest we don't really care either way 😄 |
|
@eproxus Sounds like a plan. |
robertoaloi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, apart from the incorrect spec.
7685638 to
6aaac21
Compare
|
@robertoaloi Simplified the type specs to match the original version (plus a bug fix Ready to merge from my side. Let me know if you have any more concerns. |
This change makes `rebar3 experimental manifest` return macros as maps (JSON objects) to match the required ELP format.
6aaac21 to
50e5b85
Compare
This change makes
rebar3 experimental manifestreturn macros as maps (JSON objects) to match the required ELP format.