diff --git a/.travis.yml b/.travis.yml index 0c3e76c0..6cacaced 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,8 @@ before_script: script: "make test" otp_release: - - 17.0-rc1 + - 17.1 + - 17.0 - R16B03-1 - R16B - R15B03 diff --git a/Makefile b/Makefile index cd06e0a9..2426396a 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,14 @@ APP_NAME=emysql MODULES=$(shell ls -1 src/*.erl | awk -F[/.] '{ print $$2 }' | sed '$$q;s/$$/,/g') MAKETIME=$(shell date) -all: crypto_compat app +all: compat app (cd src;$(MAKE)) app: ebin/$(PKGNAME).app -crypto_compat: +compat: (escript support/crypto_compat.escript) + (escript support/type_compat.escript) ebin/$(PKGNAME).app: src/$(PKGNAME).app.src mkdir -p ebin @@ -55,6 +56,7 @@ clean: rm -f *.beam rm -f *.html rm -f include/crypto_compat.hrl + rm -f include/type_compat.hrl rm -fr logs package: clean diff --git a/include/emysql.hrl b/include/emysql.hrl index 1320289f..f770f692 100644 --- a/include/emysql.hrl +++ b/include/emysql.hrl @@ -24,7 +24,7 @@ %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR %% OTHER DEALINGS IN THE SOFTWARE. - +-include("type_compat.hrl"). -record(pool, {pool_id :: atom(), size :: number(), @@ -34,9 +34,9 @@ port :: number(), database :: string(), encoding :: utf8 | latin1 | {utf8, utf8_unicode_ci} | {utf8, utf8_general_ci}, - available=queue:new() :: queue(), - locked=gb_trees:empty() :: gb_tree(), - waiting=queue:new() :: queue(), + available=queue:new() :: emysql_queue(), + locked=gb_trees:empty() :: emysql_gb_tree(), + waiting=queue:new() :: emysql_queue(), start_cmds=[] :: string(), conn_test_period=0 :: number(), connect_timeout=infinity :: number() | infinity, diff --git a/rebar.config b/rebar.config index e61983a8..5898af82 100644 --- a/rebar.config +++ b/rebar.config @@ -1,9 +1,10 @@ % -*- Erlang -*- % vim: ts=4 sw=4 et ft=erlang {erl_opts, [ - nowarn_deprecated_type ]}. {pre_hooks,[ {"linux|bsd|darwin|solaris", compile, "escript ./support/crypto_compat.escript"}, - {"win32", compile, "escript.exe support/crypto_compat.escript"} + {"linux|bsd|darwin|solaris", compile, "escript ./support/type_compat.escript"}, + {"win32", compile, "escript.exe support/crypto_compat.escript"}, + {"win32", compile, "escript.exe support/type_compat.escript"} ]}. diff --git a/src/emysql.erl b/src/emysql.erl index a373de9a..8966d8de 100644 --- a/src/emysql.erl +++ b/src/emysql.erl @@ -669,7 +669,7 @@ result_type(#eof_packet{}) -> eof. -spec as_dict(Result) -> Dict when Result :: #result_packet{}, - Dict :: dict(). + Dict :: emysql_dict(). as_dict(Res) -> emysql_conv:as_dict(Res). diff --git a/src/emysql_conn_mgr.erl b/src/emysql_conn_mgr.erl index b14a08d6..c7a98a96 100644 --- a/src/emysql_conn_mgr.erl +++ b/src/emysql_conn_mgr.erl @@ -40,7 +40,7 @@ -include("emysql.hrl"). --record(state, {pools, lockers = dict:new() :: dict()}). +-record(state, {pools, lockers = dict:new() :: emysql_dict()}). %%==================================================================== %% API diff --git a/support/type_compat.escript b/support/type_compat.escript new file mode 100755 index 00000000..8a00b5c2 --- /dev/null +++ b/support/type_compat.escript @@ -0,0 +1,58 @@ +#!/usr/bin/env escript +%% vim: ts=4 sw=4 et ft=erlang + +%% Erlang 17 Changed the expected types of dict(), gb_trees(), etc to require +%% prefixing with the module name. This caused a non-backwards compatibile +%% break with versions prior to Erlang 17. +%% +%% This script will check the Erlang version and if otp_release >= 17, it will create +%% custom types called emysql_dict(), etc which just refer to dict:dict(), making the +%% types fully backwards compatible, and if OTP prior to 17, will create +%% emysql_dict() which refers to dict(). +%% +%% It will do this for dict(), queue(), and gb_tree() +%% +%% Note: This should be run *before* compiling! + +-define(TYPE_PREFIX, "emysql_"). +-define(TYPES, [ + %{old version, new version} + {"dict()", "dict:dict()"}, + {"queue()", "queue:queue()"}, + {"gb_tree()", "gb_trees:tree()"} +]). + +main([]) -> + crypto:start(), + + Filename = "include/type_compat.hrl", + io:format("Generating ~p ...~n", [Filename]), + + TypeStrings = process_otp_version(erlang:system_info(otp_release)), + + Contents = [ + "%% Note: This file was automatically generated. Do not include it in source control\n", + TypeStrings + ], + + ContentsBin = iolist_to_binary(Contents), + case file:read_file(Filename) of + {ok, ContentsBin} -> + io:format("...no changes needed to ~p. Skipping writing new file~n", [Filename]); + _ -> + io:format("...writing ~p~n", [Filename]), + file:write_file(Filename, Contents) + end. + +process_otp_version(Version = "R" ++ _) -> + io:format("...OTP ~s does not require module prefixes for types...~n",[Version]), + [make_type_pre_17(OldType) || {OldType, _} <- ?TYPES]; +process_otp_version(Version) -> + io:format("...OTP ~s requires module prefixes for types...~n",[Version]), + [make_type_17_plus(Types) || Types <- ?TYPES]. + +make_type_pre_17(Type) -> + ["-type ",?TYPE_PREFIX,Type, " :: ",Type,".\n"]. + +make_type_17_plus({Type, FullType}) -> + ["-type ",?TYPE_PREFIX,Type, " :: ",FullType,".\n"].