Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

508 rindas
20 KiB

Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
Properly support package aliasing and alt names Aliasing only had a bit of ad-hoc support in rebar3, and various issues have encountered problems related to the package names not mapping properly with the application name. One such issue is https://github.com/erlang/rebar3/issues/1290 The problem has been hard to find because it only impacts transitive dependencies (not top-level ones) of other packages. The root cause for this is that the application name was not being tracked by rebar3's internal index, only the package name and its version were. When a given application was a package app, the data for the application name would be reconstructed from the lock file, but only if it were a top-level app or a dependency of a source application where parsing the lock file is necessary to know what comes next. When a transitive dependency of a package dependency was fetched, we instead read its dependencies directly from the in-memory package index within rebar3. This caused us to only read the package name and version, and lost all information regarding application name. This worked fine for most cases since for the vast majority of packages, the package name matches the app name, but failed for all aliases, which would then be moved to directories that wouldn't match the app name. This in turn broke some aspects of code analysis (in Dialyzer), or other functionality relying on static paths, such as including .hrl files from dependencies. This patch reformats the internal storage format of dependencies to align with the internal one used by rebar3, so that the app name can be carried along with the package name and its version. The fix can only work once `rebar3 update` is called so the index is rebuilt internally, and will the file cached on disk will be incompatible with older rebar3 versions. Currently, the following is not covered: - Tests - Including the package hashes of dependencies so they may match what is in a lock file -- they're being `undefined` instead, which may break some lookups. The previous format did not lend itself to hashing in the same way, and it is possible transitive deps were not being tracked properly, or worked by respecting the current package hierarchy. This will require further analysis For now this commit can allow reviewing and discussion.
pirms 8 gadiem
  1. -module(rebar_deps_SUITE).
  2. -compile(export_all).
  3. -include_lib("common_test/include/ct.hrl").
  4. -include_lib("eunit/include/eunit.hrl").
  5. all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock,
  6. http_proxy_settings, https_proxy_settings,
  7. http_os_proxy_settings, https_os_proxy_settings,
  8. semver_matching_lt, semver_matching_lte, semver_matching_gt,
  9. valid_version, top_override, {group, git}, {group, pkg}].
  10. groups() ->
  11. [{all, [], [flat, pick_highest_left, pick_highest_right,
  12. pick_smallest1, pick_smallest2,
  13. circular1, circular2, circular_skip]},
  14. {git, [], [{group, all}]},
  15. {pkg, [], [{group, all}]}].
  16. init_per_suite(Config) ->
  17. application:start(meck),
  18. Config.
  19. end_per_suite(_Config) ->
  20. application:stop(meck).
  21. init_per_group(git, Config) ->
  22. [{deps_type, git} | Config];
  23. init_per_group(pkg, Config) ->
  24. [{deps_type, pkg} | Config];
  25. init_per_group(_, Config) ->
  26. Config.
  27. end_per_group(_, Config) ->
  28. Config.
  29. init_per_testcase(valid_version, Config) ->
  30. rebar_test_utils:init_rebar_state(Config);
  31. init_per_testcase(semver_matching_lt, Config) ->
  32. rebar_test_utils:init_rebar_state(Config);
  33. init_per_testcase(semver_matching_lte, Config) ->
  34. rebar_test_utils:init_rebar_state(Config);
  35. init_per_testcase(semver_matching_gt, Config) ->
  36. rebar_test_utils:init_rebar_state(Config);
  37. init_per_testcase(newly_added_after_empty_lock, Config) ->
  38. rebar_test_utils:init_rebar_state(Config);
  39. init_per_testcase(newly_added_dep, Config) ->
  40. rebar_test_utils:init_rebar_state(Config);
  41. init_per_testcase(sub_app_deps, Config) ->
  42. rebar_test_utils:init_rebar_state(Config);
  43. init_per_testcase(top_override, Config) ->
  44. rebar_test_utils:init_rebar_state(Config);
  45. init_per_testcase(http_proxy_settings, Config) ->
  46. %% Create private rebar.config
  47. Priv = ?config(priv_dir, Config),
  48. GlobalDir = filename:join(Priv, "global"),
  49. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  50. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  51. meck:new(rebar_dir, [passthrough]),
  52. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  53. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  54. %% Insert proxy variables into config
  55. rebar_test_utils:create_config(GlobalConfigDir,
  56. [{http_proxy, "http://localhost:1234"}
  57. ]),
  58. rebar_test_utils:init_rebar_state(Config);
  59. init_per_testcase(https_proxy_settings, Config) ->
  60. SupportsHttpsProxy = case erlang:system_info(otp_release) of
  61. "R16"++_ -> true;
  62. "R"++_ -> false;
  63. _ -> true % 17 and up don't have a "R" in the version
  64. end,
  65. if not SupportsHttpsProxy ->
  66. {skip, https_proxy_unsupported_before_R16};
  67. SupportsHttpsProxy ->
  68. %% Create private rebar.config
  69. Priv = ?config(priv_dir, Config),
  70. GlobalDir = filename:join(Priv, "global"),
  71. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  72. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  73. meck:new(rebar_dir, [passthrough]),
  74. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  75. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  76. %% Insert proxy variables into config
  77. rebar_test_utils:create_config(GlobalConfigDir,
  78. [{https_proxy, "http://localhost:1234"}
  79. ]),
  80. %% Add a bad value by default to show config overtakes default
  81. os:putenv("https_proxy", "unparseable-garbage"),
  82. rebar_test_utils:init_rebar_state(Config)
  83. end;
  84. init_per_testcase(http_os_proxy_settings, Config) ->
  85. %% Create private rebar.config
  86. Priv = ?config(priv_dir, Config),
  87. GlobalDir = filename:join(Priv, "global"),
  88. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  89. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  90. meck:new(rebar_dir, [passthrough]),
  91. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  92. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  93. %% Insert proxy variables into os env, but not config
  94. os:putenv("http_proxy", "http://localhost:1234"),
  95. rebar_test_utils:create_config(GlobalConfigDir, []),
  96. rebar_test_utils:init_rebar_state(Config);
  97. init_per_testcase(https_os_proxy_settings, Config) ->
  98. SupportsHttpsProxy = case erlang:system_info(otp_release) of
  99. "R16"++_ -> true;
  100. "R"++_ -> false;
  101. _ -> true % 17 and up don't have a "R" in the version
  102. end,
  103. if not SupportsHttpsProxy ->
  104. {skip, https_proxy_unsupported_before_R16};
  105. SupportsHttpsProxy ->
  106. %% Create private rebar.config
  107. Priv = ?config(priv_dir, Config),
  108. GlobalDir = filename:join(Priv, "global"),
  109. GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
  110. GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
  111. meck:new(rebar_dir, [passthrough]),
  112. meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
  113. meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
  114. %% Insert proxy variables into os env, not in config
  115. os:putenv("https_proxy", "http://localhost:1234"),
  116. rebar_test_utils:create_config(GlobalConfigDir, []),
  117. rebar_test_utils:init_rebar_state(Config)
  118. end;
  119. init_per_testcase(Case, Config) ->
  120. {Deps, Warnings, Expect} = deps(Case),
  121. Expected = case Expect of
  122. {ok, List} -> {ok, format_expected_deps(List)};
  123. {error, Reason} -> {error, Reason}
  124. end,
  125. DepsType = ?config(deps_type, Config),
  126. mock_warnings(),
  127. [{expect, Expected},
  128. {warnings, Warnings}
  129. | setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))].
  130. end_per_testcase(https_proxy_settings, Config) ->
  131. os:putenv("https_proxy", ""),
  132. meck:unload(rebar_dir),
  133. Config;
  134. end_per_testcase(http_proxy_settings, Config) ->
  135. meck:unload(rebar_dir),
  136. Config;
  137. end_per_testcase(http_os_proxy_settings, Config) ->
  138. os:putenv("http_proxy", ""),
  139. meck:unload(rebar_dir),
  140. Config;
  141. end_per_testcase(https_os_proxy_settings, Config) ->
  142. os:putenv("https_proxy", ""),
  143. meck:unload(rebar_dir),
  144. Config;
  145. end_per_testcase(_, Config) ->
  146. meck:unload(),
  147. Config.
  148. format_expected_deps(Deps) ->
  149. [case Dep of
  150. {N,V} -> {dep, N, V};
  151. N -> {dep, N}
  152. end || Dep <- Deps].
  153. %% format:
  154. %% {Spec,
  155. %% [Warning],
  156. %% {ok, Result} | {error, Reason}}
  157. %%
  158. %% Spec is a list of levelled dependencies of two possible forms:
  159. %% - {"Name", Spec}
  160. %% - {"Name", "Vsn", Spec}
  161. %%
  162. %% Warnings are going to match on mocked ?WARN(...)
  163. %% calls to be evaluated. An empty list means we do not care about
  164. %% warnings, not that no warnings will be printed. This means
  165. %% the list of warning isn't interpreted to be exhaustive, and more
  166. %% warnings may be generated than are listed.
  167. deps(flat) ->
  168. {[{"B", []},
  169. {"C", []}],
  170. [],
  171. {ok, ["B", "C"]}};
  172. deps(pick_highest_left) ->
  173. {[{"B", [{"C", "2", []}]},
  174. {"C", "1", []}],
  175. [{"C","2"}],
  176. {ok, ["B", {"C", "1"}]}};
  177. deps(pick_highest_right) ->
  178. {[{"B", "1", []},
  179. {"C", [{"B", "2", []}]}],
  180. [{"B","2"}],
  181. {ok, [{"B","1"}, "C"]}};
  182. deps(pick_smallest1) ->
  183. {[{"B", [{"D", "1", []}]},
  184. {"C", [{"D", "2", []}]}],
  185. [{"D","2"}],
  186. %% we pick D1 because B < C
  187. {ok, ["B","C",{"D","1"}]}};
  188. deps(pick_smallest2) ->
  189. {[{"C", [{"D", "2", []}]},
  190. {"B", [{"D", "1", []}]}],
  191. [{"D","2"}],
  192. %% we pick D1 because B < C
  193. {ok, ["B","C",{"D","1"}]}};
  194. deps(circular1) ->
  195. {[{"B", [{"A", []}]}, % A is the top-level app
  196. {"C", []}],
  197. [],
  198. {error, {rebar_prv_install_deps, {cycles, [[<<"A">>,<<"B">>]]}}}};
  199. deps(circular2) ->
  200. {[{"B", [{"C", [{"B", []}]}]},
  201. {"C", []}],
  202. [],
  203. {error, {rebar_prv_install_deps, {cycles, [[<<"B">>,<<"C">>]]}}}};
  204. deps(circular_skip) ->
  205. %% Never spot the circular dep due to being to low in the deps tree
  206. %% in source deps
  207. {[{"B", [{"C", "2", [{"B", []}]}]},
  208. {"C", "1", [{"D",[]}]}],
  209. [{"C","2"}],
  210. {ok, ["B", {"C","1"}, "D"]}}.
  211. setup_project(Case, Config0, Deps) ->
  212. DepsType = ?config(deps_type, Config0),
  213. Config = rebar_test_utils:init_rebar_state(
  214. Config0,
  215. atom_to_list(Case)++"_"++atom_to_list(DepsType)++"_"
  216. ),
  217. AppDir = ?config(apps, Config),
  218. rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]),
  219. TopDeps = rebar_test_utils:top_level_deps(Deps),
  220. RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
  221. {SrcDeps, PkgDeps} = rebar_test_utils:flat_deps(Deps),
  222. mock_git_resource:mock([{deps, SrcDeps}]),
  223. mock_pkg_resource:mock([{pkgdeps, PkgDeps}]),
  224. [{rebarconfig, RebarConf} | Config].
  225. mock_warnings() ->
  226. %% just let it do its thing, we check warnings through
  227. %% the call log.
  228. meck:new(rebar_log, [no_link, passthrough]).
  229. %%% TESTS %%%
  230. flat(Config) -> run(Config).
  231. pick_highest_left(Config) -> run(Config).
  232. pick_highest_right(Config) -> run(Config).
  233. pick_smallest1(Config) -> run(Config).
  234. pick_smallest2(Config) -> run(Config).
  235. circular1(Config) -> run(Config).
  236. circular2(Config) -> run(Config).
  237. circular_skip(Config) -> run(Config).
  238. %% Test that a top-level application overtakes dependencies, and
  239. %% works even if said deps do not exist.
  240. top_override(Config) ->
  241. AppDir = ?config(apps, Config),
  242. ct:pal("dir: ~p", [AppDir]),
  243. Name1 = rebar_test_utils:create_random_name("sub_app1_"),
  244. Name2 = rebar_test_utils:create_random_name("sub_app2_"),
  245. SubAppsDir1 = filename:join([AppDir, "apps", Name1]),
  246. SubAppsDir2 = filename:join([AppDir, "apps", Name2]),
  247. Vsn = rebar_test_utils:create_random_vsn(),
  248. rebar_test_utils:create_app(SubAppsDir1, Name1, Vsn, [kernel, stdlib]),
  249. rebar_test_utils:create_app(SubAppsDir2, Name2, Vsn, [kernel, stdlib]),
  250. rebar_test_utils:create_config(
  251. SubAppsDir1,
  252. [{deps, [list_to_atom(Name2)]}]
  253. ),
  254. rebar_test_utils:create_config(
  255. SubAppsDir2,
  256. [{deps, [{list_to_atom(Name1),
  257. {git, "https://example.org", {branch, "master"}}}]}]
  258. ),
  259. rebar_test_utils:run_and_check(
  260. Config, [], ["compile"],
  261. {ok, [{app, Name1}, {app,Name2}]}
  262. ).
  263. %% Test that the deps of project apps that have their own rebar.config
  264. %% are included, but that top level rebar.config deps take precedence
  265. sub_app_deps(Config) ->
  266. AppDir = ?config(apps, Config),
  267. Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  268. ,{"b", "1.0.0", []}
  269. ,{"b", "2.0.0", []}]),
  270. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  271. mock_git_resource:mock([{deps, SrcDeps}]),
  272. Name = rebar_test_utils:create_random_name("sub_app1_"),
  273. Vsn = rebar_test_utils:create_random_vsn(),
  274. SubAppsDir = filename:join([AppDir, "apps", Name]),
  275. SubDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  276. ,{"b", "2.0.0", []}])),
  277. rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
  278. rebar_test_utils:create_config(SubAppsDir, [{deps, SubDeps}]),
  279. TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
  280. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])),
  281. rebar_test_utils:run_and_check(
  282. Config, RebarConfig, ["compile"],
  283. {ok, [{app, Name}, {dep, "a"}, {dep, "b", "1.0.0"}]}).
  284. %% Newly added dependency after locking
  285. newly_added_dep(Config) ->
  286. AppDir = ?config(apps, Config),
  287. Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  288. ,{"b", "1.0.0", [{"c", "1.0.0", []}]}
  289. ,{"c", "2.0.0", []}]),
  290. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  291. mock_git_resource:mock([{deps, SrcDeps}]),
  292. Name = rebar_test_utils:create_random_name("app_"),
  293. Vsn = rebar_test_utils:create_random_vsn(),
  294. SubAppsDir = filename:join([AppDir, "apps", Name]),
  295. rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
  296. TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
  297. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])),
  298. rebar_test_utils:run_and_check(
  299. Config, RebarConfig, ["compile"],
  300. {ok, [{app, Name}, {dep, "b", "1.0.0"}, {dep, "c", "1.0.0"}]}),
  301. %% Add a and c to top level
  302. TopDeps2 = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
  303. ,{"c", "2.0.0", []}
  304. ,{"b", "1.0.0", []}])),
  305. {ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])),
  306. LockFile = filename:join(AppDir, "rebar.lock"),
  307. RebarConfig3 = rebar_config:merge_locks(RebarConfig2,
  308. rebar_config:consult_lock_file(LockFile)),
  309. %% a should now be installed and c should not change
  310. rebar_test_utils:run_and_check(
  311. Config, RebarConfig3, ["compile"],
  312. {ok, [{app, Name}, {dep, "a"}, {dep, "b", "1.0.0"}, {dep, "c", "1.0.0"}]}).
  313. newly_added_after_empty_lock(Config) ->
  314. AppDir = ?config(apps, Config),
  315. Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]),
  316. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  317. mock_git_resource:mock([{deps, SrcDeps}]),
  318. Name = rebar_test_utils:create_random_name("app_"),
  319. Vsn = rebar_test_utils:create_random_vsn(),
  320. SubAppsDir = filename:join([AppDir, "apps", Name]),
  321. rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
  322. TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [])),
  323. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])),
  324. rebar_test_utils:run_and_check(
  325. Config, RebarConfig, ["compile"],
  326. {ok, []}),
  327. %% Add a and c to top level
  328. TopDeps2 = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}])),
  329. {ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])),
  330. LockFile = filename:join(AppDir, "rebar.lock"),
  331. RebarConfig3 = rebar_config:merge_locks(RebarConfig2,
  332. rebar_config:consult_lock_file(LockFile)),
  333. %% a should now be installed and c should not change
  334. rebar_test_utils:run_and_check(
  335. Config, RebarConfig3, ["compile"],
  336. {ok, [{app, Name}, {dep, "a", "1.0.0"}]}).
  337. http_proxy_settings(_Config) ->
  338. %% Load config
  339. rebar_utils:set_httpc_options(),
  340. rebar3:init_config(),
  341. %% Assert variable is right
  342. ?assertEqual({ok,{{"localhost", 1234}, []}},
  343. httpc:get_option(proxy, rebar)).
  344. https_proxy_settings(_Config) ->
  345. %% Load config
  346. rebar_utils:set_httpc_options(),
  347. rebar3:init_config(),
  348. %% Assert variable is right
  349. ?assertEqual({ok,{{"localhost", 1234}, []}},
  350. httpc:get_option(https_proxy, rebar)).
  351. http_os_proxy_settings(_Config) ->
  352. %% Load config
  353. rebar_utils:set_httpc_options(),
  354. rebar3:init_config(),
  355. %% Assert variable is right
  356. ?assertEqual({ok,{{"localhost", 1234}, []}},
  357. httpc:get_option(proxy, rebar)).
  358. https_os_proxy_settings(_Config) ->
  359. %% Load config
  360. rebar_utils:set_httpc_options(),
  361. rebar3:init_config(),
  362. %% Assert variable is right
  363. ?assertEqual({ok,{{"localhost", 1234}, []}},
  364. httpc:get_option(https_proxy, rebar)).
  365. semver_matching_lt(_Config) ->
  366. Dep = <<"test">>,
  367. Dep1 = {Dep, <<"1.0.0">>, Dep, Dep},
  368. MaxVsn = <<"0.2.0">>,
  369. Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
  370. ?assertEqual([{Dep, {pkg, Dep, <<"0.1.9">>, undefined}}],
  371. rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
  372. fun ec_semver:lt/2)).
  373. semver_matching_lte(_Config) ->
  374. Dep = <<"test">>,
  375. Dep1 = {Dep, <<"1.0.0">>, Dep, Dep},
  376. MaxVsn = <<"0.2.0">>,
  377. Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
  378. ?assertEqual([{Dep, {pkg, Dep, <<"0.2.0">>, undefined}}],
  379. rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
  380. fun ec_semver:lte/2)).
  381. semver_matching_gt(_Config) ->
  382. Dep = <<"test">>,
  383. Dep1 = {Dep, <<"1.0.0">>, Dep, Dep},
  384. MaxVsn = <<"0.2.0">>,
  385. Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
  386. ?assertEqual([{Dep, {pkg, Dep, <<"0.2.1">>, undefined}}],
  387. rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
  388. fun ec_semver:gt/2)).
  389. semver_matching_gte(_Config) ->
  390. Dep = <<"test">>,
  391. Dep1 = {Dep, <<"1.0.0">>, Dep, Dep},
  392. MaxVsn = <<"0.2.0">>,
  393. Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>],
  394. ?assertEqual([{Dep, {pkg, Dep, <<"0.2.0">>, undefined}}],
  395. rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
  396. fun ec_semver:gt/2)).
  397. valid_version(_Config) ->
  398. ?assert(rebar_prv_update:valid_vsn(<<"0.1">>)),
  399. ?assert(rebar_prv_update:valid_vsn(<<"0.1.0">>)),
  400. ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
  401. ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
  402. ?assert(rebar_prv_update:valid_vsn(<<"<0.1">>)),
  403. ?assert(rebar_prv_update:valid_vsn(<<"<0.1.0">>)),
  404. ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
  405. ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
  406. ?assert(rebar_prv_update:valid_vsn(<<">0.1">>)),
  407. ?assert(rebar_prv_update:valid_vsn(<<">0.1.0">>)),
  408. ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
  409. ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
  410. ?assert(rebar_prv_update:valid_vsn(<<"<=0.1">>)),
  411. ?assert(rebar_prv_update:valid_vsn(<<"<=0.1.0">>)),
  412. ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
  413. ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
  414. ?assert(rebar_prv_update:valid_vsn(<<">=0.1">>)),
  415. ?assert(rebar_prv_update:valid_vsn(<<">=0.1.0">>)),
  416. ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
  417. ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
  418. ?assert(rebar_prv_update:valid_vsn(<<"==0.1">>)),
  419. ?assert(rebar_prv_update:valid_vsn(<<"==0.1.0">>)),
  420. ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
  421. ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
  422. ?assert(rebar_prv_update:valid_vsn(<<"~>0.1">>)),
  423. ?assert(rebar_prv_update:valid_vsn(<<"~>0.1.0">>)),
  424. ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
  425. ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
  426. ?assertNot(rebar_prv_update:valid_vsn(<<"> 0.1.0 and < 0.2.0">>)),
  427. ok.
  428. run(Config) ->
  429. {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
  430. rebar_test_utils:run_and_check(
  431. Config, RebarConfig, ["install_deps"], ?config(expect, Config)
  432. ),
  433. check_warnings(warning_calls(), ?config(warnings, Config), ?config(deps_type, Config)).
  434. warning_calls() ->
  435. History = meck:history(rebar_log),
  436. [{Str, Args} || {_, {rebar_log, log, [warn, Str, Args]}, _} <- History].
  437. check_warnings(_, [], _) ->
  438. ok;
  439. check_warnings(Warns, [{Name, Vsn} | Rest], Type) ->
  440. ct:pal("Checking for warning ~p in ~p", [{Name,Vsn},Warns]),
  441. ?assert(in_warnings(Type, Warns, Name, Vsn)),
  442. check_warnings(Warns, Rest, Type).
  443. in_warnings(git, Warns, NameRaw, VsnRaw) ->
  444. Name = iolist_to_binary(NameRaw),
  445. 1 =< length([1 || {_, [AppName, {git, _, {_, Vsn}}]} <- Warns,
  446. AppName =:= Name, Vsn =:= VsnRaw]);
  447. in_warnings(pkg, Warns, NameRaw, VsnRaw) ->
  448. Name = iolist_to_binary(NameRaw),
  449. Vsn = iolist_to_binary(VsnRaw),
  450. 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn, _}]} <- Warns,
  451. AppName =:= Name, AppVsn =:= Vsn]).