Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

2179 righe
85 KiB

10 anni fa
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 anni fa
10 anni fa
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 anni fa
10 anni fa
10 anni fa
10 anni fa
10 anni fa
10 anni fa
10 anni fa
10 anni fa
10 anni fa
support for hex v2, multiple repository fetching, private organizations (#1884) * update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
6 anni fa
  1. -module(rebar_compile_SUITE).
  2. -compile(export_all).
  3. -include_lib("common_test/include/ct.hrl").
  4. -include_lib("eunit/include/eunit.hrl").
  5. -include_lib("kernel/include/file.hrl").
  6. suite() ->
  7. [].
  8. all() ->
  9. [{group, basic_app}, {group, release_apps},
  10. {group, checkout_apps}, {group, checkout_deps},
  11. {group, basic_srcdirs}, {group, release_srcdirs}, {group, unbalanced_srcdirs},
  12. {group, basic_extras}, {group, release_extras}, {group, unbalanced_extras},
  13. {group, root_extras},
  14. recompile_when_hrl_changes, recompile_when_included_hrl_changes,
  15. recompile_when_opts_included_hrl_changes,
  16. recompile_when_opts_change,
  17. dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl,
  18. delete_beam_if_source_deleted,
  19. deps_in_path, checkout_priority, highest_version_of_pkg_dep,
  20. parse_transform_test, erl_first_files_test, mib_test,
  21. umbrella_mib_first_test, only_default_transitive_deps, clean_all,
  22. profile_deps, deps_build_in_prod, only_deps,
  23. override_deps, override_add_deps, override_del_deps,
  24. override_opts, override_add_opts, override_del_opts,
  25. apply_overrides_exactly_once,
  26. profile_override_deps, profile_override_add_deps, profile_override_del_deps,
  27. profile_override_opts, profile_override_add_opts, profile_override_del_opts,
  28. include_file_relative_to_working_directory, include_file_in_src,
  29. include_file_relative_to_working_directory_test, include_file_in_src_test,
  30. include_file_in_src_test_multiapp,
  31. recompile_when_parse_transform_as_opt_changes,
  32. recompile_when_parse_transform_inline_changes,
  33. regex_filter_skip, regex_filter_regression,
  34. recursive, no_recursive,
  35. always_recompile_when_erl_compiler_options_set,
  36. dont_recompile_when_erl_compiler_options_env_does_not_change,
  37. recompile_when_erl_compiler_options_env_changes,
  38. rebar_config_os_var].
  39. groups() ->
  40. [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
  41. {release_apps, [], [build_release_apps, paths_release_apps, clean_release_apps]},
  42. {checkout_apps, [], [build_checkout_apps, paths_checkout_apps]},
  43. {checkout_deps, [], [build_checkout_deps, paths_checkout_deps]},
  44. {basic_srcdirs, [], [build_basic_srcdirs, paths_basic_srcdirs]},
  45. {release_srcdirs, [], [build_release_srcdirs,
  46. paths_release_srcdirs]},
  47. {unbalanced_srcdirs, [], [build_unbalanced_srcdirs,
  48. paths_unbalanced_srcdirs]},
  49. {basic_extras, [], [build_basic_extra_dirs,
  50. paths_basic_extra_dirs,
  51. clean_basic_extra_dirs]},
  52. {release_extras, [], [build_release_extra_dirs,
  53. paths_release_extra_dirs,
  54. clean_release_extra_dirs]},
  55. {unbalanced_extras, [], [build_unbalanced_extra_dirs,
  56. paths_unbalanced_extra_dirs]},
  57. {root_extras, [], [build_extra_dirs_in_project_root,
  58. paths_extra_dirs_in_project_root,
  59. clean_extra_dirs_in_project_root]}].
  60. init_per_group(basic_app, Config) ->
  61. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_app_"),
  62. AppDir = ?config(apps, NewConfig),
  63. Name = rebar_test_utils:create_random_name("app1"),
  64. Vsn = rebar_test_utils:create_random_vsn(),
  65. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  66. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  67. init_per_group(release_apps, Config) ->
  68. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_apps_"),
  69. AppDir = ?config(apps, NewConfig),
  70. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  71. Vsn1 = rebar_test_utils:create_random_vsn(),
  72. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]),
  73. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  74. Vsn2 = rebar_test_utils:create_random_vsn(),
  75. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
  76. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  77. init_per_group(checkout_apps, Config) ->
  78. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_apps_"),
  79. AppDir = ?config(apps, NewConfig),
  80. CheckoutsDir = ?config(checkouts, NewConfig),
  81. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  82. Vsn1 = rebar_test_utils:create_random_vsn(),
  83. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  84. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  85. Vsn2 = rebar_test_utils:create_random_vsn(),
  86. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  87. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  88. init_per_group(checkout_deps, Config) ->
  89. NewConfig = rebar_test_utils:init_rebar_state(Config, "checkout_deps_"),
  90. AppDir = ?config(apps, NewConfig),
  91. CheckoutsDir = ?config(checkouts, NewConfig),
  92. DepsDir = filename:join([AppDir, "_build", "default", "lib"]),
  93. Name1 = rebar_test_utils:create_random_name("checkapp1_"),
  94. Vsn1 = rebar_test_utils:create_random_vsn(),
  95. rebar_test_utils:create_app(AppDir, Name1, Vsn1, [kernel, stdlib]),
  96. Name2 = rebar_test_utils:create_random_name("checkapp2_"),
  97. Vsn2 = rebar_test_utils:create_random_vsn(),
  98. rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
  99. rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]),
  100. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  101. init_per_group(Group, Config) when Group == basic_srcdirs; Group == basic_extras ->
  102. NewConfig = rebar_test_utils:init_rebar_state(Config, "basic_srcdirs_"),
  103. AppDir = ?config(apps, NewConfig),
  104. Name = rebar_test_utils:create_random_name("app1_"),
  105. Vsn = rebar_test_utils:create_random_vsn(),
  106. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  107. ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
  108. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  109. ok = file:write_file(filename:join([AppDir, "extra", io_lib:format("~ts_extra.erl", [Name])]),
  110. ExtraSrc),
  111. [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
  112. init_per_group(Group, Config) when Group == release_srcdirs; Group == release_extras ->
  113. NewConfig = rebar_test_utils:init_rebar_state(Config, "release_srcdirs_"),
  114. AppDir = ?config(apps, NewConfig),
  115. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  116. Vsn1 = rebar_test_utils:create_random_vsn(),
  117. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  118. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  119. Vsn2 = rebar_test_utils:create_random_vsn(),
  120. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  121. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  122. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  123. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  124. io_lib:format("~ts_extra.erl", [Name1])]),
  125. ExtraOne),
  126. ExtraTwo = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name2]),
  127. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "extra", "dummy"])),
  128. ok = file:write_file(filename:join([AppDir, "apps", Name2, "extra",
  129. io_lib:format("~ts_extra.erl", [Name2])]),
  130. ExtraTwo),
  131. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  132. init_per_group(Group, Config) when Group == unbalanced_srcdirs; Group == unbalanced_extras ->
  133. NewConfig = rebar_test_utils:init_rebar_state(Config, "unbalanced_srcdirs_"),
  134. AppDir = ?config(apps, NewConfig),
  135. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  136. Vsn1 = rebar_test_utils:create_random_vsn(),
  137. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  138. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  139. Vsn2 = rebar_test_utils:create_random_vsn(),
  140. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  141. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  142. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  143. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  144. io_lib:format("~ts_extra.erl", [Name1])]),
  145. ExtraOne),
  146. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
  147. init_per_group(root_extras, Config) ->
  148. NewConfig = rebar_test_utils:init_rebar_state(Config, "root_extras_"),
  149. AppDir = ?config(apps, NewConfig),
  150. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  151. Vsn1 = rebar_test_utils:create_random_vsn(),
  152. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  153. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  154. Vsn2 = rebar_test_utils:create_random_vsn(),
  155. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  156. Extra = <<"-module(extra).\n-export([ok/0]).\nok() -> ok.\n">>,
  157. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  158. ok = file:write_file(filename:join([AppDir, "extra", "extra.erl"]), Extra),
  159. [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig].
  160. end_per_group(_Group, _Config) ->
  161. ok.
  162. init_per_suite(Config) ->
  163. Config.
  164. end_per_suite(_Config) ->
  165. ok.
  166. init_per_testcase(Test, Config) when
  167. Test == dont_recompile_when_erl_compiler_options_env_does_not_change
  168. orelse
  169. Test == recompile_when_erl_compiler_options_env_changes ->
  170. _ = code:ensure_loaded(os),
  171. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  172. _ = code:ensure_loaded(compile),
  173. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  174. case {UnSetEnv, EnvOpts} of
  175. {true, true} -> maybe_init_config(Config);
  176. _ -> {skip, "compile:env_compiler_options/0 unavailable"}
  177. end;
  178. init_per_testcase(always_recompile_when_erl_compiler_options_set, Config) ->
  179. _ = code:ensure_loaded(os),
  180. UnSetEnv = erlang:function_exported(os, unsetenv, 1),
  181. _ = code:ensure_loaded(compile),
  182. EnvOpts = erlang:function_exported(compile, env_compiler_options, 0),
  183. case {UnSetEnv, EnvOpts} of
  184. {true, true} -> {skip, "compile:env_compiler_options/0 available"};
  185. {true, false} -> maybe_init_config(Config);
  186. _ -> {skip, "os:unsetenv/1 unavailable"}
  187. end;
  188. init_per_testcase(_, Config) -> maybe_init_config(Config).
  189. maybe_init_config(Config) ->
  190. case ?config(apps, Config) of
  191. undefined -> rebar_test_utils:init_rebar_state(Config);
  192. _ -> Config
  193. end.
  194. end_per_testcase(_, _Config) ->
  195. catch meck:unload().
  196. %% test cases
  197. build_basic_app(Config) ->
  198. [Name] = ?config(app_names, Config),
  199. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
  200. build_release_apps(Config) ->
  201. [Name1, Name2] = ?config(app_names, Config),
  202. rebar_test_utils:run_and_check(
  203. Config, [], ["compile"],
  204. {ok, [{app, Name1}, {app, Name2}]}
  205. ).
  206. build_checkout_apps(Config) ->
  207. [Name1, Name2] = ?config(app_names, Config),
  208. rebar_test_utils:run_and_check(
  209. Config, [], ["compile"],
  210. {ok, [{app, Name1}, {checkout, Name2}]}
  211. ).
  212. build_checkout_deps(Config) ->
  213. AppDir = ?config(apps, Config),
  214. [Name1, Name2] = ?config(app_names, Config),
  215. [_, Vsn2] = ?config(vsns, Config),
  216. Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}],
  217. {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])),
  218. rebar_test_utils:run_and_check(
  219. Config, RebarConfig, ["compile"],
  220. {ok, [{app, Name1}, {checkout, Name2}]}
  221. ).
  222. build_basic_srcdirs(Config) ->
  223. AppDir = ?config(apps, Config),
  224. [Name] = ?config(app_names, Config),
  225. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  226. %% check a beam corresponding to the src in the extra src_dir exists
  227. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  228. io_lib:format("~ts_extra.beam", [Name])]),
  229. %% check the extra src_dir was copied/linked into the _build dir
  230. ExtraDir = filename:join([AppDir, "_build", "default", "lib", Name, "extra"]),
  231. rebar_test_utils:run_and_check(
  232. Config, RebarConfig, ["compile"],
  233. {ok, [{app, Name}, {file, ExtraBeam}, {dir, ExtraDir}]}
  234. ).
  235. build_release_srcdirs(Config) ->
  236. AppDir = ?config(apps, Config),
  237. [Name1, Name2] = ?config(app_names, Config),
  238. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  239. %% check a beam corresponding to the src in the extra src_dir exists
  240. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  241. io_lib:format("~ts_extra.beam", [Name1])]),
  242. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  243. io_lib:format("~ts_extra.beam", [Name2])]),
  244. %% check the extra src_dir was copied/linked into the _build dir
  245. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  246. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  247. rebar_test_utils:run_and_check(
  248. Config, RebarConfig, ["compile"],
  249. {ok, [{app, Name1}, {app, Name2},
  250. {file, Extra1Beam}, {file, Extra2Beam},
  251. {dir, Extra1Dir}, {dir, Extra2Dir}]}
  252. ).
  253. build_unbalanced_srcdirs(Config) ->
  254. AppDir = ?config(apps, Config),
  255. [Name1, Name2] = ?config(app_names, Config),
  256. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  257. %% check a beam corresponding to the src in the extra src_dir exists
  258. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  259. io_lib:format("~ts_extra.beam", [Name1])]),
  260. %% check the extra src_dir was copied/linked into the _build dir
  261. Extra1Dir = filename:join([AppDir, "_build", "default", "lib", Name1, "extra"]),
  262. rebar_test_utils:run_and_check(
  263. Config, RebarConfig, ["compile"],
  264. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {dir, Extra1Dir}]}
  265. ),
  266. %% check no extra src_dir were copied/linked into the _build dir
  267. Extra2Dir = filename:join([AppDir, "_build", "default", "lib", Name2, "extra"]),
  268. false = filelib:is_dir(Extra2Dir),
  269. %% check only expected beams are in the ebin dir
  270. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  271. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  272. Files).
  273. build_basic_extra_dirs(Config) ->
  274. AppDir = ?config(apps, Config),
  275. [Name] = ?config(app_names, Config),
  276. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  277. %% check a beam corresponding to the src in the extra src_dir exists
  278. ExtraBeam = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  279. io_lib:format("~ts_extra.beam", [Name])]),
  280. rebar_test_utils:run_and_check(
  281. Config, RebarConfig, ["compile"],
  282. {ok, [{app, Name}, {file, ExtraBeam}]}
  283. ).
  284. build_release_extra_dirs(Config) ->
  285. AppDir = ?config(apps, Config),
  286. [Name1, Name2] = ?config(app_names, Config),
  287. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  288. %% check a beam corresponding to the src in the extra src_dir exists
  289. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  290. io_lib:format("~ts_extra.beam", [Name1])]),
  291. Extra2Beam = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  292. io_lib:format("~ts_extra.beam", [Name2])]),
  293. rebar_test_utils:run_and_check(
  294. Config, RebarConfig, ["compile"],
  295. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}, {file, Extra2Beam}]}
  296. ).
  297. build_unbalanced_extra_dirs(Config) ->
  298. AppDir = ?config(apps, Config),
  299. [Name1, Name2] = ?config(app_names, Config),
  300. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  301. %% check a beam corresponding to the src in the extra src_dir exists
  302. Extra1Beam = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  303. io_lib:format("~ts_extra.beam", [Name1])]),
  304. rebar_test_utils:run_and_check(
  305. Config, RebarConfig, ["compile"],
  306. {ok, [{app, Name1}, {app, Name2}, {file, Extra1Beam}]}
  307. ),
  308. %% check no extra src_dir were copied/linked into the _build dir
  309. false = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "extra"])),
  310. %% check only expected beams are in the ebin dir
  311. {ok, Files} = rebar_utils:list_dir(filename:join([AppDir, "_build", "default", "lib", Name2, "ebin"])),
  312. lists:all(fun(Beam) -> lists:member(Beam, [Name2 ++ ".app", "not_a_real_src_" ++ Name2 ++ ".beam"]) end,
  313. Files).
  314. build_extra_dirs_in_project_root(Config) ->
  315. AppDir = ?config(apps, Config),
  316. [Name1, Name2] = ?config(app_names, Config),
  317. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  318. %% check a beam corresponding to the src in the extra src_dir exists
  319. ExtraBeam = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  320. rebar_test_utils:run_and_check(
  321. Config, RebarConfig, ["compile"],
  322. {ok, [{app, Name1}, {app, Name2}, {file, ExtraBeam}]}
  323. ).
  324. paths_basic_app(Config) ->
  325. [Name] = ?config(app_names, Config),
  326. [Vsn] = ?config(vsns, Config),
  327. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  328. code:add_paths(rebar_state:code_paths(State, all_deps)),
  329. ok = application:load(list_to_atom(Name)),
  330. Loaded = application:loaded_applications(),
  331. {_, _, Vsn} = lists:keyfind(list_to_atom(Name), 1, Loaded).
  332. paths_release_apps(Config) ->
  333. [Name1, Name2] = ?config(app_names, Config),
  334. [Vsn1, Vsn2] = ?config(vsns, Config),
  335. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  336. code:add_paths(rebar_state:code_paths(State, all_deps)),
  337. ok = application:load(list_to_atom(Name1)),
  338. ok = application:load(list_to_atom(Name2)),
  339. Loaded = application:loaded_applications(),
  340. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded),
  341. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  342. paths_checkout_apps(Config) ->
  343. [Name1, _Name2] = ?config(app_names, Config),
  344. [Vsn1, _Vsn2] = ?config(vsns, Config),
  345. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
  346. code:add_paths(rebar_state:code_paths(State, all_deps)),
  347. ok = application:load(list_to_atom(Name1)),
  348. Loaded = application:loaded_applications(),
  349. {_, _, Vsn1} = lists:keyfind(list_to_atom(Name1), 1, Loaded).
  350. paths_checkout_deps(Config) ->
  351. AppDir = ?config(apps, Config),
  352. [_Name1, Name2] = ?config(app_names, Config),
  353. [_Vsn1, Vsn2] = ?config(vsns, Config),
  354. %% rebar_test_utils:init_rebar_state/1,2 uses rebar_state:new/3 which
  355. %% maybe incorrectly sets deps to [] (based on `rebar.lock`) instead of
  356. %% to the checkapps
  357. %% until that is sorted out the lock file has to be removed before
  358. %% this test will pass
  359. file:delete(filename:join([AppDir, "rebar.lock"])),
  360. {ok, RebarConfig} = file:consult(filename:join([AppDir, "rebar.config"])),
  361. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  362. code:add_paths(rebar_state:code_paths(State, all_deps)),
  363. ok = application:load(list_to_atom(Name2)),
  364. Loaded = application:loaded_applications(),
  365. {_, _, Vsn2} = lists:keyfind(list_to_atom(Name2), 1, Loaded).
  366. paths_basic_srcdirs(Config) ->
  367. AppDir = ?config(apps, Config),
  368. [Name] = ?config(app_names, Config),
  369. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  370. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  371. code:add_paths(rebar_state:code_paths(State, all_deps)),
  372. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  373. {module, Mod} = code:ensure_loaded(Mod),
  374. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "ebin",
  375. io_lib:format("~ts_extra.beam", [Name])]),
  376. Expect = code:which(Mod).
  377. paths_release_srcdirs(Config) ->
  378. AppDir = ?config(apps, Config),
  379. [Name1, Name2] = ?config(app_names, Config),
  380. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  381. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  382. code:add_paths(rebar_state:code_paths(State, all_deps)),
  383. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  384. {module, Mod1} = code:ensure_loaded(Mod1),
  385. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  386. {module, Mod2} = code:ensure_loaded(Mod2),
  387. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  388. io_lib:format("~ts_extra.beam", [Name1])]),
  389. ExpectOne = code:which(Mod1),
  390. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin",
  391. io_lib:format("~ts_extra.beam", [Name2])]),
  392. ExpectTwo = code:which(Mod2).
  393. paths_unbalanced_srcdirs(Config) ->
  394. AppDir = ?config(apps, Config),
  395. [Name1, Name2] = ?config(app_names, Config),
  396. RebarConfig = [{erl_opts, [{src_dirs, ["src", "extra"]}]}],
  397. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  398. code:add_paths(rebar_state:code_paths(State, all_deps)),
  399. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  400. {module, Mod1} = code:ensure_loaded(Mod1),
  401. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  402. {error, nofile} = code:ensure_loaded(Mod2),
  403. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin",
  404. io_lib:format("~ts_extra.beam", [Name1])]),
  405. ExpectOne = code:which(Mod1).
  406. paths_basic_extra_dirs(Config) ->
  407. AppDir = ?config(apps, Config),
  408. [Name] = ?config(app_names, Config),
  409. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  410. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  411. code:add_paths(rebar_state:code_paths(State, all_deps)),
  412. Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  413. {module, Mod} = code:ensure_loaded(Mod),
  414. Expect = filename:join([AppDir, "_build", "default", "lib", Name, "extra",
  415. io_lib:format("~ts_extra.beam", [Name])]),
  416. Expect = code:which(Mod).
  417. paths_release_extra_dirs(Config) ->
  418. AppDir = ?config(apps, Config),
  419. [Name1, Name2] = ?config(app_names, Config),
  420. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  421. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  422. code:add_paths(rebar_state:code_paths(State, all_deps)),
  423. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  424. {module, Mod1} = code:ensure_loaded(Mod1),
  425. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  426. {module, Mod2} = code:ensure_loaded(Mod2),
  427. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  428. io_lib:format("~ts_extra.beam", [Name1])]),
  429. ExpectOne = code:which(Mod1),
  430. ExpectTwo = filename:join([AppDir, "_build", "default", "lib", Name2, "extra",
  431. io_lib:format("~ts_extra.beam", [Name2])]),
  432. ExpectTwo = code:which(Mod2).
  433. paths_unbalanced_extra_dirs(Config) ->
  434. AppDir = ?config(apps, Config),
  435. [Name1, Name2] = ?config(app_names, Config),
  436. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  437. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  438. code:add_paths(rebar_state:code_paths(State, all_deps)),
  439. Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  440. {module, Mod1} = code:ensure_loaded(Mod1),
  441. Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  442. {error, nofile} = code:ensure_loaded(Mod2),
  443. ExpectOne = filename:join([AppDir, "_build", "default", "lib", Name1, "extra",
  444. io_lib:format("~ts_extra.beam", [Name1])]),
  445. ExpectOne = code:which(Mod1).
  446. paths_extra_dirs_in_project_root(Config) ->
  447. AppDir = ?config(apps, Config),
  448. RebarConfig = [{erl_opts, [{extra_src_dirs, ["extra"]}]}],
  449. {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
  450. code:add_paths(rebar_state:code_paths(State, all_deps)),
  451. {module, extra} = code:ensure_loaded(extra),
  452. Expect = filename:join([AppDir, "_build", "default", "extras", "extra", "extra.beam"]),
  453. Expect = code:which(extra).
  454. clean_basic_app(Config) ->
  455. [Name] = ?config(app_names, Config),
  456. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}).
  457. clean_release_apps(Config) ->
  458. [Name1, Name2] = ?config(app_names, Config),
  459. rebar_test_utils:run_and_check(Config, [], ["clean"],
  460. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}).
  461. clean_basic_extra_dirs(Config) ->
  462. AppDir = ?config(apps, Config),
  463. [Name] = ?config(app_names, Config),
  464. rebar_test_utils:run_and_check(Config, [], ["clean"], {ok, [{app, Name, invalid}]}),
  465. Beam = lists:flatten(io_lib:format("~ts_extra", [Name])),
  466. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name, "extras", Beam])).
  467. clean_release_extra_dirs(Config) ->
  468. AppDir = ?config(apps, Config),
  469. [Name1, Name2] = ?config(app_names, Config),
  470. rebar_test_utils:run_and_check(Config, [], ["clean"],
  471. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  472. Beam1 = lists:flatten(io_lib:format("~ts_extra", [Name1])),
  473. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name1, "extras", Beam1])),
  474. Beam2 = lists:flatten(io_lib:format("~ts_extra", [Name2])),
  475. false = ec_file:exists(filename:join([AppDir, "_build", "default", "lib", Name2, "extras", Beam2])).
  476. clean_extra_dirs_in_project_root(Config) ->
  477. AppDir = ?config(apps, Config),
  478. [Name1, Name2] = ?config(app_names, Config),
  479. rebar_test_utils:run_and_check(Config, [], ["clean"],
  480. {ok, [{app, Name1, invalid}, {app, Name2, invalid}]}),
  481. false = ec_file:exists(filename:join([AppDir, "_build", "default", "extras"])).
  482. recompile_when_hrl_changes(Config) ->
  483. AppDir = ?config(apps, Config),
  484. Name = rebar_test_utils:create_random_name("app1_"),
  485. Vsn = rebar_test_utils:create_random_vsn(),
  486. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  487. ExtraSrc = <<"-module(test_header_include).\n"
  488. "-export([main/0]).\n"
  489. "-include(\"test_header_include.hrl\").\n"
  490. "main() -> ?SOME_DEFINE.\n">>,
  491. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  492. HeaderFile = filename:join([AppDir, "src", "test_header_include.hrl"]),
  493. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  494. ok = file:write_file(HeaderFile, ExtraHeader),
  495. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  496. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  497. {ok, Files} = rebar_utils:list_dir(EbinDir),
  498. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  499. || F <- Files, filename:extension(F) == ".beam"],
  500. timer:sleep(1000),
  501. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  502. ok = file:write_file(HeaderFile, NewExtraHeader),
  503. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  504. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  505. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  506. || F <- NewFiles, filename:extension(F) == ".beam"],
  507. ?assert(ModTime =/= NewModTime).
  508. recompile_when_included_hrl_changes(Config) ->
  509. AppDir = ?config(apps, Config),
  510. Name = rebar_test_utils:create_random_name("app1_"),
  511. Vsn = rebar_test_utils:create_random_vsn(),
  512. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  513. ExtraSrc = <<"-module(test_header_include).\n"
  514. "-export([main/0]).\n"
  515. "-include(\"test_header_include.hrl\").\n"
  516. "main() -> ?SOME_DEFINE.\n">>,
  517. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  518. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  519. HeaderFile = filename:join([AppDir, "include", "test_header_include.hrl"]),
  520. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  521. ok = file:write_file(HeaderFile, ExtraHeader),
  522. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  523. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  524. {ok, Files} = rebar_utils:list_dir(EbinDir),
  525. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  526. || F <- Files, filename:extension(F) == ".beam"],
  527. timer:sleep(1000),
  528. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  529. ok = file:write_file(HeaderFile, NewExtraHeader),
  530. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  531. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  532. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  533. || F <- NewFiles, filename:extension(F) == ".beam"],
  534. ?assert(ModTime =/= NewModTime).
  535. recompile_when_opts_included_hrl_changes(Config) ->
  536. AppsDir = ?config(apps, Config),
  537. Name = rebar_test_utils:create_random_name("app1_"),
  538. Vsn = rebar_test_utils:create_random_vsn(),
  539. AppDir = filename:join([AppsDir, "apps", Name]),
  540. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  541. ExtraSrc = <<"-module(test_header_include).\n"
  542. "-export([main/0]).\n"
  543. "-include(\"test_header_include.hrl\").\n"
  544. "main() -> ?SOME_DEFINE.\n">>,
  545. ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>,
  546. ok = filelib:ensure_dir(filename:join([AppsDir, "include", "dummy"])),
  547. HeaderFile = filename:join([AppsDir, "include", "test_header_include.hrl"]),
  548. ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc),
  549. ok = file:write_file(HeaderFile, ExtraHeader),
  550. %% Using relative path from the project root
  551. RebarConfig = [{erl_opts, [{i, "include/"}]}],
  552. {ok,Cwd} = file:get_cwd(),
  553. ok = file:set_cwd(AppsDir),
  554. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  555. EbinDir = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
  556. {ok, Files} = rebar_utils:list_dir(EbinDir),
  557. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  558. || F <- Files, filename:extension(F) == ".beam"],
  559. timer:sleep(1000),
  560. NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>,
  561. ok = file:write_file(HeaderFile, NewExtraHeader),
  562. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  563. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  564. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  565. || F <- NewFiles, filename:extension(F) == ".beam"],
  566. ok = file:set_cwd(Cwd),
  567. ?assert(ModTime =/= NewModTime).
  568. recompile_when_opts_change(Config) ->
  569. AppDir = ?config(apps, Config),
  570. Name = rebar_test_utils:create_random_name("app1_"),
  571. Vsn = rebar_test_utils:create_random_vsn(),
  572. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  573. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  574. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  575. {ok, Files} = rebar_utils:list_dir(EbinDir),
  576. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  577. || F <- Files, filename:extension(F) == ".beam"],
  578. timer:sleep(1000),
  579. rebar_test_utils:create_config(AppDir, [{erl_opts, [{d, some_define}]}]),
  580. rebar_test_utils:run_and_check(Config, [{erl_opts, [{d, some_define}]}], ["compile"], {ok, [{app, Name}]}),
  581. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  582. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  583. || F <- NewFiles, filename:extension(F) == ".beam"],
  584. ?assert(ModTime =/= NewModTime).
  585. dont_recompile_when_opts_dont_change(Config) ->
  586. AppDir = ?config(apps, Config),
  587. Name = rebar_test_utils:create_random_name("app1_"),
  588. Vsn = rebar_test_utils:create_random_vsn(),
  589. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  590. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  591. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  592. {ok, Files} = rebar_utils:list_dir(EbinDir),
  593. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  594. || F <- Files, filename:extension(F) == ".beam"],
  595. timer:sleep(1000),
  596. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  597. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  598. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  599. || F <- NewFiles, filename:extension(F) == ".beam"],
  600. ?assertEqual(ModTime, NewModTime).
  601. dont_recompile_yrl_or_xrl(Config) ->
  602. AppDir = ?config(apps, Config),
  603. Name = rebar_test_utils:create_random_name("app1_"),
  604. Vsn = rebar_test_utils:create_random_vsn(),
  605. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  606. Xrl = filename:join([AppDir, "src", "not_a_real_xrl_" ++ Name ++ ".xrl"]),
  607. ok = filelib:ensure_dir(Xrl),
  608. XrlBody =
  609. "Definitions."
  610. "\n\n"
  611. "D = [0-9]"
  612. "\n\n"
  613. "Rules."
  614. "\n\n"
  615. "{D}+ :"
  616. " {token,{integer,TokenLine,list_to_integer(TokenChars)}}."
  617. "\n\n"
  618. "{D}+\\.{D}+((E|e)(\\+|\\-)?{D}+)? :"
  619. " {token,{float,TokenLine,list_to_float(TokenChars)}}."
  620. "\n\n"
  621. "Erlang code.",
  622. ok = ec_file:write(Xrl, XrlBody),
  623. XrlBeam = filename:join([AppDir, "ebin", filename:basename(Xrl, ".xrl") ++ ".beam"]),
  624. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  625. ModTime = filelib:last_modified(XrlBeam),
  626. timer:sleep(1000),
  627. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  628. NewModTime = filelib:last_modified(XrlBeam),
  629. ?assert(ModTime == NewModTime).
  630. delete_beam_if_source_deleted(Config) ->
  631. AppDir = ?config(apps, Config),
  632. Name = rebar_test_utils:create_random_name("app1_"),
  633. Vsn = rebar_test_utils:create_random_vsn(),
  634. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  635. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  636. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  637. _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]),
  638. ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))),
  639. file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])),
  640. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  641. ?assertNot(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))).
  642. deps_in_path(Config) ->
  643. AppDir = ?config(apps, Config),
  644. StartPaths = code:get_path(),
  645. Name = rebar_test_utils:create_random_name("app1_"),
  646. Vsn = rebar_test_utils:create_random_vsn(),
  647. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  648. DepName = rebar_test_utils:create_random_name("dep1_"),
  649. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  650. mock_git_resource:mock([]),
  651. mock_pkg_resource:mock([
  652. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  653. ]),
  654. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  655. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  656. {list_to_atom(PkgName), Vsn}
  657. ]}]),
  658. {ok, RConf} = file:consult(RConfFile),
  659. %% Make sure apps we look for are not visible
  660. %% Hope not to find src name
  661. ?assertEqual([], [Path || Path <- code:get_path(),
  662. {match, _} <- [re:run(Path, DepName)]]),
  663. %% Hope not to find pkg name in there
  664. ?assertEqual([], [Path || Path <- code:get_path(),
  665. {match, _} <- [re:run(Path, PkgName)]]),
  666. %% Build things
  667. {ok, State} = rebar_test_utils:run_and_check(
  668. Config, RConf, ["compile"],
  669. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  670. ),
  671. code:add_paths(rebar_state:code_paths(State, all_deps)),
  672. %% Find src name in there
  673. ?assertNotEqual([], [Path || Path <- code:get_path(),
  674. {match, _} <- [re:run(Path, DepName)]]),
  675. %% find pkg name in there
  676. ?assertNotEqual([], [Path || Path <- code:get_path(),
  677. {match, _} <- [re:run(Path, PkgName)]]),
  678. true = code:set_path(lists:filter(fun(P) -> ec_file:exists(P) end, StartPaths)),
  679. %% Make sure apps we look for are not visible again
  680. %% Hope not to find src name
  681. ?assertEqual([], [Path || Path <- code:get_path(),
  682. {match, _} <- [re:run(Path, DepName)]]),
  683. %% Hope not to find pkg name in there
  684. ?assertEqual([], [Path || Path <- code:get_path(),
  685. {match, _} <- [re:run(Path, PkgName)]]),
  686. %% Rebuild
  687. {ok, State1} = rebar_test_utils:run_and_check(
  688. Config, RConf, ["compile"],
  689. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  690. ),
  691. %% Find src name in there
  692. code:add_paths(rebar_state:code_paths(State1, all_deps)),
  693. ?assertNotEqual([], [Path || Path <- code:get_path(),
  694. {match, _} <- [re:run(Path, DepName)]]),
  695. %% find pkg name in there
  696. ?assertNotEqual([], [Path || Path <- code:get_path(),
  697. {match, _} <- [re:run(Path, PkgName)]]).
  698. checkout_priority(Config) ->
  699. AppDir = ?config(apps, Config),
  700. CheckoutsDir = ?config(checkouts, Config),
  701. StartPaths = code:get_path(),
  702. Name = rebar_test_utils:create_random_name("app1_"),
  703. Vsn = rebar_test_utils:create_random_vsn(),
  704. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  705. DepName = rebar_test_utils:create_random_name("dep1_"),
  706. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  707. mock_git_resource:mock([]),
  708. mock_pkg_resource:mock([
  709. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  710. ]),
  711. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  712. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  713. {list_to_atom(PkgName), Vsn}
  714. ]}]),
  715. {ok, RConf} = file:consult(RConfFile),
  716. %% Build with deps.
  717. rebar_test_utils:run_and_check(
  718. Config, RConf, ["compile"],
  719. {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]}
  720. ),
  721. %% Build two checkout apps similar to dependencies to be fetched,
  722. %% but on a different version
  723. Vsn2 = rebar_test_utils:create_random_vsn(),
  724. rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]),
  725. rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]),
  726. %% Rebuild and make sure the checkout apps are in path
  727. code:set_path(StartPaths),
  728. {ok, State} = rebar_test_utils:run_and_check(
  729. Config, RConf, ["compile"],
  730. {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]}
  731. ),
  732. code:add_paths(rebar_state:code_paths(State, all_deps)),
  733. [DepPath] = [Path || Path <- code:get_path(),
  734. {match, _} <- [re:run(Path, DepName)]],
  735. [PkgPath] = [Path || Path <- code:get_path(),
  736. {match, _} <- [re:run(Path, PkgName)]],
  737. {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])),
  738. {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])),
  739. {application, _, DepProps} = DepApp,
  740. {application, _, PkgProps} = PkgApp,
  741. ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)),
  742. ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)).
  743. highest_version_of_pkg_dep(Config) ->
  744. AppDir = ?config(apps, Config),
  745. Name = rebar_test_utils:create_random_name("app1_"),
  746. Vsn = rebar_test_utils:create_random_vsn(),
  747. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  748. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  749. mock_git_resource:mock([]),
  750. mock_pkg_resource:mock([
  751. {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
  752. {{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
  753. {{iolist_to_binary(PkgName), <<"0.1.3">>}, []},
  754. {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}
  755. ]),
  756. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]),
  757. {ok, RConf} = file:consult(RConfFile),
  758. %% Build with deps.
  759. rebar_test_utils:run_and_check(
  760. Config, RConf, ["compile"],
  761. {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]}
  762. ).
  763. parse_transform_test(Config) ->
  764. AppDir = ?config(apps, Config),
  765. RebarConfig = [{erl_opts, [{parse_transform, pascal}]}],
  766. Name = rebar_test_utils:create_random_name("app1_"),
  767. Vsn = rebar_test_utils:create_random_vsn(),
  768. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  769. ExtraSrc = <<"-module(pascal). "
  770. "-export([parse_transform/2]). "
  771. "parse_transform(Forms, _Options) -> "
  772. "Forms.">>,
  773. ok = file:write_file(filename:join([AppDir, "src", "pascal.erl"]), ExtraSrc),
  774. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  775. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  776. true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])).
  777. erl_first_files_test(Config) ->
  778. AppDir = ?config(apps, Config),
  779. RebarConfig = [{erl_opts, [{parse_transform, mark_time}]},
  780. {erl_first_files, ["src/mark_time.erl",
  781. "src/b.erl",
  782. "src/d.erl",
  783. "src/a.erl"]}],
  784. Name = rebar_test_utils:create_random_name("app1_"),
  785. Vsn = rebar_test_utils:create_random_vsn(),
  786. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  787. rebar_test_utils:write_src_file(AppDir, "a.erl"),
  788. rebar_test_utils:write_src_file(AppDir, "b.erl"),
  789. rebar_test_utils:write_src_file(AppDir, "d.erl"),
  790. rebar_test_utils:write_src_file(AppDir, "e.erl"),
  791. ExtraSrc = <<"-module(mark_time). "
  792. "-export([parse_transform/2]). "
  793. "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> "
  794. " [Form, {attribute,1,number, os:timestamp()} | Forms];"
  795. "parse_transform([Form|Forms], Options) -> "
  796. " [Form | parse_transform(Forms, Options)].">>,
  797. ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc),
  798. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  799. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  800. true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])),
  801. code:load_abs(filename:join([EbinDir, "a"])),
  802. code:load_abs(filename:join([EbinDir, "b"])),
  803. code:load_abs(filename:join([EbinDir, "d"])),
  804. code:load_abs(filename:join([EbinDir, "e"])),
  805. A = proplists:get_value(number, a:module_info(attributes)),
  806. B = proplists:get_value(number, b:module_info(attributes)),
  807. D = proplists:get_value(number, d:module_info(attributes)),
  808. E = proplists:get_value(number, e:module_info(attributes)),
  809. ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])).
  810. mib_test(Config) ->
  811. AppDir = ?config(apps, Config),
  812. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  813. Name = rebar_test_utils:create_random_name("app1_"),
  814. Vsn = rebar_test_utils:create_random_vsn(),
  815. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  816. MibsSrc = <<"-- SIMPLE-MIB.\n"
  817. "-- This is just a simple MIB used for testing!\n"
  818. "--\n"
  819. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  820. "IMPORTS\n"
  821. " MODULE-IDENTITY, enterprises\n"
  822. " FROM SNMPv2-SMI;\n"
  823. "\n"
  824. "ericsson MODULE-IDENTITY\n"
  825. " LAST-UPDATED\n"
  826. " \"201403060000Z\"\n"
  827. " ORGANIZATION\n"
  828. " \"rebar\"\n"
  829. " CONTACT-INFO\n"
  830. " \"rebar <rebar@example.com>\n"
  831. " or\n"
  832. " whoever is currently responsible for the SIMPLE\n"
  833. " enterprise MIB tree branch (enterprises.999).\"\n"
  834. " DESCRIPTION\n"
  835. " \"This very small module is made available\n"
  836. " for mib-compilation testing.\"\n"
  837. " ::= { enterprises 999 }\n"
  838. "END\n">>,
  839. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  840. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  841. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  842. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  843. PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  844. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  845. %% check a hrl corresponding to the mib in the mibs dir exists in include
  846. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  847. %% check the mibs dir was linked into the _build dir
  848. true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])).
  849. umbrella_mib_first_test(Config) ->
  850. AppsDir = ?config(apps, Config),
  851. Name = rebar_test_utils:create_random_name("app1_"),
  852. Vsn = rebar_test_utils:create_random_vsn(),
  853. AppDir = filename:join([AppsDir, "apps", Name]),
  854. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  855. MibsSrc = <<"-- SIMPLE-MIB.\n"
  856. "-- This is just a simple MIB used for testing!\n"
  857. "--\n"
  858. "SIMPLE-MIB DEFINITIONS ::= BEGIN\n"
  859. "IMPORTS\n"
  860. " MODULE-IDENTITY, enterprises\n"
  861. " FROM SNMPv2-SMI;\n"
  862. "\n"
  863. "ericsson MODULE-IDENTITY\n"
  864. " LAST-UPDATED\n"
  865. " \"201403060000Z\"\n"
  866. " ORGANIZATION\n"
  867. " \"rebar\"\n"
  868. " CONTACT-INFO\n"
  869. " \"rebar <rebar@example.com>\n"
  870. " or\n"
  871. " whoever is currently responsible for the SIMPLE\n"
  872. " enterprise MIB tree branch (enterprises.999).\"\n"
  873. " DESCRIPTION\n"
  874. " \"This very small module is made available\n"
  875. " for mib-compilation testing.\"\n"
  876. " ::= { enterprises 999 }\n"
  877. "END\n">>,
  878. ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])),
  879. ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc),
  880. RebarConfig = [{mib_first_files, ["mibs/SIMPLE-MIB.mib"]}],
  881. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  882. %% check a bin corresponding to the mib in the mibs dir exists in priv/mibs
  883. PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),
  884. true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])),
  885. %% check a hrl corresponding to the mib in the mibs dir exists in include
  886. true = filelib:is_file(filename:join([AppDir, "include", "SIMPLE-MIB.hrl"])),
  887. %% check the mibs dir was linked into the _build dir
  888. true = filelib:is_dir(filename:join([AppsDir, "_build", "default", "lib", Name, "mibs"])).
  889. only_default_transitive_deps(Config) ->
  890. AppDir = ?config(apps, Config),
  891. Name = rebar_test_utils:create_random_name("app1_"),
  892. Vsn = rebar_test_utils:create_random_vsn(),
  893. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  894. GitDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]),
  895. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  896. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  897. mock_git_resource:mock([{deps, SrcDeps},
  898. {config, [{profiles, [{test, [{deps, [list_to_atom(PkgName)]}]}]}]}]),
  899. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  900. Deps = rebar_test_utils:top_level_deps(GitDeps),
  901. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  902. {ok, RConf} = file:consult(RConfFile),
  903. %% Build with deps.
  904. rebar_test_utils:run_and_check(
  905. Config, RConf, ["as", "test", "compile"],
  906. {ok, [{app, Name}, {dep, "a", <<"1.0.0">>}, {dep_not_exist, PkgName}]}
  907. ).
  908. clean_all(Config) ->
  909. AppDir = ?config(apps, Config),
  910. Name = rebar_test_utils:create_random_name("app1_"),
  911. Vsn = rebar_test_utils:create_random_vsn(),
  912. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  913. DepName = rebar_test_utils:create_random_name("dep1_"),
  914. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  915. mock_git_resource:mock([]),
  916. mock_pkg_resource:mock([
  917. {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]}
  918. ]),
  919. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [
  920. {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}},
  921. {list_to_atom(PkgName), Vsn}
  922. ]}]),
  923. {ok, RConf} = file:consult(RConfFile),
  924. %% Build things
  925. rebar_test_utils:run_and_check(
  926. Config, RConf, ["compile"],
  927. {ok, [{app, Name}, {app, DepName}, {app, PkgName}]}
  928. ),
  929. %% Clean all
  930. rebar_test_utils:run_and_check(Config, [], ["clean", "--all"],
  931. {ok, [{app, Name, invalid},
  932. {app, DepName, invalid},
  933. {app, PkgName, invalid}]}).
  934. override_deps(Config) ->
  935. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  936. TopDeps = rebar_test_utils:top_level_deps(Deps),
  937. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  938. mock_git_resource:mock([{deps, SrcDeps}]),
  939. RebarConfig = [
  940. {deps, TopDeps},
  941. {overrides, [
  942. {override, some_dep, [
  943. {deps, []}
  944. ]}
  945. ]}
  946. ],
  947. rebar_test_utils:run_and_check(
  948. Config, RebarConfig, ["compile"],
  949. {ok, [{dep, "some_dep"},
  950. {dep_not_exist, "other_dep"}]}
  951. ).
  952. override_add_deps(Config) ->
  953. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  954. TopDeps = rebar_test_utils:top_level_deps(Deps),
  955. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  956. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  957. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  958. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  959. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  960. RebarConfig = [
  961. {deps, TopDeps},
  962. {overrides, [
  963. {add, some_dep, [
  964. {deps, [DepA, DepB]}
  965. ]},
  966. {add, [
  967. {deps, [DepC]}
  968. ]}
  969. ]}
  970. ],
  971. rebar_test_utils:run_and_check(
  972. Config, RebarConfig, ["compile"],
  973. {ok, [{dep, "some_dep"},
  974. {dep, "other_dep"},
  975. {dep, "dep_a"},
  976. {dep, "dep_b"},
  977. {dep, "dep_c"}]}
  978. ).
  979. override_del_deps(Config) ->
  980. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  981. {"dep_b", "0.0.1", []},
  982. {"dep_c", "0.0.1", []}]},
  983. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  984. {"dep_d", "0.0.1", []}]}]),
  985. TopDeps = rebar_test_utils:top_level_deps(Deps),
  986. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  987. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  988. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  989. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  990. mock_git_resource:mock([{deps, SrcDeps}]),
  991. RebarConfig = [
  992. {deps, TopDeps},
  993. {overrides, [
  994. {del, some_dep, [
  995. {deps, [DepA, DepB]}
  996. ]},
  997. {del, [
  998. {deps, [DepC]}
  999. ]}
  1000. ]}
  1001. ],
  1002. rebar_test_utils:run_and_check(
  1003. Config, RebarConfig, ["compile"],
  1004. {ok, [{dep, "some_dep"},
  1005. {dep, "other_dep"},
  1006. {dep_not_exist, "dep_a"},
  1007. {dep_not_exist, "dep_b"},
  1008. {dep_not_exist, "dep_c"},
  1009. {dep, "dep_d"}]}
  1010. ).
  1011. override_opts(Config) ->
  1012. AppDir = ?config(apps, Config),
  1013. Name = rebar_test_utils:create_random_name("app1_"),
  1014. Vsn = rebar_test_utils:create_random_vsn(),
  1015. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1016. RebarConfig = [
  1017. {erl_opts, [
  1018. compressed,
  1019. warn_missing_spec
  1020. ]},
  1021. {overrides, [
  1022. {override, [
  1023. {erl_opts, [compressed]}
  1024. ]}
  1025. ]}
  1026. ],
  1027. rebar_test_utils:create_config(AppDir, RebarConfig),
  1028. rebar_test_utils:run_and_check(
  1029. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1030. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1031. code:add_patha(Path),
  1032. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1033. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1034. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1035. %% test for fix of https://github.com/erlang/rebar3/issues/1801
  1036. %% only apply overrides once
  1037. %% verify by having an override add the macro TEST to the dep some_dep
  1038. %% building under `ct` will fail if the `add` is applied more than once
  1039. apply_overrides_exactly_once(Config) ->
  1040. AppDir = ?config(apps, Config),
  1041. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1042. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1043. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1044. mock_git_resource:mock([{deps, SrcDeps}]),
  1045. Name = rebar_test_utils:create_random_name("app1_"),
  1046. Vsn = rebar_test_utils:create_random_vsn(),
  1047. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1048. RebarConfig = [{deps, TopDeps},
  1049. {overrides, [
  1050. {add, some_dep, [
  1051. {erl_opts, [{d, 'TEST'}]}
  1052. ]}
  1053. ]}],
  1054. rebar_test_utils:create_config(AppDir, RebarConfig),
  1055. rebar_test_utils:run_and_check(
  1056. Config, RebarConfig, ["ct", "--compile_only"], {ok, [{app, Name}, {dep, "some_dep"}], "test"}).
  1057. override_add_opts(Config) ->
  1058. AppDir = ?config(apps, Config),
  1059. Name = rebar_test_utils:create_random_name("app1_"),
  1060. Vsn = rebar_test_utils:create_random_vsn(),
  1061. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1062. RebarConfig = [
  1063. {erl_opts, [
  1064. warn_missing_spec
  1065. ]},
  1066. {overrides, [
  1067. {add, [
  1068. {erl_opts, [compressed]}
  1069. ]}
  1070. ]}
  1071. ],
  1072. rebar_test_utils:create_config(AppDir, RebarConfig),
  1073. rebar_test_utils:run_and_check(
  1074. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1075. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1076. code:add_patha(Path),
  1077. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1078. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1079. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1080. override_del_opts(Config) ->
  1081. AppDir = ?config(apps, Config),
  1082. Name = rebar_test_utils:create_random_name("app1_"),
  1083. Vsn = rebar_test_utils:create_random_vsn(),
  1084. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1085. RebarConfig = [
  1086. {erl_opts, [
  1087. compressed,
  1088. warn_missing_spec
  1089. ]},
  1090. {overrides, [
  1091. {del, [
  1092. {erl_opts, [warn_missing_spec]}
  1093. ]}
  1094. ]}
  1095. ],
  1096. rebar_test_utils:create_config(AppDir, RebarConfig),
  1097. rebar_test_utils:run_and_check(
  1098. Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1099. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1100. code:add_patha(Path),
  1101. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1102. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1103. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1104. profile_override_deps(Config) ->
  1105. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1106. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1107. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1108. mock_git_resource:mock([{deps, SrcDeps}]),
  1109. RebarConfig = [
  1110. {deps, TopDeps},
  1111. {profiles, [
  1112. {a, [
  1113. {overrides, [
  1114. {override, some_dep, [
  1115. {deps, []}
  1116. ]}
  1117. ]}
  1118. ]}
  1119. ]}],
  1120. rebar_test_utils:run_and_check(
  1121. Config, RebarConfig, ["as", "a", "compile"],
  1122. {ok, [{dep, "some_dep"},
  1123. {dep_not_exist, "other_dep"}]}
  1124. ).
  1125. profile_override_add_deps(Config) ->
  1126. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1127. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1128. DepA = {dep_a, "0.0.1", {git, "http://site.com/dep_a.git", {tag, "0.0.1"}}},
  1129. DepB = {dep_b, "0.0.1", {git, "http://site.com/dep_b.git", {tag, "0.0.1"}}},
  1130. DepC = {dep_c, "0.0.1", {git, "http://site.com/dep_c.git", {tag, "0.0.1"}}},
  1131. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1132. mock_git_resource:mock([{deps, [DepA, DepB, DepC | SrcDeps]}]),
  1133. RebarConfig = [
  1134. {deps, TopDeps},
  1135. {profiles, [
  1136. {a, [
  1137. {overrides, [
  1138. {add, some_dep, [
  1139. {deps, [DepA, DepB]}
  1140. ]},
  1141. {add, [
  1142. {deps, [DepC]}
  1143. ]}
  1144. ]}
  1145. ]}
  1146. ]}
  1147. ],
  1148. rebar_test_utils:run_and_check(
  1149. Config, RebarConfig, ["as", "a", "compile"],
  1150. {ok, [{dep, "some_dep"},
  1151. {dep, "other_dep"},
  1152. {dep, "dep_a"},
  1153. {dep, "dep_b"},
  1154. {dep, "dep_c"}]}
  1155. ).
  1156. profile_override_del_deps(Config) ->
  1157. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"dep_a", "0.0.1", []},
  1158. {"dep_b", "0.0.1", []},
  1159. {"dep_c", "0.0.1", []}]},
  1160. {"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
  1161. {"dep_d", "0.0.1", []}]}]),
  1162. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1163. DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
  1164. DepB = {dep_b, "0.0.1", {git, "https://example.org/user/dep_b.git", {tag, "0.0.1"}}},
  1165. DepC = {dep_c, "0.0.1", {git, "https://example.org/user/dep_c.git", {tag, "0.0.1"}}},
  1166. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1167. mock_git_resource:mock([{deps, SrcDeps}]),
  1168. RebarConfig = [
  1169. {deps, TopDeps},
  1170. {profiles, [
  1171. {a, [
  1172. {overrides, [
  1173. {del, some_dep, [
  1174. {deps, [DepA, DepB]}
  1175. ]},
  1176. {del, [
  1177. {deps, [DepC]}
  1178. ]}
  1179. ]}
  1180. ]}
  1181. ]}
  1182. ],
  1183. rebar_test_utils:run_and_check(
  1184. Config, RebarConfig, ["as", "a", "compile"],
  1185. {ok, [{dep, "some_dep"},
  1186. {dep, "other_dep"},
  1187. {dep_not_exist, "dep_a"},
  1188. {dep_not_exist, "dep_b"},
  1189. {dep_not_exist, "dep_c"},
  1190. {dep, "dep_d"}]}
  1191. ).
  1192. profile_override_opts(Config) ->
  1193. AppDir = ?config(apps, Config),
  1194. Name = rebar_test_utils:create_random_name("app1_"),
  1195. Vsn = rebar_test_utils:create_random_vsn(),
  1196. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1197. RebarConfig = [
  1198. {erl_opts, [
  1199. compressed,
  1200. warn_missing_spec
  1201. ]},
  1202. {profiles, [
  1203. {a, [
  1204. {overrides, [
  1205. {override, [
  1206. {erl_opts, [compressed]}
  1207. ]}
  1208. ]}
  1209. ]}
  1210. ]}
  1211. ],
  1212. rebar_test_utils:create_config(AppDir, RebarConfig),
  1213. rebar_test_utils:run_and_check(
  1214. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1215. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1216. code:add_patha(Path),
  1217. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1218. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1219. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1220. profile_override_add_opts(Config) ->
  1221. AppDir = ?config(apps, Config),
  1222. Name = rebar_test_utils:create_random_name("app1_"),
  1223. Vsn = rebar_test_utils:create_random_vsn(),
  1224. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1225. RebarConfig = [
  1226. {erl_opts, [
  1227. warn_missing_spec
  1228. ]},
  1229. {profiles, [
  1230. {a, [
  1231. {overrides, [
  1232. {add, [
  1233. {erl_opts, [compressed]}
  1234. ]}
  1235. ]}
  1236. ]}
  1237. ]}
  1238. ],
  1239. rebar_test_utils:create_config(AppDir, RebarConfig),
  1240. rebar_test_utils:run_and_check(
  1241. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1242. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1243. code:add_patha(Path),
  1244. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1245. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1246. true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1247. profile_override_del_opts(Config) ->
  1248. AppDir = ?config(apps, Config),
  1249. Name = rebar_test_utils:create_random_name("app1_"),
  1250. Vsn = rebar_test_utils:create_random_vsn(),
  1251. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1252. RebarConfig = [
  1253. {erl_opts, [
  1254. compressed,
  1255. warn_missing_spec
  1256. ]},
  1257. {profiles, [
  1258. {a, [
  1259. {overrides, [
  1260. {del, [
  1261. {erl_opts, [warn_missing_spec]}
  1262. ]}
  1263. ]}
  1264. ]}
  1265. ]}
  1266. ],
  1267. rebar_test_utils:create_config(AppDir, RebarConfig),
  1268. rebar_test_utils:run_and_check(
  1269. Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
  1270. Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
  1271. code:add_patha(Path),
  1272. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1273. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1274. false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
  1275. profile_deps(Config) ->
  1276. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1277. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1278. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1279. mock_git_resource:mock([{deps, SrcDeps}]),
  1280. RebarConfig = [
  1281. {deps, TopDeps},
  1282. {profiles, [{a, []}]}],
  1283. rebar_test_utils:run_and_check(
  1284. Config, RebarConfig, ["as", "a", "compile"],
  1285. {ok, [{dep, "some_dep"},{dep, "other_dep"}]}
  1286. ).
  1287. only_deps(Config) ->
  1288. AppDir = ?config(apps, Config),
  1289. Name = rebar_test_utils:create_random_name("app1_"),
  1290. Vsn = rebar_test_utils:create_random_vsn(),
  1291. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1292. Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
  1293. TopDeps = rebar_test_utils:top_level_deps(Deps),
  1294. {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
  1295. mock_git_resource:mock([{deps, SrcDeps}]),
  1296. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
  1297. {ok, RConf} = file:consult(RConfFile),
  1298. rebar_test_utils:run_and_check(
  1299. Config, RConf, ["compile", "--deps_only"],
  1300. {ok, [{app_not_exist, Name}, {dep, "some_dep"},{dep, "other_dep"}]}
  1301. ).
  1302. %% verify a deps prod profile is used
  1303. %% tested by checking prod hooks run and outputs to default profile dir for dep
  1304. %% and prod deps are installed for dep
  1305. deps_build_in_prod(Config) ->
  1306. AppDir = ?config(apps, Config),
  1307. Name = rebar_test_utils:create_random_name("app1_"),
  1308. Vsn = rebar_test_utils:create_random_vsn(),
  1309. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1310. GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]),
  1311. PkgName = rebar_test_utils:create_random_name("pkg1_"),
  1312. {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
  1313. mock_git_resource:mock([{deps, SrcDeps},
  1314. {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]},
  1315. {deps, [list_to_atom(PkgName)]}]}]}]}]),
  1316. mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
  1317. Deps = rebar_test_utils:top_level_deps(GitDeps),
  1318. RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
  1319. {ok, RConf} = file:consult(RConfFile),
  1320. %% Build with deps.
  1321. rebar_test_utils:run_and_check(
  1322. Config, RConf, ["compile"],
  1323. {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName},
  1324. {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]}
  1325. ).
  1326. %% verify that the proper include path is defined
  1327. %% according the erlang doc which states:
  1328. %% If the filename File is absolute (possibly after variable substitution),
  1329. %% the include file with that name is included. Otherwise, the specified file
  1330. %% is searched for in the following directories, and in this order:
  1331. %% * The current working directory
  1332. %% * The directory where the module is being compiled
  1333. %% * The directories given by the include option
  1334. include_file_relative_to_working_directory(Config) ->
  1335. AppDir = ?config(apps, Config),
  1336. Name = rebar_test_utils:create_random_name("app1_"),
  1337. Vsn = rebar_test_utils:create_random_vsn(),
  1338. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1339. Src = <<"-module(test).\n"
  1340. "\n"
  1341. "-include(\"include/test.hrl\").\n"
  1342. "\n"
  1343. "test() -> ?TEST_MACRO.\n"
  1344. "\n">>,
  1345. Include = <<"-define(TEST_MACRO, test).\n">>,
  1346. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1347. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1348. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1349. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1350. RebarConfig = [],
  1351. rebar_test_utils:run_and_check(Config, RebarConfig,
  1352. ["compile"],
  1353. {ok, [{app, Name}]}).
  1354. include_file_in_src(Config) ->
  1355. AppDir = ?config(apps, Config),
  1356. Name = rebar_test_utils:create_random_name("app1_"),
  1357. Vsn = rebar_test_utils:create_random_vsn(),
  1358. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1359. Src = <<"-module(test).\n"
  1360. "\n"
  1361. "-include(\"test.hrl\").\n"
  1362. "\n"
  1363. "test() -> ?TEST_MACRO.\n"
  1364. "\n">>,
  1365. Include = <<"-define(TEST_MACRO, test).\n">>,
  1366. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1367. ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
  1368. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1369. RebarConfig = [],
  1370. rebar_test_utils:run_and_check(Config, RebarConfig,
  1371. ["compile"],
  1372. {ok, [{app, Name}]}).
  1373. %% verify that the proper include path is defined
  1374. %% according the erlang doc which states:
  1375. %% If the filename File is absolute (possibly after variable substitution),
  1376. %% the include file with that name is included. Otherwise, the specified file
  1377. %% is searched for in the following directories, and in this order:
  1378. %% * The current working directory
  1379. %% * The directory where the module is being compiled
  1380. %% * The directories given by the include option
  1381. %%
  1382. %% This test ensures that things keep working when additional directories
  1383. %% are used for apps, such as the test/ directory within the test profile.
  1384. include_file_relative_to_working_directory_test(Config) ->
  1385. AppDir = ?config(apps, Config),
  1386. Name = rebar_test_utils:create_random_name("app1_"),
  1387. Vsn = rebar_test_utils:create_random_vsn(),
  1388. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1389. Src = <<"-module(test).\n"
  1390. "\n"
  1391. "-include(\"include/test.hrl\").\n"
  1392. "\n"
  1393. "test() -> ?TEST_MACRO.\n"
  1394. "\n">>,
  1395. Include = <<"-define(TEST_MACRO, test).\n">>,
  1396. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1397. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1398. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1399. ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
  1400. ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
  1401. RebarConfig = [],
  1402. rebar_test_utils:run_and_check(Config, RebarConfig,
  1403. ["as", "test", "compile"],
  1404. {ok, [{app, Name}]}).
  1405. %% Same as `include_file_in_src/1' but using the `test/' directory
  1406. %% within the test profile.
  1407. include_file_in_src_test(Config) ->
  1408. AppDir = ?config(apps, Config),
  1409. Name = rebar_test_utils:create_random_name("app1_"),
  1410. Vsn = rebar_test_utils:create_random_vsn(),
  1411. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1412. Src = <<"-module(test).\n"
  1413. "\n"
  1414. "-include(\"test.hrl\").\n"
  1415. "\n"
  1416. "test() -> ?TEST_MACRO.\n"
  1417. "\n">>,
  1418. Include = <<"-define(TEST_MACRO, test).\n">>,
  1419. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1420. ok = filelib:ensure_dir(filename:join([AppDir, "test", "dummy"])),
  1421. ok = file:write_file(filename:join([AppDir, "test", "test.erl"]), Src),
  1422. ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
  1423. RebarConfig = [],
  1424. rebar_test_utils:run_and_check(Config, RebarConfig,
  1425. ["as", "test", "compile"],
  1426. {ok, [{app, Name}]}).
  1427. %% Same as `include_file_in_src_test/1' but using multiple top-level
  1428. %% apps as dependencies.
  1429. include_file_in_src_test_multiapp(Config) ->
  1430. Name1 = rebar_test_utils:create_random_name("app2_"),
  1431. Name2 = rebar_test_utils:create_random_name("app1_"),
  1432. AppDir1 = filename:join([?config(apps, Config), "lib", Name1]),
  1433. AppDir2 = filename:join([?config(apps, Config), "lib", Name2]),
  1434. Vsn = rebar_test_utils:create_random_vsn(),
  1435. rebar_test_utils:create_app(AppDir1, Name1, Vsn, [kernel, stdlib]),
  1436. rebar_test_utils:create_app(AppDir2, Name2, Vsn, [kernel, stdlib]),
  1437. Src = "-module(test).\n"
  1438. "\n"
  1439. "-include_lib(\"" ++ Name2 ++ "/include/test.hrl\").\n"
  1440. "\n"
  1441. "test() -> ?TEST_MACRO.\n"
  1442. "\n",
  1443. Include = <<"-define(TEST_MACRO, test).\n">>,
  1444. ok = filelib:ensure_dir(filename:join([AppDir1, "src", "dummy"])),
  1445. ok = filelib:ensure_dir(filename:join([AppDir1, "test", "dummy"])),
  1446. ok = filelib:ensure_dir(filename:join([AppDir2, "src", "dummy"])),
  1447. ok = filelib:ensure_dir(filename:join([AppDir2, "include", "dummy"])),
  1448. ok = file:write_file(filename:join([AppDir1, "test", "test.erl"]), Src),
  1449. ok = file:write_file(filename:join([AppDir2, "include", "test.hrl"]), Include),
  1450. RebarConfig = [],
  1451. rebar_test_utils:run_and_check(Config, RebarConfig,
  1452. ["as", "test", "compile"],
  1453. {ok, [{app, Name1}]}).
  1454. %% this test sets the env var, compiles, records the file last modified timestamp,
  1455. %% recompiles and compares the file last modified timestamp to ensure it hasn't
  1456. %% changed. this test should run on 19.x+
  1457. dont_recompile_when_erl_compiler_options_env_does_not_change(Config) ->
  1458. %% save existing env to restore after test
  1459. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1460. AppDir = ?config(apps, Config),
  1461. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1462. Vsn = rebar_test_utils:create_random_vsn(),
  1463. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1464. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1465. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1466. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1467. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1468. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1469. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1470. || F <- Files, filename:extension(F) == ".beam"],
  1471. timer:sleep(1000),
  1472. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1473. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1474. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1475. || F <- NewFiles, filename:extension(F) == ".beam"],
  1476. ?assert(ModTime == NewModTime),
  1477. %% restore existing env
  1478. case ExistingEnv of
  1479. false -> ok;
  1480. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1481. end.
  1482. %% this test compiles, records the file last modified timestamp, sets the env
  1483. %% var, recompiles and compares the file last modified timestamp to ensure it
  1484. %% has changed. this test should run on 19.x+
  1485. recompile_when_erl_compiler_options_env_changes(Config) ->
  1486. %% save existing env to restore after test
  1487. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1488. AppDir = ?config(apps, Config),
  1489. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1490. Vsn = rebar_test_utils:create_random_vsn(),
  1491. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1492. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1493. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1494. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1495. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1496. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1497. || F <- Files, filename:extension(F) == ".beam"],
  1498. timer:sleep(1000),
  1499. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1500. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1501. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1502. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1503. || F <- NewFiles, filename:extension(F) == ".beam"],
  1504. ?assert(ModTime =/= NewModTime),
  1505. %% restore existing env
  1506. case ExistingEnv of
  1507. false -> ok;
  1508. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1509. end.
  1510. rebar_config_os_var(Config) ->
  1511. AppDir = ?config(apps, Config),
  1512. Name = rebar_test_utils:create_random_name("rebar_config_os_var_"),
  1513. Vsn = rebar_test_utils:create_random_vsn(),
  1514. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1515. rebar_test_utils:create_config(AppDir, [{erl_opts, []}]),
  1516. AltConfig = filename:join(AppDir, "test.rebar.config"),
  1517. file:write_file(AltConfig, "{erl_opts, [compressed]}."),
  1518. true = os:putenv("REBAR_CONFIG", AltConfig),
  1519. rebar_test_utils:run_and_check(Config, ["compile"], {ok, [{app, Name}]}),
  1520. Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1521. code:add_patha(Path),
  1522. Mod = list_to_atom("not_a_real_src_" ++ Name),
  1523. true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
  1524. ok.
  1525. %% this test sets the env var, compiles, records the file last modified
  1526. %% timestamp, recompiles and compares the file last modified timestamp to
  1527. %% ensure it has changed. this test should run on 18.x
  1528. always_recompile_when_erl_compiler_options_set(Config) ->
  1529. %% save existing env to restore after test
  1530. ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"),
  1531. AppDir = ?config(apps, Config),
  1532. Name = rebar_test_utils:create_random_name("erl_compiler_options_"),
  1533. Vsn = rebar_test_utils:create_random_vsn(),
  1534. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1535. true = os:unsetenv("ERL_COMPILER_OPTIONS"),
  1536. true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"),
  1537. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1538. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1539. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1540. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1541. || F <- Files, filename:extension(F) == ".beam"],
  1542. timer:sleep(1000),
  1543. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1544. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1545. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1546. || F <- NewFiles, filename:extension(F) == ".beam"],
  1547. ?assert(ModTime =/= NewModTime),
  1548. %% restore existing env
  1549. case ExistingEnv of
  1550. false -> ok;
  1551. _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv)
  1552. end.
  1553. recompile_when_parse_transform_inline_changes(Config) ->
  1554. AppDir = ?config(apps, Config),
  1555. Name = rebar_test_utils:create_random_name("parse_transform_inline_"),
  1556. Vsn = rebar_test_utils:create_random_vsn(),
  1557. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1558. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1559. ModSrc = <<"-module(example).\n"
  1560. "-export([foo/2]).\n"
  1561. "-compile([{parse_transform, example_parse_transform}]).\n"
  1562. "foo(_, _) -> ok.">>,
  1563. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1564. ModSrc),
  1565. ParseTransform = <<"-module(example_parse_transform).\n"
  1566. "-export([parse_transform/2]).\n"
  1567. "parse_transform(AST, _) -> AST.\n">>,
  1568. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1569. ParseTransform),
  1570. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1571. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1572. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1573. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1574. || F <- Files, filename:basename(F, ".beam") == "example"],
  1575. timer:sleep(1000),
  1576. NewParseTransform = <<"-module(example_parse_transform).\n"
  1577. "-export([parse_transform/2]).\n"
  1578. "parse_transform(AST, _) -> identity(AST).\n"
  1579. "identity(AST) -> AST.\n">>,
  1580. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1581. NewParseTransform),
  1582. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1583. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1584. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1585. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1586. ?assert(ModTime =/= NewModTime).
  1587. recompile_when_parse_transform_as_opt_changes(Config) ->
  1588. AppDir = ?config(apps, Config),
  1589. Name = rebar_test_utils:create_random_name("parse_transform_opt_"),
  1590. Vsn = rebar_test_utils:create_random_vsn(),
  1591. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1592. ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
  1593. ModSrc = <<"-module(example).\n"
  1594. "-export([foo/2]).\n"
  1595. "foo(_, _) -> ok.">>,
  1596. ok = file:write_file(filename:join([AppDir, "src", "example.erl"]),
  1597. ModSrc),
  1598. ParseTransform = <<"-module(example_parse_transform).\n"
  1599. "-export([parse_transform/2]).\n"
  1600. "parse_transform(AST, _) -> AST.">>,
  1601. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1602. ParseTransform),
  1603. RebarConfig = [{erl_opts, [{parse_transform, example_parse_transform}]}],
  1604. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1605. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1606. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1607. ModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1608. || F <- Files, filename:basename(F, ".beam") == "example"],
  1609. timer:sleep(1000),
  1610. NewParseTransform = <<"-module(example_parse_transform).\n"
  1611. "-export([parse_transform/2]).\n"
  1612. "parse_transform(AST, _) -> identity(AST).\n"
  1613. "identity(AST) -> AST.">>,
  1614. ok = file:write_file(filename:join([AppDir, "src", "example_parse_transform.erl"]),
  1615. NewParseTransform),
  1616. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
  1617. {ok, NewFiles} = rebar_utils:list_dir(EbinDir),
  1618. NewModTime = [filelib:last_modified(filename:join([EbinDir, F]))
  1619. || F <- NewFiles, filename:basename(F, ".beam") == "example"],
  1620. ?assert(ModTime =/= NewModTime).
  1621. recursive(Config) ->
  1622. AppDir = ?config(apps, Config),
  1623. Name = rebar_test_utils:create_random_name("app1_"),
  1624. Vsn = rebar_test_utils:create_random_vsn(),
  1625. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1626. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1627. rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}),
  1628. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1629. {ok, Files} = rebar_utils:list_dir(EbinDir),
  1630. ?assert(lists:member("rec.beam",Files)).
  1631. no_recursive(Config) ->
  1632. AppDir = ?config(apps, Config),
  1633. Name = rebar_test_utils:create_random_name("app1_"),
  1634. Vsn = rebar_test_utils:create_random_vsn(),
  1635. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1636. rebar_test_utils:write_src_file(filename:join(AppDir,src),"rec.erl"),
  1637. RebarConfig1 = [{erlc_compiler,[{recursive,false}]}],
  1638. rebar_test_utils:run_and_check(Config, RebarConfig1, ["compile"],
  1639. {ok, [{app, Name}]}),
  1640. EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
  1641. {ok, Files1} = rebar_utils:list_dir(EbinDir),
  1642. ?assert(false==lists:member("rec.beam",Files1)),
  1643. RebarConfig2 = [{src_dirs,[{"src",[{recursive,false}]}]}],
  1644. rebar_test_utils:run_and_check(Config, RebarConfig2, ["compile"],
  1645. {ok, [{app, Name}]}),
  1646. {ok, Files2} = rebar_utils:list_dir(EbinDir),
  1647. ?assert(false==lists:member("rec.beam",Files2)),
  1648. ok.
  1649. regex_filter_skip(Config) ->
  1650. AppDir = ?config(apps, Config),
  1651. Name = rebar_test_utils:create_random_name("regex_skip"),
  1652. Vsn = rebar_test_utils:create_random_vsn(),
  1653. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1654. rebar_test_utils:write_src_file(filename:join(AppDir,src),"._rec.erl"),
  1655. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","._rec.beam"]),
  1656. RebarConfig = [],
  1657. try
  1658. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1659. {ok, [{file, Expected}]}),
  1660. throw(should_not_be_found)
  1661. catch
  1662. %% the file was not found, as desired!
  1663. error:{assertion_failed,_} -> %% OTP =< 17
  1664. ok;
  1665. error:{assert,_} -> %% OTP >= 18
  1666. ok
  1667. end.
  1668. regex_filter_regression(Config) ->
  1669. AppDir = ?config(apps, Config),
  1670. Name = rebar_test_utils:create_random_name("regex_regression"),
  1671. Vsn = rebar_test_utils:create_random_vsn(),
  1672. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  1673. rebar_test_utils:write_src_file(filename:join(AppDir,src),"r_f.erl"),
  1674. Expected = filename:join([AppDir, "_build", "default", "lib", Name, "ebin","r_f.beam"]),
  1675. RebarConfig = [],
  1676. rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
  1677. {ok, [{file, Expected}]}),
  1678. ok.