From caf4468f3bbbea75be35e0cf0560990b5db66e7e Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Tue, 16 Feb 2016 08:54:46 -0500 Subject: Make lock files future-proof Changes to how hex or packages may work in the future will necessarily bring changes to the format of lock files. This commit adds an optional framing for future lock files of the form: {Version, LockList}. This format is supported such as the LockList is the current lockfile contents, and will never have more information than it currently does. Attributes can be whatever and are currently undefined. Rebar copies will be able to: - Keep using the core locklist (which avoids breaking the last year or so of community libraries using rebar3) - Warn when it runs an outdated copy in comparison to the lock file - Automatically rewrite lock files in the format it supports - Augment or parse files in a version-specific manner. This changes the usage interface slightly, but is backwards *and* forwards compatible. --- test/rebar_lock_SUITE.erl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/rebar_lock_SUITE.erl (limited to 'test/rebar_lock_SUITE.erl') diff --git a/test/rebar_lock_SUITE.erl b/test/rebar_lock_SUITE.erl new file mode 100644 index 0000000..00875f7 --- /dev/null +++ b/test/rebar_lock_SUITE.erl @@ -0,0 +1,46 @@ +%%% Most locking tests are implicit in other test suites handling +%%% dependencies. +%%% This suite is to test the compatibility layers between various +%%% versions of lockfiles. +-module(rebar_lock_SUITE). +-compile(export_all). +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +all() -> [current_version, future_versions_no_attrs, future_versions_attrs]. + +current_version(Config) -> + %% Current version just dumps the locks as is on disk. + LockFile = filename:join(?config(priv_dir, Config), "current_version"), + Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}], + file:write_file(LockFile, io_lib:format("~p.~n", [Locks])), + ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)). + +future_versions_no_attrs(Config) -> + %% Future versions will keep the same core attribute in there, but + %% will do so under a new format bundled with a version and potentially + %% some trailing attributes + LockFile = filename:join(?config(priv_dir, Config), "future_versions"), + Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}], + LockData = {"3.5.2", Locks}, + file:write_file(LockFile, io_lib:format("~p.~n", [LockData])), + ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)). + +future_versions_attrs(Config) -> + %% Future versions will keep the same core attribute in there, but + %% will do so under a new format bundled with a version and potentially + %% some trailing attributes + LockFile = filename:join(?config(priv_dir, Config), "future_versions"), + Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}], + LockData = {"3.5.2", Locks}, + file:write_file(LockFile, io_lib:format("~p.~na.~n{b,c}.~n[d,e,f].~n", [LockData])), + ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)). -- cgit v1.1