You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2362 line
92 KiB

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