Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

2155 lignes
84 KiB

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