Skip to content
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 23 [master] compatibility #2191

Merged
merged 4 commits into from
Dec 22, 2019

Conversation

michaelklishin
Copy link
Contributor

@michaelklishin michaelklishin commented Dec 21, 2019

Team RabbitMQ tests OTP versions from 20.3 to master in our CI/CD pipelines. Recent OTP master changes introduce additional warnings that make Rebar bootstrap fail.

Unfortunately, there is no URI utility function module that's both available in OTP 20 and not deprecated in OTP 23. So this PR suppresses a few warnings for now. I hope that's acceptable.

Switching to uri_string as the warning suggest
would ruin OTP 20 compatibility.
Switching to uri_string as the warning suggest
would ruin OTP 20 compatibility.
@michaelklishin
Copy link
Contributor Author

This is hilarious.

@tsloughter
Copy link
Collaborator

Nice, thanks.

And hah, yea, I guess you have to wrap the compile directive in a -ifdef(OTP_RELEASE).

@tsloughter
Copy link
Collaborator

The new module to use is uri_string in stdlib, right?

For OTP 19 and earlier compatibility.
@michaelklishin
Copy link
Contributor Author

@tsloughter yup, an ifdef(OTP_RELEASE) helped. The warning does recommend uri_string but it's not available in OTP <= 20 in my tests.

@michaelklishin
Copy link
Contributor Author

CI is green now 👌

@tsloughter
Copy link
Collaborator

Yea, a better change would be to create new functions that wrap http_uri and uri_string and wrap those functions in -ifdef(OTP_RELEASE) so it uses the right ones depending on being OTP 20+ or not.

@tsloughter
Copy link
Collaborator

Thanks. I'll merge this. I'm looking to get a release out today but want to replace this change with use of uri_string soon. Let me know if you were looking at doing that or if I should do it.

@tsloughter tsloughter merged commit 1553164 into erlang:master Dec 22, 2019
@michaelklishin michaelklishin deleted the otp-23-master-compat branch December 24, 2019 18:45
@michaelklishin
Copy link
Contributor Author

@tsloughter I'd be happy to do it. Thank you for the quick release!

@michaelklishin
Copy link
Contributor Author

@tsloughter so I tried and it turns out to be less trivial than it sounds. Getting rid of http_uri:parse/1 is easy, even though not pretty:

%%% @doc multi-OTP version compatibility shim for working with URIs
-module(rebar_uri).

-ifdef (OTP_RELEASE).
    -export([parse/1]).

    -spec parse(URIString) -> URIMap when
        URIString :: uri_string:uri_string(),
        URIMap :: uri_string:uri_map() | uri_string:error().

    parse(URIString) ->
        uri_string:parse(URIString).
-else.
    -export([parse/1]).

    -spec parse(URIString) -> URIMap when
        URIString :: iodata(),
        URIMap :: map() | {error, atom(), term()}.

    parse(URIString) ->
        case http_uri:parse(URIString) of
            {error, Reason} ->
                %% no additional parser/term info available to us,
                %% e.g. see what uri_string returns in
                %% uri_string:parse(<<"h$ttp:::://////lolz">>).
                {error, Reason, ""};
            {ok, {Scheme, UserInfo, Host, Port, Path, Query}} ->
                #{
                    scheme => Scheme,
                    host => Host,
                    port => Port,
                    path => Path,
                    %% http_uri:parse/1 includes the leading question mark
                    %% in query string but uri_string:parse/1 leaves it out
                    query => string:slice(Query, 1),
                    userinfo => UserInfo
                }
        end.
-endif.

but there is no replacement for http_uri:encode/1 exposed in uri_string. This means that r3_hex_api:encode_query_string/1 has to go or be replaced entirely. I'm not familiar enough
with how Rebar API modules are used and what callers may be affected (plugins?)

So if you have a clear idea of how to approach this, go ahead and do it.

@starbelly
Copy link
Contributor

starbelly commented Dec 26, 2019

Options:

  • A patch release for that version of hex_core can be coordinated with hex team and then re-vendor the patched version into rebar3
  • Patch r3_hex_api and send the patch upstream to hex_core

@michaelklishin
Copy link
Contributor Author

@starbelly thanks. Reimplementing r3_hex_api:encode_query_string/1 is also an option.

I'd also question the need for OTP 18 and 19 support in almost 2020 but OTP 20 is also affected (doesn't ship uri_string) and it still gets patch releases every once in a while.

@michaelklishin
Copy link
Contributor Author

Alternatively r3_hex_api_package, the sole user of r3_hex_api:encode_query_string/1, could be migrated to use something else.

@tsloughter
Copy link
Collaborator

Isn't uri_string:recompose the replacement?

@michaelklishin
Copy link
Contributor Author

@tsloughter it will encode URI segments but it requires at least a scheme, hostname, and a path to be in the map. So it would be a breaking change to r3_hex_api anyway it seems.

@starbelly
Copy link
Contributor

@michaelklishin I think the best option is to patch r3_hex_api:encode_query_string/1 and then send a patch to hex_core. Path of least resistance and all... and this was part of the motivation behind vendoring it in to begin with.

@michaelklishin
Copy link
Contributor Author

#2195 is ready for QA.

@starbelly
Copy link
Contributor

@michaelklishin Second thought... we are going to have to re-vendor hex_core anyway, so let's get a patch to hex_core done and then I'll do a PR to re-sync hex_core in rebar3. Are you going to open a PR to hex_core? If not, I can certainly do so based on your code.

michaelklishin added a commit to michaelklishin/hex_core that referenced this pull request Dec 30, 2019
which has been deprecated in OTP 23 [master].

See erlang/rebar32195 and erlang/rebar3#2191 for
background.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants